-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdist_test.go
48 lines (46 loc) · 980 Bytes
/
dist_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
package dist
import (
"io/ioutil"
"os"
"testing"
)
func checkMat(d *DistMat, file string, t *testing.T) {
res, err := ioutil.ReadFile(file)
if err != nil {
t.Errorf("can't open %q", file)
}
want := string(res)
get := d.String()
if get != want {
t.Errorf("get:\n%s\nwant:\n%s", get, want)
}
}
func TestDist(t *testing.T) {
fn := "data/dm.phy"
f, err := os.Open(fn)
if err != nil {
t.Errorf("can't open %q", fn)
}
defer f.Close()
sc := NewScanner(f)
sc.Scan()
dm := sc.DistanceMatrix()
checkMat(dm, "data/r1.txt", t)
dm.MakeSymmetrical()
checkMat(dm, "data/r2.txt", t)
dm.Delete(0)
checkMat(dm, "data/r3.txt", t)
data := []float64{0.1, 0.1, 0.1, 0.1}
dm.Append("new", data)
checkMat(dm, "data/r4.txt", t)
m, i, j := dm.Min()
if m != 0.0489 || i != 0 || j != 3 {
t.Errorf("can't find minimum")
}
dm.DeletePair(0, 4)
checkMat(dm, "data/r5.txt", t)
m, i, j = dm.Max()
if m != 0.186 || i != 0 || j != 2 {
t.Errorf("can't find maximum")
}
}