-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjoin_test.go
More file actions
88 lines (75 loc) · 1.45 KB
/
join_test.go
File metadata and controls
88 lines (75 loc) · 1.45 KB
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 glinq
import (
"testing"
"github.com/rlarkin212/glinq/internal"
)
type jwFun[T any] func(x T) bool
type joinTest[T any] struct {
input [][]T
expected []T
}
type joinWhereTest[T any] struct {
input [][]T
fun jwFun[T]
expected []T
}
var joinTestDataInt = []joinTest[int]{
{
input: [][]int{
{1, 2, 3, 4, 5},
{6, 7},
{8, 9},
{10},
},
expected: []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
},
{
input: [][]int{
{6, 7},
{10},
},
expected: []int{6, 7, 10},
},
}
var joinWhereTestDataInt = []joinWhereTest[int]{
{
input: [][]int{
{1, 2, 3, 4, 5},
{6, 7},
{8, 9},
{10},
},
fun: func(x int) bool {
return x%2 == 0
},
expected: []int{2, 4, 6, 8, 10},
},
{
input: [][]int{
{6, 7},
{10},
},
fun: func(x int) bool {
return x/2 == 3 || x/2 == 5
},
expected: []int{6, 7, 10},
},
}
func TestJoin(t *testing.T) {
for _, test := range joinTestDataInt {
actual := Join(test.input...)
if ok := internal.SliceCompare(test.expected, actual); !ok {
t.Errorf("expected %v; actual %v", test.expected, actual)
t.Fail()
}
}
}
func TestJoinWhere(t *testing.T) {
for _, test := range joinWhereTestDataInt {
actual := JoinWhere(test.fun, test.input...)
if ok := internal.SliceCompare(test.expected, actual); !ok {
t.Errorf("expected %v; actual %v", test.expected, actual)
t.Fail()
}
}
}