From eef2c88787067a1444ccdf9b46697a4374462de5 Mon Sep 17 00:00:00 2001 From: Arjun Mahishi Date: Mon, 8 Oct 2018 23:07:48 +0530 Subject: [PATCH 1/2] Modified to write it in a more standard way. --- 24_testing/math_test.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/24_testing/math_test.go b/24_testing/math_test.go index 76b78e7f..55e4c779 100755 --- a/24_testing/math_test.go +++ b/24_testing/math_test.go @@ -7,9 +7,26 @@ import ( ) func TestAdder(t *testing.T) { - result := Adder(4, 7) - if result != 11 { - t.Fatal("4 + 7 did not equal 11") + type args struct { + xs []int + } + tests := []struct { + name string + args args + want int + }{ + { + name: "Simple test case. Adding 4 and 7.", + args: args{xs: []int{4, 7}}, + want: 11, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := Adder(tt.args.xs...); got != tt.want { + t.Errorf("Adder() = %v, want %v", got, tt.want) + } + }) } } From 5b875a21026fc1087684af0a21cd1f81d73e18f8 Mon Sep 17 00:00:00 2001 From: Arjun Mahishi Date: Mon, 8 Oct 2018 23:08:38 +0530 Subject: [PATCH 2/2] Added comment to adder --- 24_testing/math.go | 1 + 1 file changed, 1 insertion(+) diff --git a/24_testing/math.go b/24_testing/math.go index 6de51307..3c1f87bc 100755 --- a/24_testing/math.go +++ b/24_testing/math.go @@ -1,5 +1,6 @@ package math +// Adder returns the sum of two or more integers func Adder(xs ...int) int { res := 0 for _, v := range xs {