forked from RyanCarrier/dijkstra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph_test.go
65 lines (57 loc) · 1.33 KB
/
graph_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
package dijkstra
import "testing"
func TestMapInitialised(t *testing.T) {
g := NewGraph()
g.GetMapping("test")
//if the program didn't crash then the map was initialised bahahah
}
func TestGetVertex(t *testing.T) {
g := NewGraph()
g.AddVertex(99)
if v, _ := g.GetVertex(99); v.ID != 99 {
t.Error("Getting vertex failed (99)")
}
if _, err := g.GetVertex(100); err == nil {
t.Error("Vertex should not be found (100)")
}
}
func TestAddVertex(t *testing.T) {
g := NewGraph()
g.AddVertex(99)
got, err := g.GetVertex(98)
if got.ID == 99 || err != nil {
t.Error("should not have had ID set and err should be nil")
}
for i := 0; i <= 10; i++ {
g.AddVertex(i)
}
v := g.AddNewVertex()
if v.ID != 11 {
t.Error("Adding self assigned vertex fail")
}
g = NewGraph()
for i := 0; i <= 10; i++ {
g.AddNewVertex()
}
if v = g.AddNewVertex(); v.ID != 11 {
t.Error("Adding self assigned vertex fail when extending slice")
}
}
func TestValidateCorrect(t *testing.T) {
if newGraph().validate() != nil {
t.Error(newGraph().validate().Error(), " should be nil")
}
}
func TestValidateIncorrect(t *testing.T) {
if newBadGraph().validate() == nil {
t.Error("graph should not have validated")
}
}
func newGraph() Graph {
return getBGraph()
}
func newBadGraph() Graph {
g := getBGraph()
g.Verticies[0].AddArc(9999, 1)
return g
}