-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimeout_test.go
More file actions
78 lines (67 loc) · 1.27 KB
/
Copy pathtimeout_test.go
File metadata and controls
78 lines (67 loc) · 1.27 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package cow
import (
"reflect"
"testing"
)
func TestPrepend(t *testing.T) {
t1 := &timeout{
userData: []byte("test"),
}
t2 := &timeout{
userData: []byte("test2"),
}
t3 := &timeout{
userData: []byte("test3"),
}
tl := &timeoutList{}
tl.prepend(t1)
tl.prepend(t2)
tl.prepend(t3)
if !reflect.DeepEqual(tl.head, t3) {
t.Fatalf("expected linked list head to be %+v but got %+v", t3, tl.head)
}
cout, ok := isLinkedListValid(tl)
if !ok {
t.Fatal("got invalid linked list")
}
if cout != 3 {
t.Fatalf("incorrect linked list length! expected %d but got %d", 3, cout)
}
}
func TestRemove(t *testing.T) {
t1 := &timeout{
userData: []byte("test"),
}
t2 := &timeout{
userData: []byte("test2"),
}
t3 := &timeout{
userData: []byte("test3"),
}
tl := &timeoutList{}
tl.prepend(t1)
tl.prepend(t2)
tl.prepend(t3)
t2.remove()
cout, ok := isLinkedListValid(tl)
if !ok {
t.Fatal("got invalid linked list")
}
if cout != 2 {
t.Fatalf("incorrect linked list length! expected %d but got %d", 1, cout)
}
}
func isLinkedListValid(tl *timeoutList) (int, bool) {
counter := 0
ti := tl.head
for ti != nil {
if ti.next != nil {
if !reflect.DeepEqual(ti, ti.next.prev) {
return 0, false
}
}
ti = ti.next
counter++
}
return counter, true
}