-
Notifications
You must be signed in to change notification settings - Fork 7
/
variance_test.go
38 lines (33 loc) · 762 Bytes
/
variance_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
package statistics
import (
"fmt"
"testing"
)
func ExampleVariance() {
X := []uint8{8, 3, 6, 2, 7, 1, 8, 3, 7, 4, 8}
variance := Variance(X...)
fmt.Printf("The variance of %v is %v.\n", X, variance)
// Output:
// The variance of [8 3 6 2 7 1 8 3 7 4 8] is 6.330578512396695.
}
func TestVariance(t *testing.T) {
cases := []testArrayCase{
{
name: "test 1",
input: []float64{8, 3, 6, 2, 7, 1, 8, 3, 7, 4, 8},
expected: "float64 6.3305785",
},
}
for _, c := range cases {
c := c
t.Run(c.name, func(t *testing.T) {
t.Parallel()
actual := Variance(c.input.([]float64)...)
r := fmt.Sprintf("%T %.7f", actual, actual)
if r != c.expected {
t.Logf("expected %v, got %v", c.expected, r)
t.FailNow()
}
})
}
}