-
Notifications
You must be signed in to change notification settings - Fork 3
/
element_test.go
55 lines (43 loc) · 1.14 KB
/
element_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
package triangolatte
import "testing"
func TestInsert(t *testing.T) {
t.Run("from scratch", func(t *testing.T) {
e := Insert(Point{1, 1}, nil)
if e.Next != e || e.Prev != e {
t.Error("Wrong creation of single element list")
}
})
t.Run("two element", func(t *testing.T) {
e1 := Insert(Point{1, 1}, nil)
e2 := Insert(Point{2, 2}, e1)
if e1.Next != e2 || e2.Next != e1 || e2.Prev != e1 {
t.Error("Wrong two element list")
}
})
}
func TestElement_Remove(t *testing.T) {
t.Run("removal", func(t *testing.T) {
e1 := Insert(Point{1, 1}, nil)
e2 := Insert(Point{2, 2}, e1)
e3 := Insert(Point{3, 3}, e2)
if e1.Next != e2 || e2.Next != e3 {
t.Error("Wrong insert")
}
e2.Remove()
if e1.Next != e3 || e3.Prev != e1 {
t.Error("Removal did not connect outer nodes")
}
if e2.Prev != e1 || e2.Next != e3 {
t.Error("Removal did not preserve connections")
}
})
t.Run("remove edge", func(t *testing.T) {
e1 := Insert(Point{1, 1}, nil)
e2 := Insert(Point{2, 2}, e1)
e3 := Insert(Point{3, 3}, e2)
e3.Remove()
if e2.Next != e1 || e1.Prev != e2 {
t.Error("Edge removal makes incorrect connection")
}
})
}