-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevents_test.go
34 lines (31 loc) · 953 Bytes
/
events_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
package go_gb
import (
"testing"
)
func testQueue(t *testing.T, queue *eventQueue, expectedSize int, expectedHeadData, expectedTailData string) {
if queue.size != expectedSize {
t.Errorf("expected size %d, got %d", expectedSize, queue.size)
}
if queue.tail.data != expectedTailData {
t.Errorf("expected tail data to be \"%s\", got %s", expectedTailData, queue.tail.data)
}
if queue.head.data != expectedHeadData {
t.Errorf("expected head data to be \"%s\", got %s", expectedHeadData, queue.head.data)
}
}
func Test_eventQueue_Add(t *testing.T) {
queue := NewEventQueue(3)
queue.Add("1")
if queue.head == nil || queue.head != queue.tail {
t.Error("expected head and tail to be the same event")
}
testQueue(t, queue, 1, "1", "1")
queue.Add("2")
testQueue(t, queue, 2, "1", "2")
queue.Add("3")
testQueue(t, queue, 3, "1", "3")
queue.Add("4")
testQueue(t, queue, 3, "2", "4")
queue.Add("5")
testQueue(t, queue, 3, "3", "5")
}