-
Notifications
You must be signed in to change notification settings - Fork 0
/
hash_set_test.go
117 lines (88 loc) · 2.16 KB
/
hash_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
package gost
import "testing"
func Test_HashSet_IsSubset(t *testing.T) {
t.Parallel()
set1 := HashSetNew[I32]()
set1.Insert(I32(1))
set1.Insert(I32(2))
set2 := HashSetNew[I32]()
set2.Insert(I32(1))
set2.Insert(I32(2))
set2.Insert(I32(3))
Assert(set1.IsSubset(set2))
Assert(!set2.IsSubset(set1))
}
func Test_HashSet_IsSuperset(t *testing.T) {
t.Parallel()
set1 := HashSetNew[I32]()
set1.Insert(I32(1))
set1.Insert(I32(2))
set2 := HashSetNew[I32]()
set2.Insert(I32(1))
set2.Insert(I32(2))
set2.Insert(I32(3))
Assert(set2.IsSuperset(set1))
Assert(!set1.IsSuperset(set2))
}
func Test_HashSet_Intersection(t *testing.T) {
t.Parallel()
set1 := HashSetNew[I32]()
set1.Insert(I32(1))
set1.Insert(I32(2))
set1.Insert(I32(5))
set2 := HashSetNew[I32]()
set2.Insert(I32(1))
set2.Insert(I32(2))
set2.Insert(I32(3))
intersection := set1.Intersection(set2)
Assert(intersection.Len() == 2)
Assert(intersection.Contains(I32(1)))
Assert(intersection.Contains(I32(2)))
Assert(!intersection.Contains(I32(3)))
Assert(!intersection.Contains(I32(5)))
}
func Test_HashSet_IsDisjoint(t *testing.T) {
t.Parallel()
set1 := HashSetNew[I32]()
set1.Insert(I32(1))
set1.Insert(I32(2))
set2 := HashSetNew[I32]()
set2.Insert(I32(3))
set2.Insert(I32(4))
Assert(set1.IsDisjoint(set2))
Assert(set2.IsDisjoint(set1))
set2.Insert(I32(2))
Assert(!set1.IsDisjoint(set2))
Assert(!set2.IsDisjoint(set1))
}
func Test_HashSet_Union(t *testing.T) {
t.Parallel()
set1 := HashSetNew[I32]()
set1.Insert(I32(1))
set1.Insert(I32(2))
set1.Insert(I32(3))
set2 := HashSetNew[I32]()
set2.Insert(I32(3))
set2.Insert(I32(4))
union := set1.Union(set2)
Assert(union.Len() == 4)
Assert(union.Contains(I32(1)))
Assert(union.Contains(I32(2)))
Assert(union.Contains(I32(3)))
Assert(union.Contains(I32(4)))
}
func Test_HashSet_SymmetricDifference(t *testing.T) {
t.Parallel()
set1 := HashSetNew[I32]()
set1.Insert(I32(1))
set1.Insert(I32(2))
set1.Insert(I32(5))
set2 := HashSetNew[I32]()
set2.Insert(I32(1))
set2.Insert(I32(2))
set2.Insert(I32(3))
diff := set1.SymmetricDifference(set2)
Assert(diff.Len() == 2)
Assert(diff.Contains(I32(3)))
Assert(diff.Contains(I32(5)))
}