-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patharithmetics_add_test.go
More file actions
125 lines (118 loc) · 2.51 KB
/
Copy patharithmetics_add_test.go
File metadata and controls
125 lines (118 loc) · 2.51 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package num
import (
"slices"
"testing"
"github.com/quant1x/num/labs"
)
func TestAdd(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{0, 1, 2.00, -3},
},
Want: []int32{-1, 2, 0, -6},
TestFunc: func(v any) any {
vs := v.(args)
return Add(vs.x.([]int32), vs.y.([]int32))
},
},
{
Name: "int32-align",
Args: args{
x: []int32{-1, 1, -2, -3, 1, 5},
y: []int32{0, 1, 2.00, -3, 1},
},
Want: []int32{-1, 2, 0, -6, 2, 5},
TestFunc: func(v any) any {
vs := v.(args)
return Add(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{-0.2, 2.0, -4.00, -6},
TestFunc: func(v any) any {
vs := v.(args)
return Add(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{-0.2, 2.0, -4.00, -6},
TestFunc: func(v any) any {
vs := v.(args)
return Add(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.9, 2.0, -1.00, -2},
TestFunc: func(v any) any {
vs := v.(args)
return Add(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.9, Float64NaN(), Float64NaN(), Float64NaN()},
TestFunc: func(v any) any {
vs := v.(args)
return Add(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("Add() = %v, want %v", got, tt.Want)
}
})
}
}
func BenchmarkAdd_init(b *testing.B) {
testalignOnce.Do(initTestData)
}
func BenchmarkAdd_release(b *testing.B) {
testalignOnce.Do(initTestData)
x := slices.Clone(testDataFloat64)
y := slices.Clone(testDataFloat64y)
for n := 0; n < b.N; n++ {
_ = Add(x, y)
}
}
func BenchmarkAdd_v1(b *testing.B) {
testalignOnce.Do(initTestData)
x := slices.Clone(testDataFloat64)
y := slices.Clone(testDataFloat64y)
for n := 0; n < b.N; n++ {
_ = v1Add(x, y)
}
}