-
Notifications
You must be signed in to change notification settings - Fork 0
/
ordered_set_test.go
58 lines (45 loc) · 1.14 KB
/
ordered_set_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
package kredis
import "time"
func (s *KredisTestSuite) TestStringOrderedSet() {
oset, e := NewStringOrderedSet("ints", 3)
s.NoError(e)
add, rm, e := oset.Append("ready", "set", "go")
s.NoError(e)
s.Equal(int64(3), add)
s.Equal(int64(0), rm)
s.True(oset.Includes("go"))
s.False(oset.Includes("not"))
add, rm, e = oset.Prepend("not", "were")
s.NoError(e)
s.Equal(int64(2), add)
s.Equal(int64(2), rm)
members, e := oset.Members()
s.NoError(e)
s.Equal([]string{"were", "not", "ready"}, members)
n, e := oset.Remove("not")
s.NoError(e)
s.Equal(int64(1), n)
s.NoError(oset.Clear())
s.Equal(int64(0), oset.Size())
}
func (s *KredisTestSuite) TestTimeOrderedSet() {
oset, e := NewTimeOrderedSet("times", 3)
s.NoError(e)
members, e := oset.Members()
s.NoError(e)
s.Empty(members)
t1 := time.Now()
t2 := time.Date(2021, 8, 28, 23, 0, 0, 0, time.UTC)
add, rm, e := oset.Append(t1)
s.NoError(e)
s.Equal(int64(1), add)
s.Equal(int64(0), rm)
s.True(oset.Includes(t1))
s.False(oset.Includes(t2))
oset.SetLimit(1)
add, rm, e = oset.Append(t2)
s.NoError(e)
s.Equal(int64(1), add)
s.Equal(int64(1), rm)
s.True(oset.Includes(t2))
}