-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiter_test.go
59 lines (55 loc) · 1.04 KB
/
iter_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
package flatmap
import (
"slices"
"testing"
)
func TestFlatMapAll(t *testing.T) {
fm := FlatMap[int, string]{
data: []Pair[int, string]{
{1, "4"},
{2, "3"},
{3, "2"},
{4, "1"},
},
}
count := 0
for k, v := range fm.All() {
count++
if v2, ok := fm.Get(k); !ok || v2 != v {
t.Errorf("got: %v, want: %v", v, v2)
}
}
if count != fm.Length() {
t.Errorf("length got: %v, want: %v", count, fm.Length())
}
}
func TestFlatMapKeys(t *testing.T) {
fm := FlatMap[int, string]{
data: []Pair[int, string]{
{1, "4"},
{2, "3"},
{3, "2"},
{4, "1"},
},
}
values := []int{1, 2, 3, 4}
got := slices.Collect(fm.Keys())
if !slices.Equal(got, values) {
t.Errorf("keys got: %v, want: %v", got, values)
}
}
func TestFlatMapValues(t *testing.T) {
fm := FlatMap[int, string]{
data: []Pair[int, string]{
{1, "4"},
{2, "3"},
{3, "2"},
{4, "1"},
},
}
values := []string{"4", "3", "2", "1"}
got := slices.Collect(fm.Values())
if !slices.Equal(got, values) {
t.Errorf("values got: %v, want: %v", got, values)
}
}