-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtypes_test.go
More file actions
120 lines (113 loc) · 2.37 KB
/
types_test.go
File metadata and controls
120 lines (113 loc) · 2.37 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
package float16
import "testing"
func TestFromInt(t *testing.T) {
tests := []struct {
name string
i int
want Float16
}{
{"FromInt(0)", 0, PositiveZero},
{"FromInt(1)", 1, 0x3C00},
{"FromInt(-1)", -1, 0xBC00},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := FromInt(tt.i); got != tt.want {
t.Errorf("FromInt() = %v, want %v", got, tt.want)
}
})
}
}
func TestFromInt32(t *testing.T) {
tests := []struct {
name string
i int32
want Float16
}{
{"FromInt32(0)", 0, PositiveZero},
{"FromInt32(1)", 1, 0x3C00},
{"FromInt32(-1)", -1, 0xBC00},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := FromInt32(tt.i); got != tt.want {
t.Errorf("FromInt32() = %v, want %v", got, tt.want)
}
})
}
}
func TestFromInt64(t *testing.T) {
tests := []struct {
name string
i int64
want Float16
}{
{"FromInt64(0)", 0, PositiveZero},
{"FromInt64(1)", 1, 0x3C00},
{"FromInt64(-1)", -1, 0xBC00},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := FromInt64(tt.i); got != tt.want {
t.Errorf("FromInt64() = %v, want %v", got, tt.want)
}
})
}
}
func TestToInt(t *testing.T) {
tests := []struct {
name string
f Float16
want int
}{
{"ToInt(0)", PositiveZero, 0},
{"ToInt(1.0)", 0x3C00, 1},
{"ToInt(-1.0)", 0xBC00, -1},
{"ToInt(1.9)", 0x3F33, 1},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.f.ToInt(); got != tt.want {
t.Errorf("ToInt() = %v, want %v", got, tt.want)
}
})
}
}
func TestToInt32(t *testing.T) {
tests := []struct {
name string
f Float16
want int32
}{
{"ToInt32(0)", PositiveZero, 0},
{"ToInt32(1.0)", 0x3C00, 1},
{"ToInt32(-1.0)", 0xBC00, -1},
{"ToInt32(1.9)", 0x3F33, 1},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.f.ToInt32(); got != tt.want {
t.Errorf("ToInt32() = %v, want %v", got, tt.want)
}
})
}
}
func TestToInt64(t *testing.T) {
tests := []struct {
name string
f Float16
want int64
}{
{"ToInt64(0)", PositiveZero, 0},
{"ToInt64(1.0)", 0x3C00, 1},
{"ToInt64(-1.0)", 0xBC00, -1},
{"ToInt64(1.9)", 0x3F33, 1},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.f.ToInt64(); got != tt.want {
t.Errorf("ToInt64() = %v, want %v", got, tt.want)
}
})
}
}