-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue_test.go
More file actions
85 lines (68 loc) · 1.19 KB
/
queue_test.go
File metadata and controls
85 lines (68 loc) · 1.19 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
package queue
import (
"testing"
)
func TestNewQueue(t *testing.T) {
q := NewQueue()
if q == nil {
t.Error("New queue is nil")
}
}
func TestQueue(t *testing.T) {
q := NewQueue()
length := 4
slc := make([]interface{}, length)
slc[0] = "string"
slc[1] = 10
slc[2] = 0.1
slc[3] = struct{}{}
for i := 0; i < length; i++ {
q.Push(NewTask(slc[i]))
}
for i := 0; i < length; i++ {
tsk := q.Pop()
if tsk.Value() != slc[i] {
t.Error("Value does not match")
}
}
}
func TestQueue_Length(t *testing.T) {
q := NewQueue()
if q.Length() != 0 {
t.Error("Length does not match")
}
q.Push(NewTask(1))
if q.Length() != 1 {
t.Error("Length does not match")
}
q.Push(NewTask(2))
if q.Length() != 2 {
t.Error("Length does not match")
}
q.Pop()
if q.Length() != 1 {
t.Error("Length does not match")
}
q.Push(NewTask(3))
if q.Length() != 2 {
t.Error("Length does not match")
}
q.Push(NewTask(4))
q.Push(NewTask(5))
q.Push(NewTask(6))
if q.Length() != 5 {
t.Error("Length does not match")
}
q.Pop()
q.Pop()
q.Pop()
q.Pop()
q.Pop()
if q.Length() != 0 {
t.Error("Length does not match")
}
q.Pop()
if q.Length() != 0 {
t.Error("Length does not match")
}
}