-
Notifications
You must be signed in to change notification settings - Fork 225
/
join_test.go
60 lines (53 loc) · 1.93 KB
/
join_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
package linq
import "testing"
func TestJoin(t *testing.T) {
outer := []int{0, 1, 2, 3, 4, 5, 8}
inner := []int{1, 2, 1, 4, 7, 6, 7, 2}
want := []interface{}{
KeyValue{1, 1},
KeyValue{1, 1},
KeyValue{2, 2},
KeyValue{2, 2},
KeyValue{4, 4},
}
q := From(outer).Join(
From(inner),
func(i interface{}) interface{} { return i },
func(i interface{}) interface{} { return i },
func(outer interface{}, inner interface{}) interface{} {
return KeyValue{outer, inner}
})
if !validateQuery(q, want) {
t.Errorf("From().Join()=%v expected %v", toSlice(q), want)
}
}
func TestJoinT_PanicWhenOuterKeySelectorFnIsInvalid(t *testing.T) {
mustPanicWithError(t, "JoinT: parameter [outerKeySelectorFn] has a invalid function signature. Expected: 'func(T)T', actual: 'func(int,int)int'", func() {
From([]int{0, 1, 2}).JoinT(
From([]int{1, 2, 3, 4, 5, 6, 7, 8, 9}),
func(i, j int) int { return i },
func(i int) int { return i % 2 },
func(outer int, inner int) KeyValue { return KeyValue{outer, inner} },
)
})
}
func TestJoinT_PanicWhenInnerKeySelectorFnIsInvalid(t *testing.T) {
mustPanicWithError(t, "JoinT: parameter [innerKeySelectorFn] has a invalid function signature. Expected: 'func(T)T', actual: 'func(int,int)int'", func() {
From([]int{0, 1, 2}).JoinT(
From([]int{1, 2, 3, 4, 5, 6, 7, 8, 9}),
func(i int) int { return i },
func(i, j int) int { return i % 2 },
func(outer int, inners []int) KeyValue { return KeyValue{outer, len(inners)} },
)
})
}
func TestJoinT_PanicWhenResultSelectorFnIsInvalid(t *testing.T) {
mustPanicWithError(t, "JoinT: parameter [resultSelectorFn] has a invalid function signature. Expected: 'func(T,T)T', actual: 'func(int,int,int)linq.KeyValue'", func() {
From([]int{0, 1, 2}).JoinT(
From([]int{1, 2, 3, 4, 5, 6, 7, 8, 9}),
func(i int) int { return i },
func(i int) int { return i % 2 },
func(outer int, inner, j int) KeyValue { return KeyValue{outer, inner} },
)
})
}