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