forked from rjNemo/underscore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzip_test.go
65 lines (51 loc) · 1.59 KB
/
zip_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
package underscore_test
import (
"reflect"
"testing"
u "github.com/rjNemo/underscore"
)
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 = u.Zip(left, right)
want := []u.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 = u.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 := []u.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 = u.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 := []u.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)
}
}