gitee.com/quant1x/num@v0.3.2/where_test.go (about) 1 package num 2 3 import ( 4 "gitee.com/quant1x/num/labs" 5 "math" 6 "testing" 7 ) 8 9 func TestWhere(t *testing.T) { 10 type args struct { 11 condition []float64 12 x []float64 13 y []float64 14 } 15 tests := []struct { 16 name string 17 args args 18 want []float64 19 }{ 20 { 21 name: "t01", 22 args: args{ 23 condition: []float64{1, 1, 1}, 24 x: []float64{0.1, 0.2, 0.3}, 25 y: []float64{1.1, 1.2, 1.3}, 26 }, 27 want: []float64{0.1, 0.2, 0.3}, 28 }, 29 { 30 name: "t02", 31 args: args{ 32 condition: []float64{1, 0}, 33 x: []float64{0.1, 0.2, 0.3}, 34 y: []float64{1.1, 1.2, 1.3}, 35 }, 36 want: []float64{0.1, 1.2, 0.3}, 37 }, 38 { 39 name: "t03", 40 args: args{ 41 condition: []float64{1, 0}, 42 x: []float64{0.1, 0.2}, 43 y: []float64{1.1, math.NaN(), 1.3}, 44 }, 45 want: []float64{0.1, math.NaN(), math.NaN()}, 46 }, 47 { 48 name: "t04", 49 args: args{ 50 condition: []float64{1, 0, 1, 1}, 51 x: []float64{0.1, 0.2}, 52 y: []float64{1.1, math.NaN(), 1.3}, 53 }, 54 want: []float64{0.1, math.NaN(), math.NaN(), math.NaN()}, 55 }, 56 { 57 name: "t05", 58 args: args{ 59 condition: []float64{1, 0, 1}, 60 x: []float64{0.1, 0.2, 0.3, 0.4}, 61 y: []float64{1.1, math.NaN(), 1.3}, 62 }, 63 want: []float64{0.1, math.NaN(), 0.3, 0.4}, 64 }, 65 } 66 for _, tt := range tests { 67 t.Run(tt.name, func(t *testing.T) { 68 if got := Where(tt.args.condition, tt.args.x, tt.args.y); !labs.SliceWantFloat(got, tt.want) { 69 t.Errorf("Where() = %v, want %v", got, tt.want) 70 } 71 }) 72 } 73 }