...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package trace
16
17 import (
18 "reflect"
19 "testing"
20 )
21
22 func init() {
23 }
24
25 func TestAdd(t *testing.T) {
26 q := newEvictedQueue(3)
27 q.add("value1")
28 q.add("value2")
29 if wantLen, gotLen := 2, len(q.queue); wantLen != gotLen {
30 t.Errorf("got queue length %d want %d", gotLen, wantLen)
31 }
32 }
33
34 func (eq *evictedQueue) queueToArray() []string {
35 arr := make([]string, 0)
36 for _, value := range eq.queue {
37 arr = append(arr, value.(string))
38 }
39 return arr
40 }
41
42 func TestDropCount(t *testing.T) {
43 q := newEvictedQueue(3)
44 q.add("value1")
45 q.add("value2")
46 q.add("value3")
47 q.add("value1")
48 q.add("value4")
49 if wantLen, gotLen := 3, len(q.queue); wantLen != gotLen {
50 t.Errorf("got queue length %d want %d", gotLen, wantLen)
51 }
52 if wantDropCount, gotDropCount := 2, q.droppedCount; wantDropCount != gotDropCount {
53 t.Errorf("got drop count %d want %d", gotDropCount, wantDropCount)
54 }
55 wantArr := []string{"value3", "value1", "value4"}
56 gotArr := q.queueToArray()
57
58 if wantLen, gotLen := len(wantArr), len(gotArr); gotLen != wantLen {
59 t.Errorf("got array len %d want %d", gotLen, wantLen)
60 }
61
62 if !reflect.DeepEqual(gotArr, wantArr) {
63 t.Errorf("got array = %#v; want %#v", gotArr, wantArr)
64 }
65 }
66
View as plain text