-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevel_test.go
103 lines (97 loc) · 2.29 KB
/
level_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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package mutex
import "testing"
func TestAddOrderToLevel(t *testing.T) {
l := &Level{}
o := &Order{}
l.AddOrder(o)
if l.FirstOrder.Order != o {
t.FailNow()
}
if l.LastOrder.Order != o {
t.FailNow()
}
o2 := &Order{}
l.AddOrder(o2)
if l.FirstOrder.Order != o {
t.FailNow()
}
if l.LastOrder.Order != o2 {
t.Error("Second order was not inserted at end of level")
}
if l.FirstOrder.NextOrder.Order != o2 {
t.Error("Link to second order not established")
}
if l.FirstOrder.NextOrder.PrevOrder.Order != o {
t.Error("Link back to first order not established")
}
}
func TestRemoveOnlyFromLevel(t *testing.T) {
l := &Level{}
o := &Order{}
l.AddOrder(o)
l.RemoveOrder(o)
if l.FirstOrder != nil {
t.Error("Did not remove first link")
}
if l.LastOrder != nil {
t.Error("Did not remove last link")
}
}
func TestRemoveLastFromLevel(t *testing.T) {
l := &Level{}
first_order := &Order{}
o := &Order{}
l.AddOrder(first_order)
l.AddOrder(o)
l.RemoveOrder(o)
if l.FirstOrder.Order != first_order {
t.Error("Did not keep first link to first order")
}
if l.LastOrder.Order != first_order {
t.Error("Did not change last link to first order")
}
if l.FirstOrder.NextOrder != nil {
t.Error("Did not clear link to second order")
}
}
func TestRemoveMiddleFromLevel(t *testing.T) {
l := &Level{}
first_order := &Order{}
middle_order := &Order{}
last_order := &Order{}
l.AddOrder(first_order)
l.AddOrder(middle_order)
l.AddOrder(last_order)
l.RemoveOrder(middle_order)
if l.FirstOrder.Order != first_order {
t.Error("First link should be untouched")
}
if l.LastOrder.Order != last_order {
t.Error("Last link should be untouched")
}
if l.FirstOrder.NextOrder.Order != last_order {
t.Error("Middle order should be removed going forward")
}
if l.LastOrder.PrevOrder.Order != first_order {
t.Error("Middle order should be removed going backwards")
}
}
func TestRemoveFirstFromLevel(t *testing.T) {
l := &Level{}
first_order := &Order{}
middle_order := &Order{}
last_order := &Order{}
l.AddOrder(first_order)
l.AddOrder(middle_order)
l.AddOrder(last_order)
l.RemoveOrder(first_order)
if l.FirstOrder.Order != middle_order {
t.Fail()
}
if l.FirstOrder.NextOrder.Order != last_order {
t.Fail()
}
if l.FirstOrder.NextOrder.PrevOrder.Order != middle_order {
t.Fail()
}
}