-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathset_test.go
126 lines (108 loc) · 2.34 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package contalgo
import (
"fmt"
"strings"
"testing"
)
func Test_Set_Interface(t *testing.T) {
s := make(Set[int])
_ = Container[int](&s)
}
func Test_MakeSet(t *testing.T) {
s := make(Set[string])
expectEq(t, s.Len(), 0)
expectEq(t, s.IsEmpty(), true)
}
func Test_MakeSet2(t *testing.T) {
s := Set[string]{}
expectEq(t, s.Len(), 0)
expectEq(t, s.IsEmpty(), true)
}
func Test_MakeSetOf(t *testing.T) {
s := MakeSetOf("hello", "world")
expectEq(t, s.Len(), 2)
}
func Test_Set_IsEmpty(t *testing.T) {
s := make(Set[string])
expectEq(t, s.IsEmpty(), true)
s.Add("hello")
expectEq(t, s.IsEmpty(), false)
}
func Test_Set_Clean(t *testing.T) {
s := MakeSetOf("hello", "world")
s.Clean()
expectTrue(t, s.IsEmpty())
}
func Test_Set_String(t *testing.T) {
s := MakeSetOf("hello", "world")
expectTrue(t, strings.HasPrefix(fmt.Sprintf("%v", s), "Set[string]"))
}
func Test_Set_Has(t *testing.T) {
s := MakeSetOf("hello", "world")
expectTrue(t, s.Has("hello"))
expectTrue(t, s.Has("world"))
expectFalse(t, s.Has("!"))
}
func Test_Set_Get(t *testing.T) {
s := MakeSetOf("hello", "world")
expectTrue(t, s["hello"])
expectTrue(t, s["world"])
expectFalse(t, s["!"])
}
func Test_Set_Add(t *testing.T) {
s := make(Set[string])
s.Add("hello")
s.Add("hello")
expectEq(t, s.Has("world"), false)
s.Add("world")
expectEq(t, s.Has("hello"), true)
expectEq(t, s.Len(), 2)
}
func Test_Set_AddN(t *testing.T) {
s := make(Set[string])
s.AddN("hello", "world")
expectEq(t, s.Len(), 2)
}
func Test_Set_Del(t *testing.T) {
s := MakeSetOf("hello", "world")
s.Del("hello")
expectEq(t, s.Len(), 1)
s.Del("hello")
expectEq(t, s.Len(), 1)
s.Del("world")
expectEq(t, s.Len(), 0)
}
func Test_Set_DelN(t *testing.T) {
s := MakeSetOf("hello", "world")
s.DelN("hello", "world")
s.Del("world")
expectTrue(t, s.IsEmpty())
}
func Test_Set_Keys(t *testing.T) {
s := MakeSetOf("hello", "world")
ks := s.Keys()
expectEq(t, 2, len(ks))
}
func Test_Set_For(t *testing.T) {
s := MakeSetOf("hello", "world")
for v := range s {
expectTrue(t, v == "hello" || v == "world")
}
}
func Test_Set_ForEach(t *testing.T) {
s := MakeSetOf("hello", "world")
c := 0
s.ForEach(func(string) {
c++
})
expectEq(t, c, 2)
}
func Test_Set_ForEachIf(t *testing.T) {
s := MakeSetOf("hello", "world")
c := 0
s.ForEachIf(func(string) bool {
c++
return false
})
expectLt(t, c, 2)
}