/
quickFind_test.go
63 lines (50 loc) · 1.09 KB
/
quickFind_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
package dyncon
import (
"bufio"
"os"
"strconv"
"testing"
)
type union func(int, int)
func TestQuickFind(t *testing.T) {
file, err := os.Open("tinyUF.txt")
if err != nil {
t.Errorf("Error opening File")
}
defer file.Close()
scanner := bufio.NewScanner(file)
scanner.Split(bufio.ScanWords)
scanner.Scan()
size, _ := strconv.Atoi(scanner.Text())
qf := initQuickFind(size)
for scanner.Scan() {
x, _ := strconv.Atoi(scanner.Text())
scanner.Scan()
y, _ := strconv.Atoi(scanner.Text())
qf.Union(x, y)
}
if conn := qf.Connected(6, 1); conn != true {
t.Errorf("Error")
}
}
func TestQuickUnion(t *testing.T) {
file, err := os.Open("tinyUF.txt")
if err != nil {
t.Errorf("Error opening File")
}
defer file.Close()
scanner := bufio.NewScanner(file)
scanner.Split(bufio.ScanWords)
scanner.Scan()
size, _ := strconv.Atoi(scanner.Text())
uf := initQuickUnionUF(size)
for scanner.Scan() {
x, _ := strconv.Atoi(scanner.Text())
scanner.Scan()
y, _ := strconv.Atoi(scanner.Text())
uf.union(x, y)
}
if conn := uf.connected(6, 1); conn != true {
t.Errorf("Error")
}
}