-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgraph_test.go
More file actions
96 lines (79 loc) · 1.71 KB
/
Copy pathgraph_test.go
File metadata and controls
96 lines (79 loc) · 1.71 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package grapho
import (
"testing"
)
func EqualsIntSlice(x, y []uint64) bool {
if len(x) != len(y) {
return false
}
for i, v := range x {
if v != y[i] {
return false
}
}
return true
}
func TestGraphAddNode(t *testing.T) {
g := NewGraph(false)
g.AddNode(1, nil)
attr := NewAttr()
attr["x"] = 25
g.AddNode(2, attr)
if len(g.Nodes()) != 2 {
t.Errorf("Expected size %d, got %d", 2, len(g.Nodes()))
}
attr, _ = g.Node(2)
x, ok := attr["x"]
if !ok || x.(int) != 25 {
t.Errorf("Expected value: 25. Got %v", x)
}
// Update node
attr = NewAttr()
attr["name"] = "Dylan"
g.AddNode(1, attr)
attr, _ = g.Node(1)
name, ok := attr["name"]
if !ok || name.(string) != "Dylan" {
t.Errorf("Expected value: 'Dylan'. Got %v", name)
}
}
func TestGraphDeleteNode(t *testing.T) {
g := NewGraph(false)
g.AddNode(1, nil)
g.AddNode(2, nil)
g.AddEdge(2, 1, 1, nil)
g.DeleteNode(1)
if len(g.Nodes()) != 1 {
t.Errorf("Node was not successfully deleted")
}
}
func TestGraphAddEdge(t *testing.T) {
g := NewGraph(false)
attr := NewAttr()
attr["x"] = 5
g.AddEdge(2, 1, 1, attr)
nodes, ok := g.Neighbors(1)
if !ok || !EqualsIntSlice(nodes, []uint64{2}) {
t.Errorf("Edge was not successfully added")
}
nodes, ok = g.Neighbors(2)
if !ok || !EqualsIntSlice(nodes, []uint64{1}) {
t.Errorf("Edge was not successfully added")
}
edge, ok := g.Edge(1, 2)
if !ok {
t.Errorf("Edge was not successfully added")
}
x, ok := edge.Attr["x"]
if !ok || x.(int) != 5 {
t.Errorf("Expected value: 5. Got %v", x)
}
}
func TestGraphDeleteEdge(t *testing.T) {
g := NewGraph(false)
g.AddEdge(2, 1, 1, NewAttr())
g.DeleteEdge(1, 2)
if _, ok := g.Edge(2, 1); ok {
t.Errorf("Edge was not successfully deleted")
}
}