-
Notifications
You must be signed in to change notification settings - Fork 2
/
queue_test.go
63 lines (55 loc) · 1.21 KB
/
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
53
54
55
56
57
58
59
60
61
62
63
package prefixmap
import (
"testing"
)
type queue_test struct {
w string
}
var queue_tests = []queue_test{
{"alessandro"},
{"typeflow"},
{"triego"},
}
func Test_queue(t *testing.T) {
for _, v := range queue_tests {
q := newQueue()
word := make([]byte, 0, len(v.w))
for i := 0; i < len(v.w); i++ {
t_ := newNode()
t_.key = string(append([]byte(t_.key), v.w[i]))
q.enqueue(t_)
}
for !q.isEmpty() {
t_ := q.dequeue()
word = append(word, t_.key[0])
}
if string(word) != v.w {
t.Errorf("Unexpected characters dequeued: got '%s', expected '%s'", string(word), v.w)
}
}
}
func Benchmark_queue_enqueue(b *testing.B) {
b.ReportAllocs()
q := newQueue()
t := newNode()
b.StopTimer()
b.ResetTimer()
b.StartTimer()
for i := 0; i < b.N; i++ {
q.enqueue(t)
}
}
func Benchmark_queue_dequeue(b *testing.B) {
b.ReportAllocs()
q := newQueue()
t := newNode()
b.StopTimer()
for i := 0; i < b.N; i++ {
q.enqueue(t)
}
b.ResetTimer()
b.StartTimer()
for i := 0; i < b.N; i++ {
q.dequeue()
}
}