-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutility_test.go
More file actions
56 lines (50 loc) · 1.76 KB
/
utility_test.go
File metadata and controls
56 lines (50 loc) · 1.76 KB
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
package gosom
import (
"testing"
)
func TestUnitDistances(t *testing.T) {
grid, _ := NewGrid(2, 3, Rectangular, nil, false)
ris := unitDistances(grid)
expected := [][]float64{
[]float64{0, 1, 1, 1, 2, 2},
[]float64{1, 0, 1, 1, 2, 2},
[]float64{1, 1, 0, 1, 1, 1},
[]float64{1, 1, 1, 0, 1, 1},
[]float64{2, 2, 1, 1, 0, 1},
[]float64{2, 2, 1, 1, 1, 0},
}
for i := 0; i < len(expected); i++ {
for y := 0; y < len(expected[i]); y++ {
if ris[i][y] != expected[i][y] {
t.Fatalf("Error: element in position %d-%d should be %v but is %v (%+v)", i, y, expected[i][y], ris[i][y], ris)
}
}
}
}
func TestUnitDistancesHexagonal(t *testing.T) {
grid, _ := NewGrid(2, 3, Hexagonal, nil, false)
ris := unitDistances(grid)
expected := [][]float64{
[]float64{0, 1, 0.9999999999999999, 0.9999999999999999, 1.7320508075688774, 2},
[]float64{1, 0, 1.7320508075688772, 0.9999999999999999, 2, 1.7320508075688774},
[]float64{0.9999999999999999, 1.7320508075688772, 0, 1, 1.0000000000000002, 1.7320508075688774},
[]float64{0.9999999999999999, 0.9999999999999999, 1, 0, 1.0000000000000002, 1.0000000000000002},
[]float64{1.7320508075688774, 2, 1.0000000000000002, 1.0000000000000002, 0, 1},
[]float64{2, 1.7320508075688774, 1.7320508075688774, 1.0000000000000002, 1, 0},
}
for i := 0; i < len(expected); i++ {
for y := 0; y < len(expected[i]); y++ {
if ris[i][y] != expected[i][y] {
t.Fatalf("Error: element in position %d-%d should be %v but is %v (%+v)", i, y, expected[i][y], ris[i][y], ris)
}
}
}
}
func TestQuantile(t *testing.T) {
grid, _ := NewGrid(2, 3, Hexagonal, nil, false)
ris := unitDistances(grid)
p := calculateQuantile(ris, 2.0/3.0)
if p != 1.2440169358562918 {
t.Fatalf("Error: expected %v but having %v", 1.2440169358562918, p)
}
}