Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 24_testing/math.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
23 changes: 20 additions & 3 deletions 24_testing/math_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}
}

Expand Down