- Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathdijkstra_test.go
34 lines (28 loc) · 848 Bytes
/
dijkstra_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
package dijkstra
import (
"fmt"
"github.com/xiaomeng79/go-algorithm/data-structures/graph"
"testing"
)
funcTestShortestPath(t*testing.T) {
h:=graph.NewUndirected()
fori:=0; i<5; i++ {
h.AddVertex(graph.VertexId(i))
}
h.AddEdge(graph.VertexId(0), graph.VertexId(1), 10)
h.AddEdge(graph.VertexId(1), graph.VertexId(2), 20)
h.AddEdge(graph.VertexId(2), graph.VertexId(3), 40)
h.AddEdge(graph.VertexId(0), graph.VertexId(2), 50)
h.AddEdge(graph.VertexId(0), graph.VertexId(3), 80)
h.AddEdge(graph.VertexId(0), graph.VertexId(4), 10)
h.AddEdge(graph.VertexId(4), graph.VertexId(3), 10)
prev:=ShortestPath(h, graph.VertexId(0))
fmt.Println(prev)
ifprev[1] !=graph.VertexId(0) ||
prev[2] !=graph.VertexId(1) ||
prev[3] !=graph.VertexId(4) ||
prev[4] !=graph.VertexId(0) {
fmt.Println(prev)
t.Error()
}
}