-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfifo_test.go
More file actions
41 lines (38 loc) · 921 Bytes
/
Copy pathfifo_test.go
File metadata and controls
41 lines (38 loc) · 921 Bytes
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
package lasr
import "testing"
func TestFifo(t *testing.T) {
f := newFifo(5)
for i := 0; i < 5; i++ {
if got, want := f.Len(), i; got != want {
t.Errorf("bad count: got %d, want %d", got, want)
}
f.Push(&Message{Body: []byte{byte(i)}})
if got, want := f.Len(), i+1; got != want {
t.Errorf("bad count: got %d, want %d", got, want)
}
}
for i := 0; i < 5; i++ {
if got, want := f.Len(), 5-i; got != want {
t.Errorf("bad count: got %d, want %d", got, want)
}
m := f.Pop()
if got, want := m.Body[0], byte(i); got != want {
t.Errorf("bad Pop: got %d, want %d", got, want)
}
if got, want := f.Len(), 5-i-1; got != want {
t.Errorf("bad count: got %d, want %d", got, want)
}
}
}
func TestFifoPanicOnFull(t *testing.T) {
f := newFifo(5)
for i := 0; i < 5; i++ {
f.Push(nil)
}
defer func() {
if r := recover(); r == nil {
t.Error("no panic detected")
}
}()
f.Push(nil)
}