From e905c600f3a8de4100d6829a6f95a904503e7df3 Mon Sep 17 00:00:00 2001 From: vinchent Date: Tue, 10 Sep 2024 21:34:27 +0200 Subject: [PATCH] sum: sumAll --- sum/sum.go | 4 ++++ sum/sum_test.go | 24 ++++++++++++------------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/sum/sum.go b/sum/sum.go index a403234..8667504 100644 --- a/sum/sum.go +++ b/sum/sum.go @@ -8,3 +8,7 @@ func Sum(numbers []int) int { } return sum } + +func SumAll(x []int, y []int) []int { + return []int{Sum(x), Sum(y)} +} diff --git a/sum/sum_test.go b/sum/sum_test.go index e925ab5..03f38fd 100644 --- a/sum/sum_test.go +++ b/sum/sum_test.go @@ -1,6 +1,9 @@ package sum -import "testing" +import ( + "slices" + "testing" +) func TestSum(t *testing.T) { t.Run("collection of 5 numbers", func(t *testing.T) { @@ -13,15 +16,12 @@ func TestSum(t *testing.T) { t.Errorf("got %d, expected %d, given %v", got, exp, numbers) } }) - - t.Run("collection of any size", func(t *testing.T) { - numbers := []int{1, 2, 3} - - got := Sum(numbers) - exp := 6 - - if got != exp { - t.Errorf("got %d, expected %d, given %v", got, exp, numbers) - } - }) +} + +func TestSumAll(t *testing.T) { + got := SumAll([]int{1, 2}, []int{0, 9}) + exp := []int{3, 9} + if slices.Compare(got, exp) != 0 { + t.Errorf("got %d, expected %d", got, exp) + } }