-
Notifications
You must be signed in to change notification settings - Fork 9
/
ordered_int_set_test.go
110 lines (92 loc) · 2.27 KB
/
ordered_int_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
package ecs
import "testing"
func TestOrderedIntSet_Add(t *testing.T) {
c := OrderedIntSet[uint16]{}
insert := []uint16{7, 3, 6, 2, 9, 4}
for _, it := range insert {
c.Add(it)
}
want := []uint16{2, 3, 4, 6, 7, 9}
for i := 0; i < len(c); i++ {
if c[i] != want[i] {
t.Errorf("c[%d] = %d, want %d", i, c[i], want[i])
}
}
}
func TestOrderedIntSet_Remove(t *testing.T) {
c := OrderedIntSet[uint16]{}
insert := []uint16{7, 3, 6, 2, 9, 4}
for _, it := range insert {
c.Add(it)
}
c.Remove(3)
c.Add(1)
want := []uint16{1, 2, 4, 6, 7, 9}
for i := 0; i < len(c); i++ {
if c[i] != want[i] {
t.Errorf("c[%d] = %d, want %d", i, c[i], want[i])
}
}
}
func TestOrderedIntSet_InsertIndex(t *testing.T) {
c := OrderedIntSet[uint16]{}
insert := []uint16{7, 3, 6, 2, 9, 4}
for _, it := range insert {
c.Add(it)
}
want := []uint16{2, 3, 4, 6, 7, 9}
for i := 0; i < len(c); i++ {
if c[i] != want[i] {
t.Errorf("c[%d] = %d, want %d", i, c[i], want[i])
}
}
wantIndex := 3
if got := c.InsertIndex(5); got != wantIndex {
t.Errorf("insertIndex() = %v, want %v", got, wantIndex)
}
}
func TestOrderedIntSet_Find(t *testing.T) {
c := OrderedIntSet[uint16]{}
insert := []uint16{7, 3, 6, 2, 9, 4}
for _, it := range insert {
c.Add(it)
}
want := []uint16{2, 3, 4, 6, 7, 9}
for i := 0; i < len(c); i++ {
if c[i] != want[i] {
t.Errorf("c[%d] = %d, want %d", i, c[i], want[i])
}
}
wantIndex := 4
if got := c.Find(7); got != wantIndex {
t.Errorf("Find() = %v, want %v", got, wantIndex)
}
}
func TestOrderedIntSet_IsSubSet(t *testing.T) {
c := OrderedIntSet[uint16]{}
insert := []uint16{7, 3, 6, 2, 9, 4}
for _, it := range insert {
c.Add(it)
}
want := []uint16{2, 3, 4, 6, 7, 9}
for i := 0; i < len(c); i++ {
if c[i] != want[i] {
t.Errorf("c[%d] = %d, want %d", i, c[i], want[i])
}
}
subSet := []uint16{3, 4, 6}
wantBool := true
if got := c.IsSubSet(subSet); got != wantBool {
t.Errorf("IsSubSet() = %v, want %v", got, wantBool)
}
subSet = []uint16{2, 3, 4, 6, 7, 9}
wantBool = true
if got := c.IsSubSet(subSet); got != wantBool {
t.Errorf("IsSubSet() = %v, want %v", got, wantBool)
}
subSet = []uint16{3, 4, 8}
wantBool = false
if got := c.IsSubSet(subSet); got != wantBool {
t.Errorf("IsSubSet() = %v, want %v", got, wantBool)
}
}