Skip to content

Commit 101deaa

Browse files
committed
002 (3) update tests
1 parent f807716 commit 101deaa

File tree

2 files changed

+73
-27
lines changed

2 files changed

+73
-27
lines changed

test/_002_AddTwoNumbers/PracticeTest.java

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,43 +31,66 @@ public void tearDown() throws Exception {
3131
// 342 + 564 = 807
3232
@Test
3333
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 };
3636
ListNode a = ListNode.constructLinkedList(nums1);
3737
ListNode b = ListNode.constructLinkedList(nums2);
3838
ListNode actual = solution.addTwoNumbers(a, b);
39-
int[] exps = {7, 0, 8};
39+
int[] exps = { 7, 0, 8 };
4040
ListNode expected = ListNode.constructLinkedList(exps);
4141
assertTrue(ListNode.isSameList(actual, expected));
42-
4342
}
4443

45-
// 2 + 499 = 501
44+
// 2 + 499 = 501
4645
@Test
4746
public void Test2() {
48-
int[] nums1 = {2};
49-
int[] nums2 = {9, 9, 4};
47+
int[] nums1 = { 2 };
48+
int[] nums2 = { 9, 9, 4 };
5049
ListNode a = ListNode.constructLinkedList(nums1);
5150
ListNode b = ListNode.constructLinkedList(nums2);
5251
ListNode actual = solution.addTwoNumbers(a, b);
53-
int[] exps = {1, 0, 5};
52+
int[] exps = { 1, 0, 5 };
5453
ListNode expected = ListNode.constructLinkedList(exps);
5554
assertTrue(ListNode.isSameList(actual, expected));
56-
5755
}
5856

5957
// 8 + 2 = 10
6058
@Test
6159
public void Test3() {
62-
int[] nums1 = {2};
63-
int[] nums2 = {8};
60+
int[] nums1 = { 2 };
61+
int[] nums2 = { 8 };
6462
ListNode a = ListNode.constructLinkedList(nums1);
6563
ListNode b = ListNode.constructLinkedList(nums2);
6664
ListNode actual = solution.addTwoNumbers(a, b);
67-
int[] exps = {0, 1};
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 };
88+
ListNode a = ListNode.constructLinkedList(nums1);
89+
ListNode b = ListNode.constructLinkedList(nums2);
90+
ListNode actual = solution.addTwoNumbers(a, b);
91+
int[] exps = { 0, 2 };
6892
ListNode expected = ListNode.constructLinkedList(exps);
6993
assertTrue(ListNode.isSameList(actual, expected));
70-
7194
}
7295

7396
}

test/_002_AddTwoNumbers/SolutionTest.java

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import com.leetcode.ListNode;
1212

1313
public class SolutionTest {
14-
14+
1515
/** Test method for {@link _002_AddTwoNumbers.Solution } */
1616
Solution solution;
1717

@@ -31,43 +31,66 @@ public void tearDown() throws Exception {
3131
// 342 + 564 = 807
3232
@Test
3333
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 };
3636
ListNode a = ListNode.constructLinkedList(nums1);
3737
ListNode b = ListNode.constructLinkedList(nums2);
3838
ListNode actual = solution.addTwoNumbers(a, b);
39-
int[] exps = {7, 0, 8};
39+
int[] exps = { 7, 0, 8 };
4040
ListNode expected = ListNode.constructLinkedList(exps);
4141
assertTrue(ListNode.isSameList(actual, expected));
42-
4342
}
4443

45-
// 2 + 499 = 501
44+
// 2 + 499 = 501
4645
@Test
4746
public void Test2() {
48-
int[] nums1 = {2};
49-
int[] nums2 = {9, 9, 4};
47+
int[] nums1 = { 2 };
48+
int[] nums2 = { 9, 9, 4 };
5049
ListNode a = ListNode.constructLinkedList(nums1);
5150
ListNode b = ListNode.constructLinkedList(nums2);
5251
ListNode actual = solution.addTwoNumbers(a, b);
53-
int[] exps = {1, 0, 5};
52+
int[] exps = { 1, 0, 5 };
5453
ListNode expected = ListNode.constructLinkedList(exps);
5554
assertTrue(ListNode.isSameList(actual, expected));
56-
5755
}
5856

5957
// 8 + 2 = 10
6058
@Test
6159
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 };
6488
ListNode a = ListNode.constructLinkedList(nums1);
6589
ListNode b = ListNode.constructLinkedList(nums2);
6690
ListNode actual = solution.addTwoNumbers(a, b);
67-
int[] exps = {0, 1};
91+
int[] exps = { 0, 2 };
6892
ListNode expected = ListNode.constructLinkedList(exps);
6993
assertTrue(ListNode.isSameList(actual, expected));
70-
7194
}
7295

7396
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy