-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerator_test.go
More file actions
58 lines (49 loc) · 1.18 KB
/
Copy pathgenerator_test.go
File metadata and controls
58 lines (49 loc) · 1.18 KB
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
package grafo
import "testing"
func TestGenerator(t *testing.T) {
V := 10
E := 90
maxWeight := 50
g := generateRandomEdges(V, E, maxWeight)
if g.Order() != V {
t.Errorf("got %d want %d vertices", g.Order(), V)
}
count := 0
for v := range g.Order() {
for _, wt := range g.EdgesFrom(v) {
count++
if wt < 0 || wt > maxWeight {
t.Errorf("invalid weight %d, max is %d", wt, maxWeight)
}
}
}
if count != E {
t.Errorf("got %d want %d edges", count, E)
}
}
func TestGeneratorRandom(t *testing.T) {
V := 50
E := 500
maxWeight := 50
g := generateRandom(V, E, maxWeight)
if g.Order() != V {
t.Errorf("got %d want %d vertices", g.Order(), V)
}
count := 0
for v := range g.Order() {
for _, wt := range g.EdgesFrom(v) {
count++
if wt < 0 || wt > maxWeight {
t.Errorf("invalid weight %d, max is %d", wt, maxWeight)
}
}
}
// The edges generation is probabilistic, so it will generate
// aproximatly E edges. Consider +-20% of error.
pErr := 0.2
smallest := int(float64(E) * (1 - pErr))
largest := int(float64(E) * (1 + pErr))
if count < smallest || count > largest {
t.Errorf("got %d want between [%d, %d] edges", count, smallest, largest)
}
}