-
Notifications
You must be signed in to change notification settings - Fork 7
/
central_moment_test.go
50 lines (45 loc) · 997 Bytes
/
central_moment_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
package statistics
import (
"fmt"
"testing"
)
func ExampleCentralMoment() {
X := []uint8{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
moment := CentralMoment(X, 2)
fmt.Printf("The 2nd central moment of %v is %.2f.\n", X, moment)
// Output:
// The 2nd central moment of [1 2 3 4 5 6 7 8 9 10] is 8.25.
}
func TestCentralMoment(t *testing.T) {
cases := []struct {
name string
power int
input []float64
expected string
}{
{
name: "test 1",
power: 2,
input: []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
expected: "float64 8.25000",
},
{
name: "test 2",
power: 4,
input: []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
expected: "float64 120.86250",
},
}
for _, c := range cases {
c := c
t.Run(c.name, func(t *testing.T) {
t.Parallel()
actual := CentralMoment(c.input, c.power)
r := fmt.Sprintf("%T %.5f", actual, actual)
if r != c.expected {
t.Logf("expected %v, got %v", c.expected, r)
t.FailNow()
}
})
}
}