-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathweak_test.go
79 lines (71 loc) · 1.57 KB
/
weak_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 (
"math/rand"
"testing"
)
func TestComponents(t *testing.T) {
g := New(0)
if mess, diff := diff(Components(g), [][]int{}); diff {
t.Errorf("Components %s", mess)
}
if mess, diff := diff(Connected(g), false); diff {
t.Errorf("Connected %s", mess)
}
g = New(1)
if mess, diff := diff(Components(g), [][]int{{0}}); diff {
t.Errorf("Components %s", mess)
}
if mess, diff := diff(Connected(g), true); diff {
t.Errorf("Connected %s", mess)
}
g.Add(0, 0)
if mess, diff := diff(Components(g), [][]int{{0}}); diff {
t.Errorf("Components %s", mess)
}
if mess, diff := diff(Connected(g), true); diff {
t.Errorf("Connected %s", mess)
}
g = New(4)
g.Add(0, 1)
g.Add(2, 1)
if mess, diff := diff(Components(g), [][]int{{0, 1, 2}, {3}}); diff {
t.Errorf("Components %s", mess)
}
if mess, diff := diff(Connected(g), false); diff {
t.Errorf("Connected %s", mess)
}
g.AddBoth(0, 1)
g.AddBoth(1, 2)
g.AddBoth(2, 3)
g.AddBoth(0, 3)
if mess, diff := diff(Components(g), [][]int{{0, 1, 2, 3}}); diff {
t.Errorf("Components %s", mess)
}
if mess, diff := diff(Connected(g), true); diff {
t.Errorf("Connected %s", mess)
}
}
func BenchmarkConnected(b *testing.B) {
n := 1000
b.StopTimer()
g := New(n)
for i := 0; i < n; i++ {
g.AddBoth(rand.Intn(n), rand.Intn(n))
}
b.StartTimer()
for i := 0; i < b.N; i++ {
_ = Connected(g)
}
}
func BenchmarkComponents(b *testing.B) {
n := 1000
b.StopTimer()
g := New(n)
for i := 0; i < n; i++ {
g.AddBoth(rand.Intn(n), rand.Intn(n))
}
b.StartTimer()
for i := 0; i < b.N; i++ {
_ = Components(g)
}
}