-
Notifications
You must be signed in to change notification settings - Fork 0
/
unique_list_test.go
109 lines (85 loc) · 2.05 KB
/
unique_list_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package kredis
func (s *KredisTestSuite) TestIntegerUniqueList() {
l, e := NewIntegerUniqueList("uniq_ints", 3)
s.NoError(e)
n, e := l.Append(1, 2)
s.NoError(e)
s.Equal(int64(2), n)
n, e = l.Prepend(2, 4, 6)
s.NoError(e)
s.Equal(int64(4), n)
n, e = l.Length()
s.NoError(e)
s.Equal(int64(3), n)
elements := make([]int, 3)
n, e = l.Elements(elements)
s.NoError(e)
s.Equal(int64(3), n)
s.Equal([]int{4, 2, 1}, elements)
s.NoError(l.Remove(2, 1))
elements = make([]int, 1)
n, e = l.Elements(elements)
s.NoError(e)
s.Equal(int64(1), n)
s.Equal([]int{4}, elements)
}
func (s *KredisTestSuite) TestFloatUniqueList() {
l, e := NewFloatUniqueList("uniq_float64s", 3)
s.NoError(e)
n, e := l.Append(1.2, 2.3)
s.NoError(e)
s.Equal(int64(2), n)
n, e = l.Prepend(2.3, 4.5, 6.7)
s.NoError(e)
s.Equal(int64(4), n)
n, e = l.Length()
s.NoError(e)
s.Equal(int64(3), n)
elements := make([]float64, 3)
n, e = l.Elements(elements)
s.NoError(e)
s.Equal(int64(3), n)
s.Equal([]float64{4.5, 2.3, 1.2}, elements)
s.NoError(l.Remove(2, 1))
elements = make([]float64, 1)
n, e = l.Elements(elements)
s.NoError(e)
s.Equal(int64(1), n)
s.Equal([]float64{4.5}, elements)
}
func (s *KredisTestSuite) TestStringUniqueList() {
l, e := NewStringUniqueList("uniq_strs", 5)
s.NoError(e)
elements := make([]string, 5)
n, e := l.Elements(elements)
s.NoError(e)
s.Equal(int64(0), n)
n, e = l.Append("a", "b")
s.NoError(e)
s.Equal(int64(2), n)
n, e = l.Prepend("x", "y", "z")
s.NoError(e)
s.Equal(int64(5), n)
n, e = l.Length()
s.NoError(e)
s.Equal(int64(5), n)
elements = make([]string, 5)
n, e = l.Elements(elements)
s.NoError(e)
s.Equal(int64(5), n)
s.Equal([]string{"z", "y", "x", "a", "b"}, elements)
s.NoError(l.Remove("y", "z"))
elements = make([]string, 3)
n, e = l.Elements(elements)
s.NoError(e)
s.Equal(int64(3), n)
s.Equal([]string{"x", "a", "b"}, elements)
last, ok := l.Last()
s.True(ok)
s.Equal("b", last)
last2 := make([]string, 2)
n, e = l.LastN(last2)
s.NoError(e)
s.Equal(int64(2), n)
s.Equal([]string{"a", "b"}, last2)
}