-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilter_test.go
More file actions
40 lines (35 loc) · 859 Bytes
/
Filter_test.go
File metadata and controls
40 lines (35 loc) · 859 Bytes
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
package omap
import (
"cmp"
"testing"
)
func TestFilter(t *testing.T) {
st := NewSliceTree[int, int](5, cmp.Compare).ToTs()
ct := NewCenterTree[int, int](5, cmp.Compare).ToTs()
names := []string{"SliceTree", "CenterTree"}
for test, s := range []OrderedMap[int, int]{st, ct} {
name := names[test]
t.Logf("Starting remove test of: %s", name)
for k := range 5 {
s.Put(k, k)
}
s.Filter(func(k, v int) bool {
remove := k == 1 || k == 3
if remove {
t.Logf("Removing Key: %d", k)
}
return remove
})
if s.Size() != 3 {
t.Log("Test failed, dumping array contents")
for k, v := range s.All() {
t.Logf("Have key: %d, value: %d", k, v)
}
t.Fatalf("Expected a size of: 3, got: %d", s.Size())
}
s.Filter(func(k, v int) bool { return true })
if s.Size() != 0 {
t.Fatalf("Expected an empty set!")
}
}
}