-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset_test.go
77 lines (66 loc) · 1.43 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
package armap
import (
"strconv"
"testing"
)
func TestSet(t *testing.T) {
t.Run("10000", func(tt *testing.T) {
N := 10_000
a := NewArena(1024*1024, 4)
defer a.Release()
m := NewSet[string](a, WithCapacity(N))
keys := make([]string, N)
for i := 0; i < N; i += 1 {
keys[i] = strconv.Itoa(i)
}
for _, k := range keys {
if ok := m.Add(k); ok {
tt.Errorf("key %s is new key", k)
}
}
for _, k := range keys {
if ok := m.Contains(k); ok != true {
tt.Errorf("key %s is already Set", k)
}
}
for _, k := range keys {
if ok := m.Delete(k); ok != true {
tt.Errorf("key %s exists", k)
}
}
for _, k := range keys {
if ok := m.Contains(k); ok {
tt.Errorf("key %s deleted", k)
}
}
})
t.Run("string", func(tt *testing.T) {
a := NewArena(1000, 10)
defer a.Release()
s := NewSet[string](a)
if ok := s.Add("test1"); ok {
tt.Errorf("test1 is new key")
}
if ok := s.Add("test2"); ok {
tt.Errorf("test2 is new key")
}
if ok := s.Add("test3"); ok {
tt.Errorf("test3 is new key")
}
if ok := s.Contains("test1"); ok != true {
tt.Errorf("test1 is exists")
}
if ok := s.Add("test1"); ok != true {
tt.Errorf("test1 already exists")
}
if ok := s.Delete("test1"); ok != true {
tt.Errorf("test1 is exists")
}
if ok := s.Delete("not found"); ok {
tt.Errorf("not found key")
}
if ok := s.Contains("test1"); ok {
tt.Errorf("test1 is deleted")
}
})
}