-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue_test.go
74 lines (56 loc) · 1.38 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
package arrayqueue_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/zergon321/arrayqueue"
)
func TestQueueLength(t *testing.T) {
queue, err := arrayqueue.NewQueue(512)
assert.Nil(t, err)
for i := 0; i < 512; i++ {
queue.Enqueue(i)
}
assert.Equal(t, 512, queue.Length())
for i := 0; i < 512; i++ {
_, err := queue.Dequeue()
assert.Nil(t, err)
}
assert.Equal(t, 0, queue.Length())
}
func TestQueueFIFO(t *testing.T) {
queue, err := arrayqueue.NewQueue(512)
assert.Nil(t, err)
queue.Enqueue(0)
queue.Enqueue(1)
el, err := queue.Dequeue()
assert.Nil(t, err)
assert.Equal(t, 0, el)
el, err = queue.Dequeue()
assert.Nil(t, err)
assert.Equal(t, 1, el)
}
func TestQueueBufferSize(t *testing.T) {
queue, err := arrayqueue.NewQueue(512)
assert.Nil(t, err)
assert.Equal(t, 0, queue.Length())
assert.Equal(t, 512, queue.BufferSize())
err = queue.SetBufferSize(256)
assert.Nil(t, err)
assert.Equal(t, 0, queue.Length())
assert.Equal(t, 256, queue.BufferSize())
queue.Enqueue(2)
err = queue.SetBufferSize(128)
assert.Nil(t, err)
assert.Equal(t, 1, queue.Length())
assert.Equal(t, 128, queue.BufferSize())
}
func TestQueueClear(t *testing.T) {
queue, err := arrayqueue.NewQueue(512)
assert.Nil(t, err)
for i := 0; i < 512; i++ {
queue.Enqueue(i)
}
queue.Clear()
assert.Equal(t, 0, queue.Length())
assert.Equal(t, 512, queue.BufferSize())
}