-
-
Notifications
You must be signed in to change notification settings - Fork 168
/
deviation_test.go
95 lines (84 loc) · 2.08 KB
/
deviation_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
package stats_test
import (
"math"
"testing"
"github.com/montanaflynn/stats"
)
func TestMedianAbsoluteDeviation(t *testing.T) {
_, err := stats.MedianAbsoluteDeviation([]float64{1, 2, 3})
if err != nil {
t.Errorf("Returned an error")
}
}
func TestMedianAbsoluteDeviationPopulation(t *testing.T) {
s, _ := stats.MedianAbsoluteDeviation([]float64{1, 2, 3})
m, err := stats.Round(s, 2)
if err != nil {
t.Errorf("Returned an error")
}
if m != 1.00 {
t.Errorf("%.10f != %.10f", m, 1.00)
}
s, _ = stats.MedianAbsoluteDeviation([]float64{-2, 0, 4, 5, 7})
m, err = stats.Round(s, 2)
if err != nil {
t.Errorf("Returned an error")
}
if m != 3.00 {
t.Errorf("%.10f != %.10f", m, 3.00)
}
m, _ = stats.MedianAbsoluteDeviation([]float64{})
if !math.IsNaN(m) {
t.Errorf("%.1f != %.1f", m, math.NaN())
}
}
func TestStandardDeviation(t *testing.T) {
_, err := stats.StandardDeviation([]float64{1, 2, 3})
if err != nil {
t.Errorf("Returned an error")
}
}
func TestStandardDeviationPopulation(t *testing.T) {
s, _ := stats.StandardDeviationPopulation([]float64{1, 2, 3})
m, err := stats.Round(s, 2)
if err != nil {
t.Errorf("Returned an error")
}
if m != 0.82 {
t.Errorf("%.10f != %.10f", m, 0.82)
}
s, _ = stats.StandardDeviationPopulation([]float64{-1, -2, -3.3})
m, err = stats.Round(s, 2)
if err != nil {
t.Errorf("Returned an error")
}
if m != 0.94 {
t.Errorf("%.10f != %.10f", m, 0.94)
}
m, _ = stats.StandardDeviationPopulation([]float64{})
if !math.IsNaN(m) {
t.Errorf("%.1f != %.1f", m, math.NaN())
}
}
func TestStandardDeviationSample(t *testing.T) {
s, _ := stats.StandardDeviationSample([]float64{1, 2, 3})
m, err := stats.Round(s, 2)
if err != nil {
t.Errorf("Returned an error")
}
if m != 1.0 {
t.Errorf("%.10f != %.10f", m, 1.0)
}
s, _ = stats.StandardDeviationSample([]float64{-1, -2, -3.3})
m, err = stats.Round(s, 2)
if err != nil {
t.Errorf("Returned an error")
}
if m != 1.15 {
t.Errorf("%.10f != %.10f", m, 1.15)
}
m, _ = stats.StandardDeviationSample([]float64{})
if !math.IsNaN(m) {
t.Errorf("%.1f != %.1f", m, math.NaN())
}
}