gitee.com/quant1x/num@v0.3.2/covariance_test.go (about) 1 package num 2 3 import "testing" 4 5 func TestCovariance(t *testing.T) { 6 type args struct { 7 x []float64 8 y []float64 9 } 10 tests := []struct { 11 name string 12 args args 13 want float64 14 }{ 15 { 16 name: "t-1", 17 args: args{ 18 x: []float64{1, 2, 3, 4, 5}, 19 y: []float64{2, 4, 6, 8, 10}, 20 }, 21 want: 4, 22 }, 23 } 24 for _, tt := range tests { 25 t.Run(tt.name, func(t *testing.T) { 26 if got := Covariance(tt.args.x, tt.args.y); got != tt.want { 27 t.Errorf("Covariance() = %v, want %v", got, tt.want) 28 } 29 }) 30 } 31 } 32 33 func TestVariance(t *testing.T) { 34 type args struct { 35 x []float64 36 } 37 tests := []struct { 38 name string 39 args args 40 want float64 41 }{ 42 { 43 name: "t-1", 44 args: args{ 45 x: []float64{1, 2, 3, 4, 5}, 46 }, 47 want: 2, 48 }, 49 } 50 for _, tt := range tests { 51 t.Run(tt.name, func(t *testing.T) { 52 if got := Variance(tt.args.x); got != tt.want { 53 t.Errorf("Variance() = %v, want %v", got, tt.want) 54 } 55 }) 56 } 57 }