forked from exercism/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDoublyLinkedListTest.java
More file actions
121 lines (91 loc) · 3.28 KB
/
DoublyLinkedListTest.java
File metadata and controls
121 lines (91 loc) · 3.28 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class DoublyLinkedListTest {
@Test
@DisplayName("pop gets element from the list")
public void popGetsElementFromTheList() {
DoublyLinkedList<Integer> list = new DoublyLinkedList<>();
list.push(7);
assertThat(list.pop()).isEqualTo(7);
}
@Disabled("Remove to run test")
@Test
@DisplayName("push/pop respectively add/remove at the end of the list")
public void pushAndPopRespectivelyAddsAndRemovesAtEndOfList() {
DoublyLinkedList<Integer> list = new DoublyLinkedList<>();
list.push(11);
list.push(13);
assertThat(list.pop()).isEqualTo(13);
assertThat(list.pop()).isEqualTo(11);
}
@Disabled("Remove to run test")
@Test
@DisplayName("shift gets an element from the list")
public void shiftGetsAnElementFromTheList() {
DoublyLinkedList<Integer> list = new DoublyLinkedList<>();
list.push(17);
assertThat(list.shift()).isEqualTo(17);
}
@Disabled("Remove to run test")
@Test
@DisplayName("shift gets first element from the list")
public void shiftGetsFirstElementFromTheList() {
DoublyLinkedList<Integer> list = new DoublyLinkedList<>();
list.push(23);
list.push(5);
assertThat(list.shift()).isEqualTo(23);
assertThat(list.shift()).isEqualTo(5);
}
@Disabled("Remove to run test")
@Test
@DisplayName("unshift adds element at start of the list")
public void unshiftAddsElementAtStartOfTheList() {
DoublyLinkedList<Integer> list = new DoublyLinkedList<>();
list.unshift(23);
list.unshift(5);
assertThat(list.shift()).isEqualTo(5);
assertThat(list.shift()).isEqualTo(23);
}
@Disabled("Remove to run test")
@Test
@DisplayName("pop push shift unshift can be used in any order")
public void popPushShiftUnshiftCanBeUsedInAnyOrder() {
DoublyLinkedList<String> list = new DoublyLinkedList<>();
list.push("one");
list.push("two");
assertThat(list.pop()).isEqualTo("two");
list.push("three");
assertThat(list.shift()).isEqualTo("one");
list.unshift("four");
list.push("five");
assertThat(list.shift()).isEqualTo("four");
assertThat(list.pop()).isEqualTo("five");
assertThat(list.shift()).isEqualTo("three");
}
@Disabled("Remove to run test")
@Test
@DisplayName("popping to empty doesn't break the list")
public void poppingToEmptyDoesNotBreakTheList() {
DoublyLinkedList<Integer> list = new DoublyLinkedList<>();
list.push(41);
list.push(59);
list.pop();
list.pop();
list.push(47);
assertThat(list.pop()).isEqualTo(47);
}
@Disabled("Remove to run test")
@Test
@DisplayName("shifting to empty doesn't break the list")
public void shiftingToEmptyDoesNotBreakTheList() {
DoublyLinkedList<Integer> list = new DoublyLinkedList<>();
list.push(41);
list.push(59);
list.shift();
list.shift();
list.push(47);
assertThat(list.shift()).isEqualTo(47);
}
}