Skip to content

Commit 19c8662

Browse files
committed
Test more types
1 parent d2042aa commit 19c8662

File tree

1 file changed

+57
-25
lines changed

1 file changed

+57
-25
lines changed

tests/all.rs

Lines changed: 57 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,48 @@ 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+
fn test_8_bits<T: Check>(_: T) {
96+
assert!(T::check::<F8E2M5>());
97+
assert!(T::check::<F8E2M5FN>());
98+
assert!(T::check::<F8E2M5FNUZ>());
8699

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

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

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

99-
assert!(Self::check::<F8E5M2>());
100-
assert!(Self::check::<F8E5M2FN>());
101-
assert!(Self::check::<F8E5M2FNUZ>());
102-
}
112+
assert!(T::check::<F8E5M2>());
113+
assert!(T::check::<F8E5M2FN>());
114+
assert!(T::check::<F8E5M2FNUZ>());
115+
116+
assert!(T::check::<F8E6M1>());
117+
assert!(T::check::<F8E6M1FN>());
118+
assert!(T::check::<F8E6M1FNUZ>());
119+
}
120+
121+
fn test_most_8_bits<T: Check>(x: T) {
122+
test_8_bits(x);
123+
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>());
103135
}
104136

105137
#[test]
@@ -135,7 +167,7 @@ fn test_eq() {
135167
for_all::<T>(|x| x.ne(&x) == x.is_nan())
136168
}
137169
}
138-
CheckEq::test();
170+
test_most_8_bits(CheckEq);
139171
}
140172

141173
#[test]
@@ -149,7 +181,7 @@ fn test_neg() {
149181
for_all::<T>(|x| x.to_bits() == (-(-x)).to_bits())
150182
}
151183
}
152-
CheckNeg::test();
184+
test_most_8_bits(CheckNeg);
153185
}
154186

155187
#[test]
@@ -165,7 +197,7 @@ fn test_partial_cmp() {
165197
})
166198
}
167199
}
168-
CheckOrd::test();
200+
test_most_8_bits(CheckOrd);
169201
}
170202

171203
#[test]
@@ -186,7 +218,7 @@ fn test_classify() {
186218
})
187219
}
188220
}
189-
CheckClassify::test();
221+
test_most_8_bits(CheckClassify);
190222
}
191223

192224
#[test]
@@ -202,7 +234,7 @@ fn test_to_f32() {
202234
for_all::<T>(|x| same_mini(T::from_f32(x.to_f32()), x))
203235
}
204236
}
205-
CheckToF32::test();
237+
test_most_8_bits(CheckToF32);
206238
}
207239

208240
#[test]
@@ -218,7 +250,7 @@ fn test_to_f64() {
218250
for_all::<T>(|x| same_mini(T::from_f64(x.to_f64()), x))
219251
}
220252
}
221-
CheckToF64::test();
253+
test_most_8_bits(CheckToF64);
222254
}
223255

224256
#[test]
@@ -232,5 +264,5 @@ fn test_to_floats() {
232264
for_all::<T>(|x| same_f64(x.to_f32().into(), x.to_f64()))
233265
}
234266
}
235-
CheckToFloats::test();
267+
test_most_8_bits(CheckToFloats);
236268
}

0 commit comments

Comments
 (0)