-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcov_test.go
121 lines (115 loc) · 2.48 KB
/
cov_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
111
112
113
114
115
116
117
118
119
120
121
package iterset
import (
"iter"
"maps"
"slices"
"strings"
"testing"
)
func TestBreak(t *testing.T) {
k := slices.Values([]string{"a", "A"})
for range Unique(k) {
break
}
for range UniqueBy(k, strings.ToLower) {
break
}
for range Compact(k) {
break
}
for range CompactBy(k, strings.TrimSpace) {
break
}
for range Set("a").Intersect(k) {
break
}
for range Intersect(k, slices.Values([]string{"A"})) {
break
}
for range Intersect(k, slices.Values([]string{})) {
}
for range Intersect(k, k) {
break
}
for range Set("b").Difference(k) {
break
}
for range Difference(k, slices.Values([]string{})) {
break
}
for range Set("b").ReverseDifference(k) {
break
}
for range Set("b").SymmetricDifference(k) {
break
}
for c := range Set("b").SymmetricDifference(k) {
if c == "b" {
break
}
}
for range SortedUnion(k, slices.Values([]string{})) {
break
}
for range SortedUnion(k, slices.Values([]string{""})) {
break
}
for range SortedIntersect(k, slices.Values([]string{"a"})) {
break
}
for range SortedDifference(k, slices.Values([]string{"a"})) {
break
}
for range Keys(slices.All([]string{""})) {
break
}
}
func TestExit(t *testing.T) {
k := slices.Values([]string{"a", "A"})
for c := range Index(k).Difference(k) {
t.Errorf("should be empty: %s", c)
}
for c := range Index(k).SymmetricDifference(k) {
t.Errorf("should be empty: %s", c)
}
if IsSubset(slices.Values([]string{"b"}), k) {
t.Errorf("should be false")
}
}
func TestEmpty(t *testing.T) {
var m MapSet[string, struct{}]
if m.Union() == nil {
t.Error("should not be nil")
}
for range m.Intersect(nil) {
t.Error("should be empty")
}
for range Intersect(maps.Keys(m), maps.Keys(m)) {
t.Error("should be empty")
}
for range m.ReverseDifference(maps.Keys(m)) {
t.Error("should be empty")
}
for range m.SymmetricDifference(maps.Keys(m)) {
t.Error("should be empty")
}
m.Delete("")
m.Remove(slices.Values([]string{""}))
}
func assertMulti[K any](t *testing.T, seq iter.Seq[K]) {
count := Size(seq)
if Size(seq) != count {
t.Error("should not be single-use")
}
}
func TestMulti(t *testing.T) {
k := slices.Values([]string{"a", "A", "b"})
assertMulti(t, difference(k, k))
assertMulti(t, intersect(k, k))
assertMulti(t, Unique(k))
assertMulti(t, Keys(UniqueBy(k, strings.ToLower)))
assertMulti(t, Keys(Compact(k)))
assertMulti(t, Keys(CompactBy(k, strings.ToLower)))
assertMulti(t, Keys(Set("b").Difference(k)))
assertMulti(t, Set("b").SymmetricDifference(k))
}