github.com/pavlo67/common@v0.5.3/common/mathlib/stddev_test.go (about) 1 package mathlib 2 3 import ( 4 "math" 5 "testing" 6 ) 7 8 func TestStdDev(t *testing.T) { 9 type data []float64 10 tests := []struct { 11 name string 12 args data 13 want float64 14 }{ 15 {name: "test empty list", args: data{}, want: 0}, 16 {name: "test 1-element list", args: data{1}, want: 0}, 17 {name: "test common list", args: data{1, 3, 5}, want: math.Sqrt(8. / 3.)}, 18 {name: "test sample data list", args: data{1.2219, 1.225, 1.2216, 1.2221, 1.2292}, want: 0.0028917814578560746}, 19 } 20 for _, tt := range tests { 21 t.Run(tt.name, func(t *testing.T) { 22 if got := StdDev(tt.args); got != tt.want { 23 t.Errorf("HullStdDev() = %v, wantDistance %v", got, tt.want) 24 } 25 }) 26 } 27 }