forked from torbiak/gopl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
intset_test.go
104 lines (94 loc) · 1.52 KB
/
intset_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
package main
import (
"testing"
)
func TestLenZeroInitially(t *testing.T) {
s := &IntSet{}
if s.Len() != 0 {
t.Logf("%d != 0", s.Len())
t.Fail()
}
}
func TestLenAfterAddingElements(t *testing.T) {
s := &IntSet{}
s.Add(0)
s.Add(2000)
if s.Len() != 2 {
t.Logf("%d != 2", s.Len())
t.Fail()
}
}
func TestRemove(t *testing.T) {
s := &IntSet{}
s.Add(0)
s.Remove(0)
if s.Has(0) {
t.Log(s)
t.Fail()
}
}
func TestClear(t *testing.T) {
s := &IntSet{}
s.Add(0)
s.Add(1000)
s.Clear()
if s.Has(0) || s.Has(1000) {
t.Log(s)
t.Fail()
}
}
func TestCopy(t *testing.T) {
orig := &IntSet{}
orig.Add(1)
copy := orig.Copy()
copy.Add(2)
if !copy.Has(1) || orig.Has(2) {
t.Log(orig, copy)
t.Fail()
}
}
func TestAddAll(t *testing.T) {
s := &IntSet{}
s.AddAll(0, 2, 4)
if !s.Has(0) || !s.Has(2) || !s.Has(4) {
t.Log(s)
t.Fail()
}
}
func TestIntersectWith(t *testing.T) {
s := &IntSet{}
s.AddAll(0, 2, 4)
u := &IntSet{}
u.AddAll(1, 2, 3)
s.IntersectWith(u)
if !s.Has(2) || s.Len() != 1 {
t.Log(s)
t.Fail()
}
}
func TestDifferenceWith(t *testing.T) {
s := &IntSet{}
s.AddAll(0, 2, 4)
u := &IntSet{}
u.AddAll(1, 2, 3)
s.DifferenceWith(u)
expected := &IntSet{}
expected.AddAll(0, 4)
if s.String() != expected.String() {
t.Log(s)
t.Fail()
}
}
func TestSymmetricDifference(t *testing.T) {
s := &IntSet{}
s.AddAll(0, 2, 4)
u := &IntSet{}
u.AddAll(1, 2, 3)
s.SymmetricDifference(u)
expected := &IntSet{}
expected.AddAll(0, 1, 3, 4)
if s.String() != expected.String() {
t.Log(s)
t.Fail()
}
}