-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_two_numbers_test.go
61 lines (55 loc) · 1.32 KB
/
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
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 problem0002
import (
"fmt"
. "leetcodedaily/helpers/listnode"
"testing"
"github.com/stretchr/testify/assert"
)
type Result struct {
L1 *ListNode
L2 *ListNode
Expected *ListNode
}
var Results = []Result{
{
L1: MakeListNode(2, 4, 3),
L2: MakeListNode(5, 6, 4),
Expected: MakeListNode(7, 0, 8),
},
{
L1: MakeListNode(0),
L2: MakeListNode(0),
Expected: MakeListNode(0),
},
{
L1: MakeListNode(1),
L2: MakeListNode(1),
Expected: MakeListNode(2),
},
{
L1: MakeListNode(9, 9, 9, 9, 9, 9, 9),
L2: MakeListNode(9, 9, 9, 9),
Expected: MakeListNode(8, 9, 9, 9, 0, 0, 0, 1),
},
{
L1: MakeListNode(9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9),
L2: MakeListNode(9, 9, 9, 9),
Expected: MakeListNode(8, 9, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1),
},
}
func TestAddTwoNumbers(t *testing.T) {
assert := assert.New(t)
addTwoPrinter := func(r Result, g *ListNode) string {
return fmt.Sprintf(
"L1 - %s\nL2 - %s\nExp - %s\nGot - %s",
r.L1.String(),
r.L2.String(),
r.Expected.String(),
g.String())
}
for _, res := range Results {
want := res.Expected
got := addTwoNumbers(res.L1, res.L2)
assert.Equal(want, got, addTwoPrinter(res, got))
}
}