-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode_test.go
69 lines (53 loc) · 1.52 KB
/
node_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
package graphs_test
import (
"testing"
"github.com/yannickkirschen/graphs"
)
// The tested node is a railway point and looks like this:
//
// head ---------- main
// `------ diversion
//
// We're testing a point called "W1".
func MakeNode() *graphs.Node[string, string] {
node := graphs.NewNode[string, string]("W1")
node.ConnectBi("head", "main")
node.ConnectBi("head", "diversion")
return node
}
func TestId(t *testing.T) {
node := MakeNode()
if node.Id() != "W1" {
t.Fatalf("expected node ID to be 'W1', but got %v", node.Id())
}
}
func TestHead(t *testing.T) {
node := MakeNode()
nextPorts := node.Next("head")
if len(nextPorts) != 2 {
t.Fatalf("expected 2 ports, but got %d: %v", len(nextPorts), nextPorts)
}
if !(nextPorts[0] == "main" && nextPorts[1] == "diversion") && !(nextPorts[0] == "diversion" && nextPorts[1] == "main") {
t.Fatalf("expected next ports to be ['main', 'diversion'], but got %v", nextPorts)
}
}
func TestMain(t *testing.T) {
node := MakeNode()
nextPorts := node.Next("main")
if len(nextPorts) != 1 {
t.Fatalf("expected 1 ports, but got %d: %v", len(nextPorts), nextPorts)
}
if nextPorts[0] != "head" {
t.Fatalf("expected next ports to be ['head'], but got %v", nextPorts)
}
}
func TestDiversion(t *testing.T) {
node := MakeNode()
nextPorts := node.Next("diversion")
if len(nextPorts) != 1 {
t.Fatalf("expected 1 ports, but got %d: %v", len(nextPorts), nextPorts)
}
if nextPorts[0] != "head" {
t.Fatalf("expected next ports to be ['head'], but got %v", nextPorts)
}
}