From 2353543f7d963967b0b6d951bab345b8e5aef4a5 Mon Sep 17 00:00:00 2001 From: vinchent Date: Tue, 10 Sep 2024 21:56:18 +0200 Subject: [PATCH] sum: add local test check function --- sum/sum_test.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/sum/sum_test.go b/sum/sum_test.go index 81c176c..09c5c5b 100644 --- a/sum/sum_test.go +++ b/sum/sum_test.go @@ -28,21 +28,23 @@ func TestSumAll(t *testing.T) { } func TestSumAllTails(t *testing.T) { + checkSums := func(t *testing.T, got, exp []int) { + if !slices.Equal(got, exp) { + t.Errorf("got %d, expected %d", got, exp) + } + } + t.Run("make the sums of some slices", func(t *testing.T) { got := SumAllTails([]int{1, 2}, []int{0, 9}) exp := []int{2, 9} - if !slices.Equal(got, exp) { - t.Errorf("got %d, expected %d", got, exp) - } + checkSums(t, got, exp) }) t.Run("safely sum empty slices", func(t *testing.T) { got := SumAllTails([]int{}, []int{3, 4, 5}) exp := []int{0, 9} - if !slices.Equal(got, exp) { - t.Errorf("got %d, expected %d", got, exp) - } + checkSums(t, got, exp) }) }