-
-
Notifications
You must be signed in to change notification settings - Fork 168
/
quartile_test.go
84 lines (69 loc) · 1.74 KB
/
quartile_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
package stats_test
import (
"testing"
"github.com/montanaflynn/stats"
)
func TestQuartile(t *testing.T) {
s1 := []float64{6, 7, 15, 36, 39, 40, 41, 42, 43, 47, 49}
s2 := []float64{7, 15, 36, 39, 40, 41}
for _, c := range []struct {
in []float64
Q1 float64
Q2 float64
Q3 float64
}{
{s1, 15, 40, 43},
{s2, 15, 37.5, 40},
} {
quartiles, err := stats.Quartile(c.in)
if err != nil {
t.Errorf("Should not have returned an error")
}
if quartiles.Q1 != c.Q1 {
t.Errorf("Q1 %v != %v", quartiles.Q1, c.Q1)
}
if quartiles.Q2 != c.Q2 {
t.Errorf("Q2 %v != %v", quartiles.Q2, c.Q2)
}
if quartiles.Q3 != c.Q3 {
t.Errorf("Q3 %v != %v", quartiles.Q3, c.Q3)
}
}
_, err := stats.Quartile([]float64{})
if err == nil {
t.Errorf("Empty slice should have returned an error")
}
}
func TestInterQuartileRange(t *testing.T) {
s1 := []float64{102, 104, 105, 107, 108, 109, 110, 112, 115, 116, 118}
iqr, _ := stats.InterQuartileRange(s1)
if iqr != 10 {
t.Errorf("IQR %v != 10", iqr)
}
_, err := stats.InterQuartileRange([]float64{})
if err == nil {
t.Errorf("Empty slice should have returned an error")
}
}
func TestMidhinge(t *testing.T) {
s1 := []float64{1, 3, 4, 4, 6, 6, 6, 6, 7, 7, 7, 8, 8, 9, 9, 10, 11, 12, 13}
mh, _ := stats.Midhinge(s1)
if mh != 7.5 {
t.Errorf("Midhinge %v != 7.5", mh)
}
_, err := stats.Midhinge([]float64{})
if err == nil {
t.Errorf("Empty slice should have returned an error")
}
}
func TestTrimean(t *testing.T) {
s1 := []float64{1, 3, 4, 4, 6, 6, 6, 6, 7, 7, 7, 8, 8, 9, 9, 10, 11, 12, 13}
tr, _ := stats.Trimean(s1)
if tr != 7.25 {
t.Errorf("Trimean %v != 7.25", tr)
}
_, err := stats.Trimean([]float64{})
if err == nil {
t.Errorf("Empty slice should have returned an error")
}
}