|
| 1 | +package underscore_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "reflect" |
| 5 | + "testing" |
| 6 | + |
| 7 | + u "github.com/rjNemo/underscore" |
| 8 | +) |
| 9 | + |
| 10 | +func Test_Zip_Can_Zip_Two_Equal_Sized_Slices(t *testing.T) { |
| 11 | + left := []string{"Left 1", "Left 2", "Left 3"} |
| 12 | + right := []int{1, 2, 3} |
| 13 | + |
| 14 | + var zipped = u.Zip(left, right) |
| 15 | + |
| 16 | + want := []u.Tuple[string, int]{ |
| 17 | + {Left: "Left 1", Right: 1}, |
| 18 | + {Left: "Left 2", Right: 2}, |
| 19 | + {Left: "Left 3", Right: 3}, |
| 20 | + } |
| 21 | + |
| 22 | + if !reflect.DeepEqual(zipped, want) { |
| 23 | + t.Errorf("Expected the result to be %v but we got %v", want, zipped) |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +func Test_Zip_Can_Zip_Two_Different_Sized_Slices_Left_Larger(t *testing.T) { |
| 28 | + left := []string{"Left 1", "Left 2", "Left 3", "Left 4"} |
| 29 | + right := []int{1, 2, 3} |
| 30 | + |
| 31 | + var zipped = u.Zip(left, right) |
| 32 | + if len(zipped) != 3 { |
| 33 | + t.Errorf("Expected the result of Zip(left, right) to have a length of 3 but got %v", len(zipped)) |
| 34 | + } |
| 35 | + |
| 36 | + want := []u.Tuple[string, int]{ |
| 37 | + {Left: "Left 1", Right: 1}, |
| 38 | + {Left: "Left 2", Right: 2}, |
| 39 | + {Left: "Left 3", Right: 3}, |
| 40 | + } |
| 41 | + |
| 42 | + if !reflect.DeepEqual(zipped, want) { |
| 43 | + t.Errorf("Expected the result to be %v but we got %v", want, zipped) |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +func Test_Zip_Can_Zip_Two_Different_Sized_Slices_Right_Larger(t *testing.T) { |
| 48 | + left := []string{"Left 1", "Left 2", "Left 3"} |
| 49 | + right := []int{1, 2, 3, 4} |
| 50 | + |
| 51 | + var zipped = u.Zip(left, right) |
| 52 | + if len(zipped) != 3 { |
| 53 | + t.Errorf("Expected the result of Zip(left, right) to have a length of 3 but got %v", len(zipped)) |
| 54 | + } |
| 55 | + |
| 56 | + want := []u.Tuple[string, int]{ |
| 57 | + {Left: "Left 1", Right: 1}, |
| 58 | + {Left: "Left 2", Right: 2}, |
| 59 | + {Left: "Left 3", Right: 3}, |
| 60 | + } |
| 61 | + |
| 62 | + if !reflect.DeepEqual(zipped, want) { |
| 63 | + t.Errorf("Expected the result to be %v but we got %v", want, zipped) |
| 64 | + } |
| 65 | +} |
0 commit comments