-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathfunc_test.go
50 lines (44 loc) · 820 Bytes
/
func_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
package classifier
import (
"strings"
"testing"
)
var words = []string{
"hello", "world",
}
func streamWords() chan string {
stream := make(chan string)
go func() {
for _, word := range words {
stream <- word
}
close(stream)
}()
return stream
}
func TestMap(t *testing.T) {
i := 0
results := Map(streamWords(), strings.ToUpper)
for word := range results {
expected := strings.ToUpper(words[i])
if expected != word {
t.Errorf("did not match expected result %v <> %v", expected, word)
}
i++
}
}
func TestFilter(t *testing.T) {
results := Filter(streamWords(), func(s string) bool {
return s != words[0]
})
i := 0
for word := range results {
i++
if word != words[1] {
t.Error("incorrect result:", word)
}
}
if i != 1 {
t.Error("incorrect number of results:", i)
}
}