-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathqueue_test.go
89 lines (77 loc) · 1.71 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
package threadsafe
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewQueue(t *testing.T) {
queue := NewQueue()
assert.Equal(t, 0, queue.Len())
}
func TestQueueEnqueue(t *testing.T) {
queue := NewQueue()
queue.Enqueue(42)
assert.Equal(t, 1, queue.Len())
value, ok := queue.Peek()
assert.True(t, ok)
assert.Equal(t, 42, value)
}
func TestQueueDequeue(t *testing.T) {
queue := NewQueue()
queue.Enqueue(42)
value, ok := queue.Dequeue()
assert.True(t, ok)
assert.Equal(t, 42, value)
assert.Equal(t, 0, queue.Len())
}
func TestQueueDequeueEmpty(t *testing.T) {
queue := NewQueue()
value, ok := queue.Dequeue()
assert.False(t, ok)
assert.Nil(t, value)
}
func TestQueuePeek(t *testing.T) {
queue := NewQueue()
queue.Enqueue(42)
value, ok := queue.Peek()
assert.True(t, ok)
assert.Equal(t, 42, value)
}
func TestQueuePeekEmpty(t *testing.T) {
queue := NewQueue()
value, ok := queue.Peek()
assert.False(t, ok)
assert.Nil(t, value)
}
func TestQueueLen(t *testing.T) {
queue := NewQueue()
queue.Enqueue(42)
queue.Enqueue(43)
assert.Equal(t, 2, queue.Len())
}
func TestQueueIsEmpty(t *testing.T) {
queue := NewQueue()
assert.True(t, queue.IsEmpty())
queue.Enqueue(42)
assert.False(t, queue.IsEmpty())
queue.Dequeue()
assert.True(t, queue.IsEmpty())
}
func TestQueueClear(t *testing.T) {
queue := NewQueue()
queue.Enqueue(42)
queue.Enqueue(43)
queue.Clear()
assert.Equal(t, 0, queue.Len())
assert.True(t, queue.IsEmpty())
}
func TestQueueValues(t *testing.T) {
queue := NewQueue()
queue.Enqueue(1)
queue.Enqueue(2)
queue.Enqueue(3)
values := queue.Values()
assert.Equal(t, 3, len(values))
assert.Equal(t, 1, values[0])
assert.Equal(t, 2, values[1])
assert.Equal(t, 3, values[2])
}