-
Notifications
You must be signed in to change notification settings - Fork 1
/
Funky_test.go
85 lines (67 loc) · 2.32 KB
/
Funky_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
package MultiElo
import (
"reflect"
"testing"
)
func Test_Zip_Can_Zip_Two_Equal_Sized_Slices(t *testing.T) {
left := []string{"Left 1", "Left 2", "Left 3"}
right := []int{1, 2, 3}
var zipped = Zip(left, right)
want := []Tuple[string, int]{
{Left: "Left 1", Right: 1},
{Left: "Left 2", Right: 2},
{Left: "Left 3", Right: 3},
}
if !reflect.DeepEqual(zipped, want) {
t.Errorf("Expected the result to be %v but we got %v", want, zipped)
}
}
func Test_Zip_Can_Zip_Two_Different_Sized_Slices_Left_Larger(t *testing.T) {
left := []string{"Left 1", "Left 2", "Left 3", "Left 4"}
right := []int{1, 2, 3}
var zipped = Zip(left, right)
if len(zipped) != 3 {
t.Errorf("Expected the result of Zip(left, right) to have a length of 3 but got %v", len(zipped))
}
want := []Tuple[string, int]{
{Left: "Left 1", Right: 1},
{Left: "Left 2", Right: 2},
{Left: "Left 3", Right: 3},
}
if !reflect.DeepEqual(zipped, want) {
t.Errorf("Expected the result to be %v but we got %v", want, zipped)
}
}
func Test_Zip_Can_Zip_Two_Different_Sized_Slices_Right_Larger(t *testing.T) {
left := []string{"Left 1", "Left 2", "Left 3"}
right := []int{1, 2, 3, 4}
var zipped = Zip(left, right)
if len(zipped) != 3 {
t.Errorf("Expected the result of Zip(left, right) to have a length of 3 but got %v", len(zipped))
}
want := []Tuple[string, int]{
{Left: "Left 1", Right: 1},
{Left: "Left 2", Right: 2},
{Left: "Left 3", Right: 3},
}
if !reflect.DeepEqual(zipped, want) {
t.Errorf("Expected the result to be %v but we got %v", want, zipped)
}
}
func Test_Join_Can_Join_Two_Slices_Together(t *testing.T) {
one := Tuple[int, string]{Left: 1, Right: "One"}
two := Tuple[int, string]{Left: 2, Right: "Two"}
three := Tuple[int, string]{Left: 3, Right: "Three"}
var left = []Tuple[int, string]{one, two, three}
var right = []Tuple[int, string]{one, three, two, three, two, three}
selector := func(x Tuple[int, string]) int { return x.Left }
var joined = Join(left, right, selector, selector)
var want = []Tuple[Tuple[int, string], []Tuple[int, string]]{
{Left: one, Right: []Tuple[int, string]{one}},
{Left: two, Right: []Tuple[int, string]{two, two}},
{Left: three, Right: []Tuple[int, string]{three, three, three}},
}
if !reflect.DeepEqual(joined, want) {
t.Errorf("Expected to get %v but we got %v instead", want, joined)
}
}