-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue_test.go
79 lines (70 loc) · 1.27 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
package queuearr
import "testing"
func TestEmpty(t *testing.T) {
q := NewQueue[int](10)
if !q.Empty() {
t.Errorf("wanted emtpy queue, got %v", q)
}
}
func TestFull(t *testing.T) {
q := NewQueue[int](5)
q.Enqueue(1)
q.Enqueue(2)
q.Enqueue(3)
q.Enqueue(4)
q.Enqueue(5)
if !q.Full() {
t.Errorf("wanted full, got empty")
}
q.Dequeue()
q.Enqueue(5)
q.Enqueue(1)
q.Enqueue(2)
q.Enqueue(3)
q.Enqueue(4)
if !q.Full() {
t.Errorf("wanted full, got empty")
}
}
func TestReset(t *testing.T) {
q := NewQueue[int](5)
q.Enqueue(1)
q.Enqueue(2)
q.Enqueue(3)
q.Reset()
if !q.Empty() {
t.Errorf("wanted emtpy queue, got %v", q)
}
}
func TestDequeueEmptyQueue(t *testing.T) {
q := NewQueue[int](10)
_, err := q.Dequeue()
if err == nil {
t.Errorf("wanted error cannot dequeue an empty queue, got %v", err)
}
}
func TestEnqueue(t *testing.T) {
q := NewQueue[int](10)
q.Enqueue(1)
q.Enqueue(2)
q.Enqueue(3)
if q.tail != 3 {
t.Errorf("wanted tail = 3, got %d", q.tail)
}
for i := 1; i < 11; i++ {
q.Enqueue(i)
}
if q.tail != 3 {
t.Errorf("wanted tail = 3, got %d", q.tail)
}
}
func TestDequeue(t *testing.T) {
q := NewQueue[int](10)
for i := 1; i < 11; i++ {
q.Enqueue(i)
}
_1, _ := q.Dequeue()
if _1 != 1 {
t.Errorf("wanted 1, got %d", _1)
}
}