Skip to content

Commit 4433c66

Browse files
committed
Test more types
1 parent d2042aa commit 4433c66

File tree

1 file changed

+63
-25
lines changed

1 file changed

+63
-25
lines changed

tests/all.rs

Lines changed: 63 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ minifloat!(struct F8E2M5FNUZ(u8): 2, 5, FNUZ);
2121
minifloat!(struct F8E3M4FNUZ(u8): 3, 4, FNUZ);
2222
minifloat!(struct F8E5M2FN(u8): 5, 2, FN);
2323

24+
minifloat!(struct F8E6M1(u8): 6, 1);
25+
minifloat!(struct F8E6M1FN(u8): 6, 1, FN);
26+
minifloat!(struct F8E6M1FNUZ(u8): 6, 1, FNUZ);
27+
28+
minifloat!(struct F6E2M3(u8): 2, 3);
29+
minifloat!(struct F6E2M3FNUZ(u8): 2, 3, FNUZ);
30+
31+
minifloat!(struct F6E3M2(u8): 3, 2);
32+
minifloat!(struct F6E3M2FNUZ(u8): 3, 2, FNUZ);
33+
34+
minifloat!(struct F4E2M1(u8): 2, 1);
35+
minifloat!(struct F4E2M1FNUZ(u8): 2, 1, FNUZ);
36+
2437
/// Bitmask returned by [`bit_mask`]
2538
///
2639
/// This type must be an unsigned integer.
@@ -77,29 +90,54 @@ trait Check {
7790
fn check<T: Minifloat + Debug>() -> bool
7891
where
7992
Mask: AsPrimitive<T::Bits>;
93+
}
8094

81-
/// Test typical minifloats
82-
fn test() {
83-
assert!(Self::check::<F8E2M5>());
84-
assert!(Self::check::<F8E2M5FN>());
85-
assert!(Self::check::<F8E2M5FNUZ>());
95+
/// Test 8-bit minifloats
96+
fn test_8_bits<T: Check + ?Sized>() {
97+
assert!(T::check::<F8E2M5>());
98+
assert!(T::check::<F8E2M5FN>());
99+
assert!(T::check::<F8E2M5FNUZ>());
86100

87-
assert!(Self::check::<F8E3M4>());
88-
assert!(Self::check::<F8E3M4FN>());
89-
assert!(Self::check::<F8E3M4FNUZ>());
101+
assert!(T::check::<F8E3M4>());
102+
assert!(T::check::<F8E3M4FN>());
103+
assert!(T::check::<F8E3M4FNUZ>());
90104

91-
assert!(Self::check::<F8E4M3>());
92-
assert!(Self::check::<F8E4M3FN>());
93-
assert!(Self::check::<F8E4M3FNUZ>());
105+
assert!(T::check::<F8E4M3>());
106+
assert!(T::check::<F8E4M3FN>());
107+
assert!(T::check::<F8E4M3FNUZ>());
94108

95-
assert!(Self::check::<F8E4M3B11>());
96-
assert!(Self::check::<F8E4M3B11FN>());
97-
assert!(Self::check::<F8E4M3B11FNUZ>());
109+
assert!(T::check::<F8E4M3B11>());
110+
assert!(T::check::<F8E4M3B11FN>());
111+
assert!(T::check::<F8E4M3B11FNUZ>());
98112

99-
assert!(Self::check::<F8E5M2>());
100-
assert!(Self::check::<F8E5M2FN>());
101-
assert!(Self::check::<F8E5M2FNUZ>());
102-
}
113+
assert!(T::check::<F8E5M2>());
114+
assert!(T::check::<F8E5M2FN>());
115+
assert!(T::check::<F8E5M2FNUZ>());
116+
117+
assert!(T::check::<F8E6M1>());
118+
assert!(T::check::<F8E6M1FN>());
119+
assert!(T::check::<F8E6M1FNUZ>());
120+
}
121+
122+
/// Test minifloats less that 8 bits wide
123+
fn test_micro_floats<T: Check + ?Sized>() {
124+
assert!(T::check::<F6E2M3>());
125+
assert!(T::check::<F6E2M3FN>());
126+
assert!(T::check::<F6E2M3FNUZ>());
127+
128+
assert!(T::check::<F6E3M2>());
129+
assert!(T::check::<F6E3M2FN>());
130+
assert!(T::check::<F6E3M2FNUZ>());
131+
132+
assert!(T::check::<F4E2M1>());
133+
assert!(T::check::<F4E2M1FN>());
134+
assert!(T::check::<F4E2M1FNUZ>());
135+
}
136+
137+
/// Test typical minifloats
138+
fn test_typical<T: Check>(_: T) {
139+
test_8_bits::<T>();
140+
test_micro_floats::<T>();
103141
}
104142

105143
#[test]
@@ -135,7 +173,7 @@ fn test_eq() {
135173
for_all::<T>(|x| x.ne(&x) == x.is_nan())
136174
}
137175
}
138-
CheckEq::test();
176+
test_typical(CheckEq);
139177
}
140178

141179
#[test]
@@ -149,7 +187,7 @@ fn test_neg() {
149187
for_all::<T>(|x| x.to_bits() == (-(-x)).to_bits())
150188
}
151189
}
152-
CheckNeg::test();
190+
test_typical(CheckNeg);
153191
}
154192

155193
#[test]
@@ -165,7 +203,7 @@ fn test_partial_cmp() {
165203
})
166204
}
167205
}
168-
CheckOrd::test();
206+
test_typical(CheckOrd);
169207
}
170208

171209
#[test]
@@ -186,7 +224,7 @@ fn test_classify() {
186224
})
187225
}
188226
}
189-
CheckClassify::test();
227+
test_typical(CheckClassify);
190228
}
191229

192230
#[test]
@@ -202,7 +240,7 @@ fn test_to_f32() {
202240
for_all::<T>(|x| same_mini(T::from_f32(x.to_f32()), x))
203241
}
204242
}
205-
CheckToF32::test();
243+
test_typical(CheckToF32);
206244
}
207245

208246
#[test]
@@ -218,7 +256,7 @@ fn test_to_f64() {
218256
for_all::<T>(|x| same_mini(T::from_f64(x.to_f64()), x))
219257
}
220258
}
221-
CheckToF64::test();
259+
test_typical(CheckToF64);
222260
}
223261

224262
#[test]
@@ -232,5 +270,5 @@ fn test_to_floats() {
232270
for_all::<T>(|x| same_f64(x.to_f32().into(), x.to_f64()))
233271
}
234272
}
235-
CheckToFloats::test();
273+
test_typical(CheckToFloats);
236274
}

0 commit comments

Comments
 (0)