-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathset_test.go
98 lines (84 loc) · 1.72 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
package contalgo
import (
"fmt"
"strings"
"testing"
)
func Test_Set_Interface(t *testing.T) {
_ = Container[int](NewSet[int]())
}
func Test_New(t *testing.T) {
s := NewSet[string]()
expectEq(t, s.Len(), 0)
expectEq(t, s.IsEmpty(), true)
}
func Test_Of(t *testing.T) {
s := NewSetOf("hello", "world")
expectEq(t, s.Len(), 2)
}
func Test_IsEmpty(t *testing.T) {
s := NewSet[string]()
expectEq(t, s.IsEmpty(), true)
s.Add("hello")
expectEq(t, s.IsEmpty(), false)
}
func Test_Clean(t *testing.T) {
s := NewSetOf("hello", "world")
s.Clean()
expectTrue(t, s.IsEmpty())
}
func Test_String(t *testing.T) {
s := NewSetOf("hello", "world")
expectTrue(t, strings.HasPrefix(fmt.Sprintf("%v", s), "Set[string]"))
}
func Test_Add(t *testing.T) {
s := NewSet[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_AddN(t *testing.T) {
s := NewSet[string]()
s.AddN("hello", "world")
expectEq(t, s.Len(), 2)
}
func Test_Del(t *testing.T) {
s := NewSetOf("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_DelN(t *testing.T) {
s := NewSetOf("hello", "world")
s.DelN("hello", "world")
s.Del("world")
expectTrue(t, s.IsEmpty())
}
func Test_Keys(t *testing.T) {
s := NewSetOf("hello", "world")
ks := s.Keys()
expectEq(t, 2, len(ks))
}
func Test_ForEach(t *testing.T) {
s := NewSetOf("hello", "world")
c := 0
s.ForEach(func(string) {
c++
})
expectEq(t, c, 2)
}
func Test_ForEachIf(t *testing.T) {
s := NewSetOf("hello", "world")
c := 0
s.ForEachIf(func(string) bool {
c++
return false
})
expectLt(t, c, 2)
}