-
Notifications
You must be signed in to change notification settings - Fork 2
/
deque_test.go2
64 lines (52 loc) · 1.28 KB
/
deque_test.go2
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
64
package main
// vim:set ft=go:
import (
"testing"
)
func TestDeque(t *testing.T) {
q := NewDeque[int]()
for sz := 2; sz < 256; sz++ {
for i := 0; i < sz; i++ {
q.PushBack(i)
if got := q.Len(); got != i+1 {
t.Errorf("Len() returns wrong value: want=%d got=%d\n", i+1, got)
}
}
i := 0
for it := q.Begin(); it != q.End(); it = it.Next() {
if v := it.Get(); i != v {
t.Errorf("All() returns wrong seques of values: want[%d]=%d got[%d]=%d\n", i, i, i, v)
}
i++
}
for i := 0; i < sz; i++ {
got := q.PopFront()
if i != got {
t.Errorf("PopFront returns wrong value: want=%d got=%d\n", i, got)
}
if got := q.Len(); got != sz-i-1 {
t.Errorf("Len() returns wrong value: want=%d got=%d\n", sz-i-1, got)
}
}
}
q = NewDeque[int]()
// PushBack -> PopBack
for sz := 2; sz < 256; sz++ {
for i := 0; i < sz; i++ {
q.PushBack(i)
if got := q.Len(); got != i+1 {
t.Errorf("Len() returns wrong value: want=%d got=%d\n", sz, got)
}
}
for i := 0; i < sz; i++ {
want := sz - i - 1
got := q.PopBack()
if want != got {
t.Errorf("PopFront returns wrong value: want=%d got=%d\n", want, got)
}
if got := q.Len(); got != sz-i-1 {
t.Errorf("Len() returns wrong value: want=%d got=%d\n", sz-i-1, got)
}
}
}
}