-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshort_pather_test.go
61 lines (54 loc) · 1.29 KB
/
short_pather_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
package problem2642
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
type TestCase struct {
Commands []string
N int
Edges [][]int
Values [][]int
Expected []int
}
var TestCases = []TestCase{
{
Commands: []string{"Graph", "shortestPath", "shortestPath", "addEdge", "shortestPath"},
N: 4,
Edges: [][]int{{0, 2, 5}, {0, 1, 2}, {1, 2, 1}, {3, 0, 3}},
Values: [][]int{{}, {3, 2}, {0, 3}, {1, 3, 4}, {0, 3}},
Expected: []int{0, 6, -1, 0, 6},
},
}
func TestShortPathGraph(t *testing.T) {
assert := assert.New(t)
for _, tc := range TestCases {
var want = tc.Expected
var got = make([]int, len(want))
var graph = Constructor(tc.N, tc.Edges)
for i, cmd := range tc.Commands {
switch cmd {
case "shortestPath":
got[i] = graph.ShortestPath(tc.Values[i][0], tc.Values[i][1])
case "addEdge":
graph.AddEdge(tc.Values[i])
}
}
assert.Equal(want, got, fmt.Sprintf("%+v", tc))
}
}
func BenchmarkShortPathGraph(b *testing.B) {
for i := 0; i < b.N; i++ {
for _, tc := range TestCases {
var graph = Constructor(tc.N, tc.Edges)
for i, cmd := range tc.Commands {
switch cmd {
case "shortestPath":
graph.ShortestPath(tc.Values[i][0], tc.Values[i][1])
case "addEdge":
graph.AddEdge(tc.Values[i])
}
}
}
}
}