-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfloat_test.go
More file actions
95 lines (92 loc) · 1.32 KB
/
float_test.go
File metadata and controls
95 lines (92 loc) · 1.32 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
package series
import (
"testing"
)
func Test_fpEq(t *testing.T) {
type args struct {
v1 DType
v2 DType
eps DType
}
tests := []struct {
name string
args args
want bool
}{
{
name: "eq zero vs zero",
args: args{
v1: 0,
v2: 0,
eps: EpsFp32,
},
want: true,
},
{
name: "not eq zero vs 1",
args: args{
v1: 0,
v2: 1,
eps: EpsFp32,
},
want: false,
},
{
name: "not eq 1 vs zero",
args: args{
v1: 1,
v2: 0,
eps: EpsFp32,
},
want: false,
},
{
name: "eq near",
args: args{
v1: 1.000000000302,
v2: 1.000000000501,
eps: EpsFp32,
},
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := fpEq(tt.args.v1, tt.args.v2, tt.args.eps); got != tt.want {
t.Errorf("fpEq() = %v, want %v", got, tt.want)
}
})
}
}
func Test_fpZero(t *testing.T) {
type args struct {
v DType
}
tests := []struct {
name string
args args
want DType
}{
{
name: "1",
args: args{
v: 1,
},
want: 1,
},
{
name: "1e-08",
args: args{
v: 1e-08,
},
want: 0,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := fpZero(tt.args.v, EpsFp32); got != tt.want {
t.Errorf("fpZero() = %v, want %v", got, tt.want)
}
})
}
}