|
1 | 1 | package com.fishercoder;
|
2 | 2 |
|
3 | 3 | import com.fishercoder.common.classes.ListNode;
|
| 4 | +import com.fishercoder.common.utils.LinkedListUtils; |
4 | 5 | import com.fishercoder.solutions._82;
|
5 | 6 | import org.junit.Assert;
|
| 7 | +import org.junit.BeforeClass; |
6 | 8 | import org.junit.Test;
|
7 | 9 |
|
8 |
| -/** |
9 |
| - * Created by fishercoder on 5/1/17. |
10 |
| - */ |
11 | 10 | public class _82Test {
|
12 | 11 |
|
13 |
| - @Test |
14 |
| - public void test1() { |
15 |
| - ListNode head = new ListNode(1); |
16 |
| - head.next = new ListNode(2); |
17 |
| - head.next.next = new ListNode(3); |
18 |
| - head.next.next.next = new ListNode(3); |
19 |
| - head.next.next.next.next = new ListNode(4); |
20 |
| - head.next.next.next.next.next = new ListNode(4); |
21 |
| - head.next.next.next.next.next.next = new ListNode(5); |
22 |
| - |
23 |
| - _82 test = new _82(); |
24 |
| - |
25 |
| - ListNode expected = new ListNode(1); |
26 |
| - expected.next = new ListNode(2); |
27 |
| - expected.next.next = new ListNode(5); |
28 |
| - |
29 |
| - Assert.assertEquals(expected, test.deleteDuplicates(head)); |
30 |
| - } |
31 |
| - |
32 |
| - @Test |
33 |
| - public void test2() { |
34 |
| - ListNode head = new ListNode(1); |
35 |
| - head.next = new ListNode(1); |
36 |
| - head.next.next = new ListNode(1); |
37 |
| - head.next.next.next = new ListNode(2); |
38 |
| - head.next.next.next.next = new ListNode(3); |
39 |
| - |
40 |
| - _82 test = new _82(); |
41 |
| - |
42 |
| - ListNode expected = new ListNode(2); |
43 |
| - expected.next = new ListNode(3); |
44 |
| - |
45 |
| - Assert.assertEquals(expected, test.deleteDuplicates(head)); |
46 |
| - } |
47 |
| - |
48 |
| - @Test |
49 |
| - public void test3() { |
50 |
| - ListNode head = new ListNode(1); |
51 |
| - head.next = new ListNode(1); |
52 |
| - |
53 |
| - _82 test = new _82(); |
54 |
| - |
55 |
| - ListNode expected = null; |
56 |
| - Assert.assertEquals(expected, test.deleteDuplicates(head)); |
57 |
| - } |
| 12 | + private static _82.Solution1 solution1; |
| 13 | + private static ListNode head; |
| 14 | + private static ListNode expected; |
| 15 | + |
| 16 | + @BeforeClass |
| 17 | + public static void setup() { |
| 18 | + solution1 = new _82.Solution1(); |
| 19 | + } |
| 20 | + |
| 21 | + @Test |
| 22 | + public void test1() { |
| 23 | + head = LinkedListUtils.contructLinkedList(new int[] {1, 2, 3, 3, 4, 4, 5}); |
| 24 | + expected = LinkedListUtils.contructLinkedList(new int[] {1, 2, 5}); |
| 25 | + Assert.assertEquals(expected, solution1.deleteDuplicates(head)); |
| 26 | + } |
| 27 | + |
| 28 | + @Test |
| 29 | + public void test2() { |
| 30 | + head = LinkedListUtils.contructLinkedList(new int[] {1, 1, 1, 2, 3}); |
| 31 | + expected = LinkedListUtils.contructLinkedList(new int[] {2, 3}); |
| 32 | + Assert.assertEquals(expected, solution1.deleteDuplicates(head)); |
| 33 | + } |
58 | 34 | }
|
0 commit comments