This repository has been archived by the owner on Aug 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
zip_test.go
88 lines (65 loc) · 1.64 KB
/
zip_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
package iter
import (
"testing"
"github.com/barweiss/go-tuple"
"github.com/stretchr/testify/assert"
"mtoohey.com/iter/v2/testutils"
)
func FuzzZip(f *testing.F) {
f.Add([]byte{}, []byte{})
f.Add([]byte{1, 2}, []byte{3, 4})
f.Fuzz(func(t *testing.T, a, b []byte) {
expected := make([]tuple.T2[byte, byte], len(a))
for i := range a {
expected[i] = tuple.New2(a[i], b[i])
}
assert.Equal(t, expected, Zip(Elems(a), Elems(b)).Collect())
})
}
func BenchmarkZip(b *testing.B) {
Zip(Ints[int](), Ints[int]()).Take(uint(b.N)).Consume()
}
func FuzzEnumerate(f *testing.F) {
testutils.AddByteSlices(f)
f.Fuzz(func(t *testing.T, b []byte) {
expected := make([]tuple.T2[int, byte], len(b))
for i, v := range b {
expected[i] = tuple.New2(i, v)
}
assert.Equal(t, expected, Enumerate(Elems(b)).Collect())
})
}
func BenchmarkEnumerate(b *testing.B) {
Enumerate(Ints[int]()).Take(uint(b.N)).Consume()
}
func FuzzUnzip(f *testing.F) {
testutils.AddByteSlices(f)
f.Fuzz(func(t *testing.T, b []byte) {
i := 0
iter := func() (tuple.T2[byte, byte], bool) {
if i < len(b) {
res := tuple.New2(b[i], b[len(b)-1-i])
i++
return res, true
}
var z tuple.T2[byte, byte]
return z, false
}
l, r := Unzip(iter)
bRev := make([]byte, len(b))
for j, v := range b {
bRev[len(b)-1-j] = v
}
assert.Equal(t, b, l.Collect())
assert.Equal(t, bRev, r.Collect())
i = 0
l, r = Unzip(iter)
assert.Equal(t, bRev, r.Collect())
assert.Equal(t, b, l.Collect())
})
}
func BenchmarkUnzip(b *testing.B) {
v1, v2 := Unzip(Zip(Ints[int](), Ints[int]()))
v1.Take(uint(b.N)).Consume()
v2.Take(uint(b.N)).Consume()
}