File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed
Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff 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+
917func 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
2935func 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+ }
You can’t perform that action at this time.
0 commit comments