-
Notifications
You must be signed in to change notification settings - Fork 62
/
add_two_numbers_test.go
33 lines (29 loc) · 894 Bytes
/
add_two_numbers_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package array
import (
"reflect"
"testing"
)
/*
TestAddTwoNumbers tests solution(s) with the following signature and problem description:
AddTwoNumbers(num1, num2 []int) []int
Given two numbers as an array like [2,9] and [9,9,9] return the sum of the numbers they
represent like [1,0,2,8], because 29+999=1028.
*/
func TestAddTwoNumbers(t *testing.T) {
tests := []struct {
num1, num2, sum []int
}{
{[]int{1}, []int{}, []int{1}},
{[]int{1}, []int{0}, []int{1}},
{[]int{1}, []int{1}, []int{2}},
{[]int{1}, []int{9}, []int{1, 0}},
{[]int{2, 5}, []int{3, 5}, []int{6, 0}},
{[]int{2, 9}, []int{9, 9, 9}, []int{1, 0, 2, 8}},
{[]int{9, 9, 9}, []int{9, 9, 9}, []int{1, 9, 9, 8}},
}
for i, test := range tests {
if got := AddTwoNumbers(test.num1, test.num2); !reflect.DeepEqual(got, test.sum) {
t.Fatalf("Failed test case #%d. Want %v got %v", i, test.sum, got)
}
}
}