-
Notifications
You must be signed in to change notification settings - Fork 0
/
landscape_test.go
109 lines (100 loc) · 2.02 KB
/
landscape_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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package tda
import (
"fmt"
"math"
"testing"
"gonum.org/v1/gonum/floats"
)
var (
ltests = []struct {
birth []float64
death []float64
pts []float64
depth []int
kmax [][]float64
stats []Stat
}{
{
birth: []float64{3, 4, 5},
death: []float64{9, 8, 7},
pts: []float64{6, 7, 8},
depth: []int{0, 1, 2},
kmax: [][]float64{
{3, 2, 1},
{2, 1, 0},
{1, 0, 0},
},
stats: []Stat{
{
Depth: 0,
Area: 8.999082,
Perimeter: 8.460178,
},
{
Depth: 1,
Area: 4,
Perimeter: 7.620954,
},
{
Depth: 2,
Area: 0.999082,
Perimeter: 6.803323,
},
},
},
{
birth: []float64{1, 4, 4, 7},
death: []float64{2, 7, 9, 9},
pts: []float64{3, 5, 8},
depth: []int{0, 1, 2},
kmax: [][]float64{
{0, 0, 0},
{1, 1, 0},
{1, 1, 0},
},
stats: []Stat{
{
Depth: 0,
Area: 6.499745,
Perimeter: 10.449612,
},
{
Depth: 1,
Area: 3.248646,
Perimeter: 9.985452,
},
{
Depth: 2,
Area: 0,
Perimeter: 8,
},
},
},
}
)
func TestLandscape(t *testing.T) {
for jt, tst := range ltests {
ls := NewLandscape(tst.birth, tst.death)
for j, kx := range tst.pts {
kf := ls.Eval(kx, tst.depth)
if !floats.EqualApprox(kf, tst.kmax[j], 1e-8) {
fmt.Printf("Landscape test %d failed on point %d\n", jt, j)
fmt.Printf("Got: %v\nExpected: %v\n", kf, tst.kmax[j])
t.Fail()
}
}
stats := ls.Stats(tst.depth, 100)
for j := range stats {
if math.Abs(stats[j].Area-tst.stats[j].Area) > 1e-5 {
fmt.Printf("Landscale area disagrees for test %d, point %d\n", jt, j)
fmt.Printf("Expected %f, got %f\n", tst.stats[j].Area, stats[j].Area)
t.Fail()
}
if math.Abs(stats[j].Perimeter-tst.stats[j].Perimeter) > 1e-5 {
fmt.Printf("Landscale perimeter disagrees for test %d, point %d\n", jt, j)
fmt.Printf("Expected %f, got %f\n", tst.stats[j].Perimeter, stats[j].Perimeter)
t.Fail()
}
}
}
}