Skip to content

Commit bcd7cdd

Browse files
committed
✨ (sum_tail_test): add test for empty slice
1 parent 511946e commit bcd7cdd

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

arrays-and-slices/sum_test.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,19 @@ func TestSumAll(t *testing.T) {
4949
}
5050

5151
func TestSumAllTails(t *testing.T) {
52+
t.Run("make the sums of some slices", func(t *testing.T) {
53+
got := SumAllTails([]int{1, 2}, []int{0, 9})
54+
want := []int{2, 9}
5255

53-
got := SumAllTails([]int{1, 2}, []int{0, 9})
54-
want := []int{2, 9}
55-
56-
if !reflect.DeepEqual(got, want) {
57-
t.Errorf("got %v, want %v", got, want)
58-
}
56+
if !reflect.DeepEqual(got, want) {
57+
t.Errorf("got %v, want %v", got, want)
58+
}
59+
})
60+
t.Run("safely sum empty slices", func(t *testing.T) {
61+
got := SumAllTails([]int{}, []int{3, 4, 5})
62+
want := []int{0, 9}
63+
if !reflect.DeepEqual(got, want) {
64+
t.Errorf("got %v, want %v", got, want)
65+
}
66+
})
5967
}

0 commit comments

Comments
 (0)