-
Notifications
You must be signed in to change notification settings - Fork 213
Expand file tree
/
Copy pathadd_slice_of_numbers_test.go
More file actions
36 lines (31 loc) · 1017 Bytes
/
Copy pathadd_slice_of_numbers_test.go
File metadata and controls
36 lines (31 loc) · 1017 Bytes
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
34
35
36
package array
import (
"slices"
"testing"
)
/*
TestAddSliceOfTwoNumbers tests solution(s) with the following signature and problem description:
AddTwoNumbers(num1, num2 []int) []int
A slice representation of a positive integer like 283 looks like {2,8,3}. Given two positive
integers represented in this format return their sum in the same format.
For example given {2,9} and {9,9,9}, return {1,0,2,8}.
Because 29+999=1028.
*/
func TestAddSliceOfTwoNumbers(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 := AddSliceOfTwoNumbers(test.num1, test.num2); !slices.Equal(got, test.sum) {
t.Fatalf("Failed test case #%d. Want %v got %v", i, test.sum, got)
}
}
}