-
Notifications
You must be signed in to change notification settings - Fork 0
/
Queue_test.go
98 lines (84 loc) · 1.65 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
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
package HyperUtility
import "testing"
func TestQueueImpl(t *testing.T) {
// Create new queue.
s := NewQueue()
// Check if the new queue is empty
if s.Size() != 0 {
t.Fail()
}
// Add int 1 into queue.
s.Push(1)
// Check if the queue has 1 element
if s.Size() != 1 {
t.Fail()
}
// Add int 2 into queue
s.Push(2)
// Check if the queue has 2 elements
if s.Size() != 2 {
t.Fail()
}
// Peek into the queue and check it content
if p, err := s.Peek(); err != nil {
t.Fail()
} else if p.(int) != 1 {
t.Fail()
}
// Check after peek, the size must not change
if s.Size() != 2 {
t.Fail()
}
// Pop form the queue and check it content
if p, err := s.Pop(); err != nil {
t.Fail()
} else if p.(int) != 1 {
t.Fail()
}
// Check after pop, the size must be decreased
if s.Size() != 1 {
t.Fail()
}
// Peek again the value after pop.
if p, err := s.Peek(); err != nil {
t.Fail()
} else if p.(int) != 2 {
t.Fail()
}
// Check after peek on the last content.
if s.Size() != 1 {
t.Fail()
}
// Pop again the last value
if p, err := s.Pop(); err != nil {
t.Fail()
} else if p.(int) != 2 {
t.Fail()
}
// Check again that the queue his empty
if s.Size() != 0 {
t.Fail()
}
// Test to peek on the empty queue should fail.
if _, err := s.Peek(); err == nil {
t.Fail()
}
// Test to pop on the empty queue should fail.
if _, err := s.Pop(); err == nil {
t.Fail()
}
// Push 3 values.
s.Push(1)
s.Push(2)
s.Push(3)
// Check the size of the queue after adding 3 values.
if s.Size() != 3 {
t.Fail()
}
// Clear the stack
s.Clear()
// Make sure that the queue is emptied after clear
if s.Size() != 0 {
t.Fail()
}
}