-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
vertex_test.go
106 lines (98 loc) · 3.02 KB
/
vertex_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
104
105
106
package graphman
import "fmt"
func ExampleVertex_simple() {
graph := New()
v := graph.AddVertex("A")
fmt.Println(v)
fmt.Println(v.ID())
// Output:
// A
// A
}
func ExampleVertex_withAttrs() {
graph := New()
v := graph.AddVertex("A", Attrs{
"ccc": "ddd",
"eee": []string{"fff", "ggg"},
"hhh": 42,
})
fmt.Println(v)
fmt.Println(v.ID())
// Output:
// A[[ccc:ddd,eee:[fff ggg],hhh:42]]
// A
}
func ExampleVertices() {
graph := New()
a := graph.AddVertex("A")
b := graph.AddVertex("B")
c := graph.AddVertex("C")
d := graph.AddVertex("D")
vertices := &Vertices{a, b, c, d}
fmt.Println(vertices)
// Output: {A,B,C,D}
}
func ExampleVertex_helpers() {
graph := New()
graph.AddVertex("bob")
graph.AddVertex("eve")
graph.AddVertex("joy")
graph.AddVertex("sam")
graph.AddVertex("han") // solo
graph.AddEdge("bob", "eve") // bob is the predecessor of eve
graph.AddEdge("bob", "bob") // bob is linked to itself
graph.AddEdge("eve", "joy") // eve is the predecessor of joy
graph.AddEdge("joy", "eve") // and also its successor
graph.AddEdge("sam", "bob") // sam is the predecessor of bob
for _, vertex := range graph.Vertices() {
fmt.Println(vertex.ID())
fmt.Println(" isolated: ", vertex.IsIsolated())
fmt.Println(" neighbors: ", vertex.Neighbors())
fmt.Println(" predecessor vertices: ", vertex.PredecessorVertices())
fmt.Println(" predecessor edges: ", vertex.PredecessorEdges())
fmt.Println(" successor vertices: ", vertex.SuccessorVertices())
fmt.Println(" successor edges: ", vertex.SuccessorEdges())
fmt.Println(" edges: ", vertex.Edges())
}
// Output:
// bob
// isolated: false
// neighbors: {bob,eve,sam}
// predecessor vertices: {bob,sam}
// predecessor edges: {(bob,bob),(sam,bob)}
// successor vertices: {bob,eve}
// successor edges: {(bob,eve),(bob,bob)}
// edges: {(bob,bob),(sam,bob),(bob,eve),(bob,bob)}
// eve
// isolated: false
// neighbors: {bob,joy}
// predecessor vertices: {bob,joy}
// predecessor edges: {(bob,eve),(joy,eve)}
// successor vertices: {joy}
// successor edges: {(eve,joy)}
// edges: {(bob,eve),(joy,eve),(eve,joy)}
// han
// isolated: true
// neighbors: {}
// predecessor vertices: {}
// predecessor edges: {}
// successor vertices: {}
// successor edges: {}
// edges: {}
// joy
// isolated: false
// neighbors: {eve}
// predecessor vertices: {eve}
// predecessor edges: {(eve,joy)}
// successor vertices: {eve}
// successor edges: {(joy,eve)}
// edges: {(eve,joy),(joy,eve)}
// sam
// isolated: false
// neighbors: {bob}
// predecessor vertices: {}
// predecessor edges: {}
// successor vertices: {bob}
// successor edges: {(sam,bob)}
// edges: {(sam,bob)}
}