-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsink_test.go
More file actions
124 lines (108 loc) · 2.15 KB
/
Copy pathsink_test.go
File metadata and controls
124 lines (108 loc) · 2.15 KB
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
122
123
124
package xiter
import (
"context"
"slices"
"testing"
)
func TestFind(t *testing.T) {
s, _ := Find(Windows(Generate(
0, 1),
3),
func(win []int) bool { return Sum(slices.Values(win)) >= 100 })
if [3]int(s) != [...]int{33, 34, 35} {
t.Fatal(s)
}
}
func TestContains(t *testing.T) {
c := Contains(Of(1, 2, 3), 2)
if !c {
t.Fatal(c)
}
}
func TestSum(t *testing.T) {
s := Sum(slices.Values([]string{"a", " ", "test"}))
if s != "a test" {
t.Fatal(s)
}
}
func TestProduct(t *testing.T) {
p := Product(Of(3, 2, -5))
if p != -30 {
t.Fatal(p)
}
}
func TestPartition(t *testing.T) {
s1, s2 := Partition(Of(1, 2, 3, 4, 5), func(v int) bool { return v%2 == 0 })
if !Equal(slices.Values(s1), Of(2, 4)) {
t.Fatal(s1)
}
if !Equal(slices.Values(s2), Of(1, 3, 5)) {
t.Fatal(s2)
}
}
func TestExtent(t *testing.T) {
s := Of(3, 2, 5, 1, 6, -2, 10)
min := Min(s)
max := Max(s)
if min != -2 {
t.Fatal(min)
}
if max != 10 {
t.Fatal(max)
}
}
func TestAny(t *testing.T) {
r := Any(Of(2, 4, 6, 7), func(v int) bool { return v%2 != 0 })
if !r {
t.Fatal(r)
}
}
func TestAll(t *testing.T) {
r := All(Of(2, 4, 6, 7), func(v int) bool { return v%2 == 0 })
if r {
t.Fatal(r)
}
}
func TestSendContext(t *testing.T) {
c := make(chan int, 3)
SendContext(Of(3, 2, 5), context.Background(), c)
s := []int{<-c, <-c, <-c}
select {
case v := <-c:
t.Fatal(v)
default:
}
if !slices.Equal(s, []int{3, 2, 5}) {
t.Fatal(s)
}
}
func FuzzSendRecvContext(f *testing.F) {
f.Add([]byte("The quick brown fox jumps over the lazy dog."))
f.Fuzz(func(t *testing.T, data []byte) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
c := make(chan byte, len(data))
SendContext(slices.Values(data), ctx, c)
close(c)
s := slices.Collect(RecvContext(ctx, c))
if !slices.Equal(data, s) {
t.Fatal(s)
}
})
}
func TestDrain(t *testing.T) {
v, ok := Drain(Of(3, 2, 5))
if !ok || v != 5 {
t.Fatalf("%v, %v", v, ok)
}
v, ok = Drain(Of[int]())
if ok || v != 0 {
t.Fatalf("%v, %v", v, ok)
}
}
func TestStringJoin(t *testing.T) {
s := StringJoin(Of("this", "is", "a", "test"), " ")
if s != "this is a test" {
t.Fatalf("%q", s)
}
}