-
Notifications
You must be signed in to change notification settings - Fork 0
/
hashset_test.go
60 lines (51 loc) · 963 Bytes
/
hashset_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
package hashset
import (
"fmt"
"testing"
)
func Example() {
l := NewInt64()
for _, v := range []int{10, 12, 15} {
l.Add(int64(v))
}
if l.Contains(10) {
fmt.Println("hashset contains 10")
}
l.Range(func(value int64) bool {
fmt.Println("hashset range found ", value)
return true
})
l.Remove(15)
fmt.Printf("hashset contains %d items\r\n", l.Len())
}
func TestIntSet(t *testing.T) {
// Correctness.
l := NewInt64()
if l.Len() != 0 {
t.Fatal("invalid length")
}
if l.Contains(0) {
t.Fatal("invalid contains")
}
if l.Add(0); l.Len() != 1 {
t.Fatal("invalid add")
}
if !l.Contains(0) {
t.Fatal("invalid contains")
}
if l.Remove(0); l.Len() != 0 {
t.Fatal("invalid remove")
}
if l.Add(20); l.Len() != 1 {
t.Fatal("invalid add")
}
if l.Add(22); l.Len() != 2 {
t.Fatal("invalid add")
}
if l.Add(21); l.Len() != 3 {
t.Fatal("invalid add")
}
if l.Add(21); l.Len() != 3 {
t.Fatal(l.Len(), " invalid add")
}
}