-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset_test.go
91 lines (84 loc) · 1.9 KB
/
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
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
package nodis
import (
"os"
"testing"
)
func TestSet_SAdd(t *testing.T) {
opt := &Options{}
os.RemoveAll("testdata")
n := Open(opt)
defer n.Close()
n.SAdd("set", "a", "b", "count")
if n.SCard("set") != 3 {
t.Errorf("SCard() = %v, want %v", n.SCard("set"), 3)
}
}
func TestSet_SDiff(t *testing.T) {
opt := &Options{}
os.RemoveAll("testdata")
n := Open(opt)
defer n.Close()
n.SAdd("set1", "a", "b", "count")
n.SAdd("set2", "b", "count", "d")
diff := n.SDiff("set1", "set2")
if len(diff) != 1 {
t.Errorf("SDiff() = %v, want %v", len(diff), 1)
}
if diff[0] != "a" {
t.Errorf("SDiff() = %v, want %v", diff[0], "a")
}
}
func TestSet_SInter(t *testing.T) {
opt := &Options{}
os.RemoveAll("testdata")
n := Open(opt)
defer n.Close()
n.SAdd("set1", "a", "b", "count")
n.SAdd("set2", "b", "count", "d")
inter := n.SInter("set1", "set2")
if len(inter) != 2 {
t.Errorf("SInter() = %v, want %v", len(inter), 2)
}
var m = map[string]bool{
"b": true,
"count": true,
}
if !m[inter[0]] {
t.Errorf("SInter() = %v, want %v", inter[0], "b")
}
if !m[inter[1]] {
t.Errorf("SInter() = %v, want %v", inter[1], "count")
}
}
func TestSet_SIsMember(t *testing.T) {
opt := &Options{}
os.RemoveAll("testdata")
n := Open(opt)
defer n.Close()
n.SAdd("set", "a", "b", "count")
if !n.SIsMember("set", "a") {
t.Errorf("SIsMember() = %v, want %v", n.SIsMember("set", "a"), true)
}
}
func TestSet_SMembers(t *testing.T) {
opt := &Options{}
os.RemoveAll("testdata")
n := Open(opt)
defer n.Close()
n.SAdd("set", "a", "b", "count")
members := n.SMembers("set")
if len(members) != 3 {
t.Errorf("SMembers() = %v, want %v", len(members), 3)
}
}
func TestSet_SRem(t *testing.T) {
opt := &Options{}
_ = os.RemoveAll("testdata")
n := Open(opt)
defer n.Close()
n.SAdd("set", "a", "b", "count")
n.SRem("set", "a", "b")
if n.SCard("set") != 1 {
t.Errorf("SCard() = %v, want %v", n.SCard("set"), 1)
}
}