-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patharithmetics_div_test.go
More file actions
102 lines (98 loc) · 2.02 KB
/
arithmetics_div_test.go
File metadata and controls
102 lines (98 loc) · 2.02 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package num
import (
"testing"
"gitee.com/quant1x/num/labs"
)
func TestDiv(t *testing.T) {
type args struct {
x any
y any
}
type testCase struct {
Name string
Args args
Want any
TestFunc func(v any) any
}
tests := []testCase{
{
Name: "int32",
Args: args{
x: []int32{-1, 1, -2, -3},
y: []int32{1, 1, 2.00, -3},
},
Want: []int32{-1, 1, -1, 1},
TestFunc: func(v any) any {
vs := v.(args)
return Div(vs.x.([]int32), vs.y.([]int32))
},
},
{
Name: "int32-align",
Args: args{
x: []int32{-1, 1, -2, -3, 1},
y: []int32{1, 1, 2.00, -3, 1, 5},
},
Want: []int32{-1, 1, -1, 1, 1},
TestFunc: func(v any) any {
vs := v.(args)
return Div(vs.x.([]int32), vs.y.([]int32))
},
},
{
Name: "float32",
Args: args{
x: []float32{-0.1, 1.0, -2.00, -3},
y: []float32{-0.1, 1.0, -2.00, -3},
},
Want: []float32{1, 1, 1, 1},
TestFunc: func(v any) any {
vs := v.(args)
return Div(vs.x.([]float32), vs.y.([]float32))
},
},
{
Name: "float64",
Args: args{
x: []float64{-0.1, 1.0, -2.00, -3},
y: []float64{-0.1, 1.0, -2.00, -3},
},
Want: []float64{1, 1, 1, 1},
TestFunc: func(v any) any {
vs := v.(args)
return Div(vs.x.([]float64), vs.y.([]float64))
},
},
{
Name: "float64-const-float64",
Args: args{
x: []float64{-0.1, 1.0, -2.00, -3},
y: float64(1),
},
Want: []float64{-0.1, 1.0, -2.00, -3},
TestFunc: func(v any) any {
vs := v.(args)
return Div(vs.x.([]float64), vs.y.(float64))
},
},
{
Name: "float64-add-float32",
Args: args{
x: []float64{-0.1, 1.0, -2.00, -3},
y: []float32{1.00},
},
Want: []float64{-0.1, Float64NaN(), Float64NaN(), Float64NaN()},
TestFunc: func(v any) any {
vs := v.(args)
return Div(vs.x.([]float64), vs.y)
},
},
}
for _, tt := range tests {
t.Run(tt.Name, func(t *testing.T) {
if got := tt.TestFunc(tt.Args); !labs.DeepEqual(got, tt.Want) {
t.Errorf("Div() = %v, want %v", got, tt.Want)
}
})
}
}