-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset_test.go
More file actions
95 lines (83 loc) · 1.93 KB
/
set_test.go
File metadata and controls
95 lines (83 loc) · 1.93 KB
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
package blocktree
import "testing"
func TestNewSet(t *testing.T) {
s := NewSet[int](1, 2, 3)
if s.Size() != 3 {
t.Errorf("Expected cardinality 3, got %d", s.Size())
}
}
func TestSet_Add(t *testing.T) {
s := NewSet[int](1, 2, 3)
s.Add(4)
if s.Size() != 4 {
t.Errorf("Expected cardinality 4, got %d", s.Size())
}
}
func TestSet_Remove(t *testing.T) {
s := NewSet[int](1, 2, 3)
s.Remove(3)
if s.Size() != 2 {
t.Errorf("Expected cardinality 2, got %d", s.Size())
}
}
func TestSet_Contains(t *testing.T) {
s := NewSet[int](1, 2, 3)
if !s.Contains(3) {
t.Errorf("Expected to contain 3")
}
}
func TestSet_Cardinality(t *testing.T) {
s := NewSet[int](1, 2, 3)
if s.Size() != 3 {
t.Errorf("Expected cardinality 3, got %d", s.Size())
}
}
func TestSet_ToSlice(t *testing.T) {
s := NewSet[int](1, 2, 3)
slice := s.ToSlice()
if len(slice) != 3 {
t.Errorf("Expected slice length 3, got %d", len(slice))
}
}
func TestSet_Union(t *testing.T) {
s := NewSet[int](1, 2, 3)
other := NewSet[int](3, 5, 6)
union := s.Union(*other)
if union.Size() != 5 {
t.Errorf("Expected cardinality 6, got %d", union.Size())
}
}
func TestSet_Intersect(t *testing.T) {
s := NewSet[int](1, 2, 3)
other := NewSet[int](2, 3, 4)
intersection := s.Intersect(*other)
if intersection.Size() != 2 {
t.Errorf("Expected cardinality 2, got %d", intersection.Size())
}
}
func TestSet_Difference(t *testing.T) {
s := NewSet[int](1, 2, 3)
other := NewSet[int](2, 3, 4)
difference := s.Difference(other)
if difference.Size() != 1 {
t.Errorf("Expected cardinality 1, got %d", difference.Size())
}
}
func TestSet_Equals(t *testing.T) {
s := NewSet[int](1, 2, 3)
other := NewSet[int](2, 3, 4)
if s.Equals(other) {
t.Errorf("Expected sets to be different")
}
}
func TestSet_ForEach(t *testing.T) {
s := NewSet[int](1, 2, 3)
var sum int
s.ForEach(func(i int) bool {
sum += i
return true
})
if sum != 6 {
t.Errorf("Expected sum 6, got %d", sum)
}
}