-
Notifications
You must be signed in to change notification settings - Fork 87
/
DequeTest.kt
80 lines (78 loc) · 2.35 KB
/
DequeTest.kt
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
package deque
import org.jetbrains.spek.api.Spek
import org.junit.Assert.*
/**
* Spek BDD Test for Deque Class
*/
class DequeSpecs: Spek(spekBody = {
given("Given an Empty Queue") {
val deque: Deque<Int> = Deque()
on("Peeking first value") {
val value = deque.getFirst()
it("should result in null value") {
assertNull(value)
}
}
on("Peeking last value"){
val value = deque.getLast()
it("should result in a null value"){
assertNull(value)
}
}
}
given("Given a Queue with 1 value") {
val deque: Deque<Int> = Deque()
deque.addFirst(1)
on("Fetching first value") {
val value = deque.getFirst()
it("1. should not result in null value") {
assertNotNull(value)
assertEquals(1, value)
}
it("2. should have removed the final value"){
assertNull(deque.peekFirst())
}
}
}
given("Given a Queue with 1 value") {
val deque: Deque<Int> = Deque()
deque.addFirst(1)
on("Fetching last value") {
val value = deque.getLast()
it("1. should not result in null value") {
assertNotNull(value)
assertEquals(1, value)
}
it("2. should have removed the final value"){
assertNull(deque.peekFirst())
}
}
}
given("Given a Queue with 2 values") {
val deque: Deque<Int> = Deque()
deque.addFirst(2)
deque.addFirst(1)
on("Fetching first value") {
val value = deque.peekFirst()
it("should not result in null value") {
assertNotNull(value)
assertEquals(1, value)
}
}
on("Fetching last value") {
val value = deque.peekLast()
it("should not result in null value") {
assertNotNull(value)
assertEquals(2, value)
}
}
on("Removing last value") {
deque.removeLast()
it("There should be 1 value left on the queue") {
val value = deque.peekFirst()
assertNotNull(value)
assertEquals(1, value)
}
}
}
})