-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
Copy pathedmondkarp_test.go
79 lines (76 loc) · 1.51 KB
/
edmondkarp_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
package graph
import (
"testing"
)
func TestEdmondKarp(t *testing.T) {
var edmondKarpTestData = []struct {
description string
graph WeightedGraph
source int
sink int
expected float64
}{
{
description: "test empty graph",
graph: nil,
source: 0,
sink: 0,
expected: 0.0,
},
{
description: "test graph with wrong dimensions",
graph: WeightedGraph{
{1, 2},
{0},
},
source: 0,
sink: 1,
expected: 0.0,
},
{
description: "test graph with no edges",
graph: WeightedGraph{
{0, 0},
{0, 0},
},
source: 0,
sink: 1,
expected: 0.0,
},
{
description: "test graph with 4 vertices",
graph: WeightedGraph{
{0, 1000000, 1000000, 0},
{0, 0, 1, 1000000},
{0, 0, 0, 1000000},
{0, 0, 0, 0},
},
source: 0,
sink: 3,
expected: 2000000,
},
{
description: "test graph with 6 vertices and some float64 weights",
graph: WeightedGraph{
{0, 16, 13.8, 0, 0, 0},
{0, 0, 10, 12.7, 0, 0},
{0, 4.2, 0, 0, 14, 0},
{0, 0, 9.1, 0, 0, 21.3},
{0, 0, 0, 7.5, 0, 4},
{0, 0, 0, 0, 0, 0},
},
source: 0,
sink: 5,
expected: 24.2,
},
}
for _, test := range edmondKarpTestData {
t.Run(test.description, func(t *testing.T) {
result := EdmondKarp(test.graph, test.source, test.sink)
if !almostEqual(test.expected, result) {
t.Logf("FAIL: %s", test.description)
t.Fatalf("Expected result:%f\nFound: %f", test.expected, result)
}
})
}
}