Debian Codegraph @

dstream/describe_test.go

raw symbols SCIP
1 package dstream
2
3 import (
4 "math"
5 "testing"
6 )
7
8 func describeData() Dstream {
9
10 x := [][]interface{}{
11 {
12 []float64{0, 0, 0},
13 []float64{1, 1, 1},
14 []float64{2, 2, 2},
15 },
16 {
17 []float64{1, 3, 5},
18 []float64{1, 3, 5},
19 []float64{1, 3, 5},
20 },
21 {
22 []float64{5, 5, 5},
23 []float64{5, math.NaN(), 5},
24 []float64{5, math.Inf(-1), math.Inf(1)},
25 },
26 }
27
28 na := []string{"x1", "x2", "x3"}
29 return NewFromArrays(x, na)
30 }
31
32 func compareStats(a, b Stats) bool {
33
34 if math.Abs(a.Mean-b.Mean) > 1e-6 {
35 return false
36 }
37
38 if math.Abs(a.Min-b.Min) > 1e-6 {
39 return false
40 }
41
42 if math.Abs(a.Max-b.Max) > 1e-6 {
43 return false
44 }
45
46 if math.Abs(a.SD-b.SD) > 1e-6 {
47 return false
48 }
49
50 return true
51 }
52
53 func TestDescribe1(t *testing.T) {
54
55 da := describeData()
56 st := Describe(da)
57
58 // Correct values
59 e := map[string]Stats{
60 "x1": Stats{
61 Min: 0,
62 Max: 2,
63 Mean: 1,
64 SD: math.Sqrt(6.0 / 9.0),
65 N: 9,
66 NaN: 0,
67 Inf: 0,
68 },
69 "x2": Stats{
70 Min: 1,
71 Max: 5,
72 Mean: 3,
73 SD: math.Sqrt(24.0 / 9.0),
74 N: 9,
75 NaN: 0,
76 Inf: 0,
77 },
78 "x3": Stats{
79 Min: 5,
80 Max: 5,
81 Mean: 5,
82 SD: 0,
83 N: 6,
84 Inf: 2,
85 NaN: 1,
86 },
87 }
88
89 for k, v := range e {
90 if !compareStats(v, st[k]) {
91 t.Fail()
92 }
93 }
94 }