-
Notifications
You must be signed in to change notification settings - Fork 2
/
tree_test.go
42 lines (38 loc) · 900 Bytes
/
tree_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
package ufset
import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"
)
func print(sets *DisjointSets[int]) {
setsList := make([]int, 5)
for i := 0; i < 5; i++ {
setsList[i] = sets.Find(i)
}
fmt.Println(setsList)
}
func Test1(t *testing.T) {
sets := New[int]()
sets.add(0)
sets.add(1)
sets.add(2)
sets.Union(0, 1)
sets.Union(2, 1)
sets.Union(0, 0)
sets.Union(3, 4)
sets.Union(5, 3)
sets.Union(5, 5)
print(sets)
assert.Equal(t, sets.Find(0), sets.Find(1))
assert.Equal(t, sets.Find(0), sets.Find(2))
assert.Equal(t, sets.Find(3), sets.Find(4))
assert.Equal(t, sets.Find(3), sets.Find(5))
assert.True(t, sets.InSameSet(0, 1))
assert.True(t, sets.InSameSet(3, 5))
assert.NotEqual(t, sets.Find(0), sets.Find(3))
assert.False(t, sets.InSameSet(0, 3))
sets.Union(3, 0)
print(sets)
assert.Equal(t, sets.Find(0), sets.Find(3))
assert.True(t, sets.InSameSet(0, 3))
}