|
1 | | -import org.junit.Before; |
2 | 1 | import org.junit.Ignore; |
3 | 2 | import org.junit.Test; |
4 | 3 |
|
5 | | -import static org.hamcrest.CoreMatchers.*; |
6 | | -import static org.junit.Assert.*; |
| 4 | +import static org.hamcrest.CoreMatchers.is; |
| 5 | +import static org.junit.Assert.assertThat; |
7 | 6 |
|
8 | 7 | public class DoublyLinkedListTest { |
9 | | - private DoublyLinkedList<Integer> subject; |
10 | | - |
11 | | - @Before |
12 | | - public void setUp() { |
13 | | - subject = new DoublyLinkedList<>(); |
14 | | - } |
15 | | - |
16 | 8 |
|
17 | 9 | @Test |
18 | 10 | public void testPushPop() { |
19 | | - subject.push(10); |
20 | | - subject.push(20); |
21 | | - assertThat(subject.pop(), is(20)); |
22 | | - assertThat(subject.pop(), is(10)); |
| 11 | + DoublyLinkedList<Integer> list = new DoublyLinkedList<>(); |
| 12 | + |
| 13 | + list.push(10); |
| 14 | + list.push(20); |
| 15 | + |
| 16 | + assertThat(list.pop(), is(20)); |
| 17 | + assertThat(list.pop(), is(10)); |
23 | 18 | } |
24 | 19 |
|
25 | 20 | @Ignore("Remove to run test") |
26 | 21 | @Test |
27 | 22 | public void testPushShift() { |
28 | | - subject.push(10); |
29 | | - subject.push(20); |
30 | | - assertThat(subject.shift(), is(10)); |
31 | | - assertThat(subject.shift(), is(20)); |
| 23 | + DoublyLinkedList<String> list = new DoublyLinkedList<>(); |
| 24 | + |
| 25 | + list.push("10"); |
| 26 | + list.push("20"); |
| 27 | + |
| 28 | + assertThat(list.shift(), is("10")); |
| 29 | + assertThat(list.shift(), is("20")); |
32 | 30 | } |
33 | 31 |
|
34 | 32 | @Ignore("Remove to run test") |
35 | 33 | @Test |
36 | 34 | public void testUnshiftShift() { |
37 | | - subject.unshift(10); |
38 | | - subject.unshift(20); |
39 | | - assertThat(subject.shift(), is(20)); |
40 | | - assertThat(subject.shift(), is(10)); |
| 35 | + DoublyLinkedList<Character> list = new DoublyLinkedList<>(); |
| 36 | + |
| 37 | + list.unshift('1'); |
| 38 | + list.unshift('2'); |
| 39 | + |
| 40 | + assertThat(list.shift(), is('2')); |
| 41 | + assertThat(list.shift(), is('1')); |
41 | 42 | } |
42 | 43 |
|
43 | 44 | @Ignore("Remove to run test") |
44 | 45 | @Test |
45 | 46 | public void testUnshiftPop() { |
46 | | - subject.unshift(10); |
47 | | - subject.unshift(20); |
48 | | - assertThat(subject.pop(), is(10)); |
49 | | - assertThat(subject.pop(), is(20)); |
| 47 | + DoublyLinkedList<Integer> list = new DoublyLinkedList<>(); |
| 48 | + |
| 49 | + list.unshift(10); |
| 50 | + list.unshift(20); |
| 51 | + |
| 52 | + assertThat(list.pop(), is(10)); |
| 53 | + assertThat(list.pop(), is(20)); |
50 | 54 | } |
51 | 55 |
|
52 | 56 | @Ignore("Remove to run test") |
53 | 57 | @Test |
54 | 58 | public void testExample() { |
55 | | - subject.push(10); |
56 | | - subject.push(20); |
57 | | - assertThat(subject.pop(), is(20)); |
58 | | - |
59 | | - subject.push(30); |
60 | | - assertThat(subject.shift(), is(10)); |
61 | | - |
62 | | - subject.unshift(40); |
63 | | - subject.push(50); |
64 | | - assertThat(subject.shift(), is(40)); |
65 | | - assertThat(subject.pop(), is(50)); |
66 | | - assertThat(subject.shift(), is(30)); |
| 59 | + DoublyLinkedList<String> list = new DoublyLinkedList<>(); |
| 60 | + |
| 61 | + list.push("ten"); |
| 62 | + list.push("twenty"); |
| 63 | + |
| 64 | + assertThat(list.pop(), is("twenty")); |
| 65 | + |
| 66 | + list.push("thirty"); |
| 67 | + |
| 68 | + assertThat(list.shift(), is("ten")); |
| 69 | + |
| 70 | + list.unshift("forty"); |
| 71 | + list.push("fifty"); |
| 72 | + |
| 73 | + assertThat(list.shift(), is("forty")); |
| 74 | + assertThat(list.pop(), is("fifty")); |
| 75 | + assertThat(list.shift(), is("thirty")); |
67 | 76 | } |
| 77 | + |
68 | 78 | } |
0 commit comments