-
-
Notifications
You must be signed in to change notification settings - Fork 168
/
describe_test.go
83 lines (69 loc) · 2.17 KB
/
describe_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
package stats_test
import (
"math"
"testing"
"github.com/montanaflynn/stats"
)
func TestDescribeValidDataset(t *testing.T) {
_, err := stats.Describe([]float64{1.0, 2.0, 3.0}, false, &[]float64{25.0, 50.0, 75.0})
if err != nil {
t.Errorf("Returned an error")
}
}
func TestDescribeEmptyDataset(t *testing.T) {
_, err := stats.Describe([]float64{}, false, nil)
if err != stats.ErrEmptyInput {
t.Errorf("Did not return empty input error")
}
}
func TestDescribeEmptyDatasetNaN(t *testing.T) {
describe, err := stats.Describe([]float64{}, true, nil)
if err != nil {
t.Errorf("Returned an error")
}
if !math.IsNaN(describe.Max) || !math.IsNaN(describe.Mean) || !math.IsNaN(describe.Min) || !math.IsNaN(describe.Std) {
t.Errorf("Was not NaN")
}
}
func TestDescribeValidDatasetNaN(t *testing.T) {
describe, err := stats.Describe([]float64{1.0, 2.0, 3.0}, true, &[]float64{25.0, 50.0, 75.0})
if err != nil {
t.Errorf("Returned an error")
}
if math.IsNaN(describe.Max) {
t.Errorf("Was NaN")
}
}
func TestDescribeValues(t *testing.T) {
dataSet := []float64{1.0, 2.0, 3.0}
percentiles := []float64{25.0, 50.0, 75.0}
describe, _ := stats.Describe(dataSet, true, &percentiles)
if describe.Count != len(dataSet) {
t.Errorf("Count was not == length of dataset")
}
if len(describe.DescriptionPercentiles) != len(percentiles) {
t.Errorf("Percentiles length was not == length of input percentiles")
}
max, _ := stats.Max(dataSet)
if max != describe.Max {
t.Errorf("Max was not equal to Max(dataset)")
}
min, _ := stats.Min(dataSet)
if min != describe.Min {
t.Errorf("Min was not equal to Min(dataset)")
}
mean, _ := stats.Mean(dataSet)
if mean != describe.Mean {
t.Errorf("Mean was not equal to Mean(dataset)")
}
std, _ := stats.StandardDeviation(dataSet)
if std != describe.Std {
t.Errorf("Std was not equal to StandardDeviation(dataset)")
}
}
func TestDescribeString(t *testing.T) {
describe, _ := stats.Describe([]float64{1.0, 2.0, 3.0}, true, &[]float64{25.0, 50.0, 75.0})
if describe.String(2) != "count\t3\nmean\t2.00\nstd\t0.82\nmax\t3.00\nmin\t1.00\n25.00%\tNaN\n50.00%\t1.50\n75.00%\t2.50\nNaN OK\ttrue" {
t.Errorf("String output is not correct")
}
}