Skip to content

Commit 1ea18a6

Browse files
committed
100% coverage
1 parent 9aaebc2 commit 1ea18a6

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

dsu_test.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ import (
66
"alon.kr/x/dsu"
77
)
88

9+
func assertAllSame(t *testing.T, values ...uint) {
10+
for i := 1; i < len(values); i++ {
11+
if values[i] != values[0] {
12+
t.Error("All values should be the same")
13+
}
14+
}
15+
}
16+
917
func TestSimpleUnion(t *testing.T) {
1018
d := dsu.NewDsu(3)
1119
d.Union(0, 1)
@@ -21,9 +29,7 @@ func TestDoubleUnion(t *testing.T) {
2129
d := dsu.NewDsu(3)
2230
d.Union(0, 1)
2331
d.Union(1, 2)
24-
if d.Find(0) != d.Find(1) || d.Find(1) != d.Find(2) || d.Find(0) != d.Find(2) {
25-
t.Error("0, 1, and 2 should be in the same set")
26-
}
32+
assertAllSame(t, d.Find(0), d.Find(1), d.Find(2))
2733
}
2834

2935
func TestUnionOfSameSet(t *testing.T) {
@@ -34,3 +40,10 @@ func TestUnionOfSameSet(t *testing.T) {
3440
t.Error("0 and 1 should be in the same set")
3541
}
3642
}
43+
44+
func TestReverseOrderUnion(t *testing.T) {
45+
d := dsu.NewDsu(3)
46+
d.Union(1, 2)
47+
d.Union(0, 1)
48+
assertAllSame(t, d.Find(0), d.Find(1), d.Find(2))
49+
}

0 commit comments

Comments
 (0)