-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue_test.go
71 lines (52 loc) · 1.32 KB
/
queue_test.go
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
package main
import (
"testing"
)
func TestQueuePushShift(t *testing.T) {
q := NewQueue()
s1 := "test"
q.Push(s1)
if len(q.queue) != 1 {
t.Errorf("Queue length is incorrect after push %d instead of 1", len(q.queue))
}
if q.queue[0] != s1 {
t.Errorf("Value in queue isn't correct %s instead of %s", q.queue[0], s1)
}
s2 := "test2"
q.Push(s2)
if len(q.queue) != 2 {
t.Errorf("Queue length is incorrect after push %d instead of 2", len(q.queue))
}
if q.queue[1] != s2 {
t.Errorf("Value in queue isn't correct %s instead of %s", q.queue[1], s2)
}
res := q.Shift()
if len(q.queue) != 1 {
t.Errorf("Queue length is incorrect after push %d instead of 1", len(q.queue))
}
if res != s1 {
t.Error("Element that was dequeued doesn't have the right value. %s instead of %s", res, s1)
}
res = q.Shift()
if len(q.queue) != 0 {
t.Errorf("Queue length is incorrect after push %d instead of 0", len(q.queue))
}
if res != s2 {
t.Error("Element that was dequeued doesn't have the right value. %s instead of %s", res, s2)
}
}
func TestQueueEmpty(t *testing.T) {
q := NewQueue()
for i := 0; i < 5; i++ {
q.Push("")
}
if q.IsEmpty() {
t.Error("Queue reports as empty when its not")
}
for i := 0; i < 5; i++ {
q.Shift()
}
if !q.IsEmpty() {
t.Error("Queue doesn't report as empty when it is")
}
}