11
11
import com .leetcode .ListNode ;
12
12
13
13
public class SolutionTest {
14
-
14
+
15
15
/** Test method for {@link _002_AddTwoNumbers.Solution } */
16
16
Solution solution ;
17
17
@@ -31,43 +31,66 @@ public void tearDown() throws Exception {
31
31
// 342 + 564 = 807
32
32
@ Test
33
33
public void Test1 () {
34
- int [] nums1 = {2 , 4 , 3 };
35
- int [] nums2 = {5 , 6 , 4 };
34
+ int [] nums1 = { 2 , 4 , 3 };
35
+ int [] nums2 = { 5 , 6 , 4 };
36
36
ListNode a = ListNode .constructLinkedList (nums1 );
37
37
ListNode b = ListNode .constructLinkedList (nums2 );
38
38
ListNode actual = solution .addTwoNumbers (a , b );
39
- int [] exps = {7 , 0 , 8 };
39
+ int [] exps = { 7 , 0 , 8 };
40
40
ListNode expected = ListNode .constructLinkedList (exps );
41
41
assertTrue (ListNode .isSameList (actual , expected ));
42
-
43
42
}
44
43
45
- // 2 + 499 = 501
44
+ // 2 + 499 = 501
46
45
@ Test
47
46
public void Test2 () {
48
- int [] nums1 = {2 };
49
- int [] nums2 = {9 , 9 , 4 };
47
+ int [] nums1 = { 2 };
48
+ int [] nums2 = { 9 , 9 , 4 };
50
49
ListNode a = ListNode .constructLinkedList (nums1 );
51
50
ListNode b = ListNode .constructLinkedList (nums2 );
52
51
ListNode actual = solution .addTwoNumbers (a , b );
53
- int [] exps = {1 , 0 , 5 };
52
+ int [] exps = { 1 , 0 , 5 };
54
53
ListNode expected = ListNode .constructLinkedList (exps );
55
54
assertTrue (ListNode .isSameList (actual , expected ));
56
-
57
55
}
58
56
59
57
// 8 + 2 = 10
60
58
@ Test
61
59
public void Test3 () {
62
- int [] nums1 = {2 };
63
- int [] nums2 = {8 };
60
+ int [] nums1 = { 2 };
61
+ int [] nums2 = { 8 };
62
+ ListNode a = ListNode .constructLinkedList (nums1 );
63
+ ListNode b = ListNode .constructLinkedList (nums2 );
64
+ ListNode actual = solution .addTwoNumbers (a , b );
65
+ int [] exps = { 0 , 1 };
66
+ ListNode expected = ListNode .constructLinkedList (exps );
67
+ assertTrue (ListNode .isSameList (actual , expected ));
68
+ }
69
+
70
+ // 499 + 3 = 502
71
+ @ Test
72
+ public void Test4 () {
73
+ int [] nums1 = { 9 , 9 , 4 };
74
+ int [] nums2 = { 3 };
75
+ ListNode a = ListNode .constructLinkedList (nums1 );
76
+ ListNode b = ListNode .constructLinkedList (nums2 );
77
+ ListNode actual = solution .addTwoNumbers (a , b );
78
+ int [] exps = { 2 , 0 , 5 };
79
+ ListNode expected = ListNode .constructLinkedList (exps );
80
+ assertTrue (ListNode .isSameList (actual , expected ));
81
+ }
82
+
83
+ // 0 + 20 = 20
84
+ @ Test
85
+ public void Test5 () {
86
+ int [] nums1 = { 0 };
87
+ int [] nums2 = { 0 , 2 };
64
88
ListNode a = ListNode .constructLinkedList (nums1 );
65
89
ListNode b = ListNode .constructLinkedList (nums2 );
66
90
ListNode actual = solution .addTwoNumbers (a , b );
67
- int [] exps = {0 , 1 };
91
+ int [] exps = { 0 , 2 };
68
92
ListNode expected = ListNode .constructLinkedList (exps );
69
93
assertTrue (ListNode .isSameList (actual , expected ));
70
-
71
94
}
72
95
73
96
}
0 commit comments