File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed
Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -12,8 +12,8 @@ type Dsu struct {
1212// The element values are not stored explicitly in the data structure,
1313// and the user of the data structure is responsible for maintaining
1414// a correspondence between the element values and their indices.
15- func NewDsu (n uint ) * Dsu {
16- dsu := & Dsu {
15+ func NewDsu (n uint ) Dsu {
16+ dsu := Dsu {
1717 parent : make ([]uint , n ),
1818 size : make ([]uint , n ),
1919 }
Original file line number Diff line number Diff line change @@ -16,3 +16,21 @@ func TestSimpleUnion(t *testing.T) {
1616 t .Error ("2 should not be in the same set as 0 and 1" )
1717 }
1818}
19+
20+ func TestDoubleUnion (t * testing.T ) {
21+ d := dsu .NewDsu (3 )
22+ d .Union (0 , 1 )
23+ 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+ }
27+ }
28+
29+ func TestUnionOfSameSet (t * testing.T ) {
30+ d := dsu .NewDsu (2 )
31+ d .Union (0 , 1 )
32+ d .Union (0 , 1 )
33+ if d .Find (0 ) != d .Find (1 ) {
34+ t .Error ("0 and 1 should be in the same set" )
35+ }
36+ }
You can’t perform that action at this time.
0 commit comments