-
Notifications
You must be signed in to change notification settings - Fork 1
/
04_collections_test.go
57 lines (44 loc) · 1 KB
/
04_collections_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
package playing
import (
"maps"
"math/rand/v2"
"slices"
"testing"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"playing/mylist"
"playing/mytree"
)
func TestMyList(t *testing.T) {
l := mylist.Collect(slices.Values(pods))
if l.Len() != len(pods) {
t.Errorf("list length should be %d, but it's %d", len(pods), l.Len())
}
flt := filter(l.Values(), func(pod corev1.Pod) bool {
_, ok := pod.Annotations["pick-me"]
return !ok
})
trs := transform(flt, func(pod corev1.Pod) (types.UID, string) {
return pod.UID, pod.Name
})
for uid, name := range trs {
t.Logf(`{"uid"": %q, "name": %q}`, uid, name)
}
}
func TestMyTree(t *testing.T) {
tr := mytree.New[int]()
length := 0
for range 10 {
if tr.Insert(rand.N[int](100)) {
length++
}
}
if tr.Len() != length {
t.Errorf("tree size should be %d, but it's %d", length, tr.Len())
}
trs := transform(tr.Values(), func(num int) (int, bool) {
return num, num%2 == 0
})
rands := maps.Collect(trs)
t.Logf("%#v\n", rands)
}