-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_numbers_ii_test.go
61 lines (53 loc) · 1.5 KB
/
add_numbers_ii_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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package problem0445
import (
"fmt"
"testing"
. "leetcodedaily/helpers/listnode"
"github.com/stretchr/testify/assert"
)
type TestCase struct {
L1, L2 *ListNode
Expected *ListNode
}
var TestCases = []TestCase{
{
MakeListNode(7, 2, 4, 3),
MakeListNode(5, 6, 4),
MakeListNode(7, 8, 0, 7),
},
{
MakeListNode(2, 4, 3),
MakeListNode(5, 6, 4),
MakeListNode(8, 0, 7),
},
{
MakeListNode(0),
MakeListNode(0),
MakeListNode(0),
},
{
MakeListNode(2, 4, 3, 2, 4, 3, 2, 4, 3, 2, 4, 3, 2, 4, 3, 2, 4, 3, 2, 4, 3, 2, 4, 3, 2, 4, 3, 2, 4, 3, 2, 4, 3, 2, 4, 3, 2, 4, 3, 2, 4, 3, 2, 4, 3, 2, 4, 3, 2, 4, 3, 2, 4, 3, 2, 4, 3, 2, 4, 3, 9),
MakeListNode(5, 6, 4, 2, 4, 3, 2, 4, 3, 2, 4, 3, 2, 4, 3, 2, 4, 3, 2, 4, 3, 2, 4, 3, 2, 4, 3, 2, 4, 3, 2, 4, 3, 2, 4, 3, 2, 4, 3, 2, 4, 3, 2, 4, 3, 2, 4, 3, 2, 4, 3, 2, 4, 3, 2, 4, 3, 9, 9, 9, 9),
MakeListNode(8, 0, 7, 4, 8, 6, 4, 8, 6, 4, 8, 6, 4, 8, 6, 4, 8, 6, 4, 8, 6, 4, 8, 6, 4, 8, 6, 4, 8, 6, 4, 8, 6, 4, 8, 6, 4, 8, 6, 4, 8, 6, 4, 8, 6, 4, 8, 6, 4, 8, 6, 4, 8, 6, 4, 8, 7, 2, 4, 3, 8),
},
{
MakeListNode(5, 0, 0, 0),
MakeListNode(5, 0, 0, 0),
MakeListNode(1, 0, 0, 0, 0),
},
}
func TestAddTwoNumbersII(t *testing.T) {
assert := assert.New(t)
for _, tc := range TestCases {
want := tc.Expected
got := addTwoNumbers(tc.L1, tc.L2)
assert.Equal(want.String(), got.String(), fmt.Sprintf("%+v", tc))
}
}
func BenchmarkAddTwoNumbersII(b *testing.B) {
for i := 0; i < b.N; i++ {
for _, tc := range TestCases {
addTwoNumbers(tc.L1, tc.L2)
}
}
}