forked from InsZVA/tap0901
-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue_test.go
38 lines (33 loc) · 832 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
package tap0901
import "testing"
var q *queue
func assert(v bool, t *testing.T, errStr string) {
if !v {
t.Error(errStr)
}
}
func Test_queue_push(t *testing.T) {
q = &queue{}
assert(q.push(1), t, "push failed!")
assert(q.push(2), t, "push failed!")
assert(q.push(3), t, "push failed!")
assert(q.push(4), t, "push failed!")
assert(q.push(5), t, "push failed!")
for i := 5; i < QUEUE_SIZE; i++ {
q.push(i+1)
}
assert(!q.push(1), t, "push failed, not full!")
}
func Test_queue_pop(t *testing.T) {
var i interface{}
q.pop(&i)
v, ok := i.(int)
assert(ok, t, "pop failed, type error")
assert(v == 1, t, "pop failed, number error")
q.pop(&i)
v, ok = i.(int)
assert(ok, t, "pop failed, type error")
assert(v == 2, t, "pop failed, number error")
q2 := queue{}
assert(!q2.pop(&i), t, "pop failed, not emtpy!")
}