forked from okx/xlayer-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue_test.go
52 lines (41 loc) · 1013 Bytes
/
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
package state
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestQueue(t *testing.T) {
q := NewQueue[int]()
q.Push(10)
q.Push(20)
q.Push(30)
top, err := q.Top()
require.NoError(t, err)
assert.Equal(t, 10, top)
assert.Equal(t, 3, q.Len())
assert.Equal(t, false, q.IsEmpty())
pop, err := q.Pop()
require.NoError(t, err)
assert.Equal(t, 10, pop)
assert.Equal(t, 2, q.Len())
assert.Equal(t, false, q.IsEmpty())
top, err = q.Top()
require.NoError(t, err)
assert.Equal(t, 20, top)
assert.Equal(t, 2, q.Len())
assert.Equal(t, false, q.IsEmpty())
pop, err = q.Pop()
require.NoError(t, err)
assert.Equal(t, 20, pop)
assert.Equal(t, 1, q.Len())
assert.Equal(t, false, q.IsEmpty())
pop, err = q.Pop()
require.NoError(t, err)
assert.Equal(t, 30, pop)
assert.Equal(t, 0, q.Len())
assert.Equal(t, true, q.IsEmpty())
_, err = q.Top()
require.Error(t, ErrQueueEmpty, err)
_, err = q.Pop()
require.Error(t, ErrQueueEmpty, err)
}