Skip to content

Commit a087ce4

Browse files
committed
♻️ (sum_tail): refactor sum_tail
1 parent 6e0937e commit a087ce4

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

arrays-and-slices/sum_test.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,20 @@ 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}
55-
52+
checkSums := func(t testing.TB, got, want []int) {
53+
t.Helper()
5654
if !reflect.DeepEqual(got, want) {
5755
t.Errorf("got %v, want %v", got, want)
5856
}
57+
}
58+
t.Run("make the sums of some slices", func(t *testing.T) {
59+
got := SumAllTails([]int{1, 2}, []int{0, 9})
60+
want := []int{2, 9}
61+
checkSums(t, got, want)
5962
})
6063
t.Run("safely sum empty slices", func(t *testing.T) {
6164
got := SumAllTails([]int{}, []int{3, 4, 5})
6265
want := []int{0, 9}
63-
if !reflect.DeepEqual(got, want) {
64-
t.Errorf("got %v, want %v", got, want)
65-
}
66+
checkSums(t, got, want)
6667
})
6768
}

0 commit comments

Comments
 (0)