-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathselect_test.go
86 lines (73 loc) · 1.78 KB
/
select_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
package flinx
import (
"strconv"
"testing"
)
func TestSelect(t *testing.T) {
{
tests := []struct {
input []int
selector func(int) int
output []int
}{
{[]int{1, 2, 3}, func(i int) int {
return i * 2
}, []int{2, 4, 6}},
}
for _, test := range tests {
if q := Select(test.selector)(FromSlice(test.input)); !ValidateQuery(q, test.output) {
t.Errorf("From(%v).Select()=%v expected %v", test.input, ToSlice(q), test.output)
}
}
}
{
tests := []struct {
input string
selector func(rune) string
output []string
}{
{"str", func(i rune) string {
return string(i) + "1"
}, []string{"s1", "t1", "r1"}},
}
for _, test := range tests {
if q := Select(test.selector)(FromString(test.input)); !ValidateQuery(q, test.output) {
t.Errorf("From(%v).Select()=%v expected %v", test.input, ToSlice(q), test.output)
}
}
}
}
func TestSelectIndexed(t *testing.T) {
{
tests := []struct {
input []int
selector func(int, int) int
output []int
}{
{[]int{1, 2, 3}, func(i int, x int) int {
return x * i
}, []int{0, 2, 6}},
}
for _, test := range tests {
if q := SelectIndexed(test.selector)(FromSlice(test.input)); !ValidateQuery(q, test.output) {
t.Errorf("From(%v).SelectIndexed()=%v expected %v", test.input, ToSlice(q), test.output)
}
}
}
{
tests := []struct {
input string
selector func(int, rune) string
output []string
}{
{"str", func(i int, x rune) string {
return string(x) + strconv.Itoa(i)
}, []string{"s0", "t1", "r2"}},
}
for _, test := range tests {
if q := SelectIndexed(test.selector)(FromString(test.input)); !ValidateQuery(q, test.output) {
t.Errorf("From(%v).SelectIndexed()=%v expected %v", test.input, ToSlice(q), test.output)
}
}
}
}