-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_test.go
53 lines (45 loc) · 880 Bytes
/
main_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
package main
import (
"iter"
"math/rand"
"strconv"
"strings"
"testing"
)
var (
sizes = []int{10, 100, 500, 1000}
needles = []int{10, 100, 500, 1000}
)
func testingSlice(size int) []int {
var ts = make([]int, size)
for i := 0; i < size; i++ {
ts[i] = rand.Intn(size)
}
return ts
}
func testingIter(size int) iter.Seq[int] {
return func(yield func(int) bool) {
for i := 0; i < size; i++ {
if !yield(rand.Intn(size)) {
return
}
}
}
}
func testingString(size int) string {
var builder strings.Builder
for i := 0; i < size; i++ {
builder.WriteString(strconv.Itoa(rand.Intn(size)))
}
return builder.String()
}
func TestIter(t *testing.T) {
size := 10
var accum []int
for val := range testingIter(size) {
accum = append(accum, val)
}
if len(accum) != size {
t.Errorf("expect size of accum to be: %v, got: %v", size, len(accum))
}
}