rethink testing
This commit is contained in:
parent
86d1156968
commit
ea40afef2d
25
src/lib.rs
25
src/lib.rs
|
|
@ -86,11 +86,30 @@ mod tests {
|
|||
#[test]
|
||||
fn test_int_conv() {
|
||||
assert_eq!(u8::from(F8(0)), 0);
|
||||
for e in 0..E_MAX {
|
||||
assert_eq!(u8::from(F8::merge(0, e + E_BIAS)), 1 << e, "e={e}");
|
||||
}
|
||||
assert_eq!(u8::from(F8::merge(0, 1)), 0);
|
||||
assert_eq!(u8::from(F8::merge(0, E_BIAS - 1)), 0);
|
||||
assert_eq!(u8::from(F8::merge(0, E_BIAS)), 1);
|
||||
assert_eq!(u8::from(F8::merge(0, E_BIAS + 1)), 2);
|
||||
assert_eq!(u8::from(F8::merge(0, E_STORAGE_MAX)), 1 << E_MAX);
|
||||
for k in 0..=EXACT_INT_MAX {
|
||||
assert_eq!(u8::from(F8::from(k)), k);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_float_conv() {
|
||||
assert_eq!(f32::from(F8(0)), 0.0);
|
||||
assert_eq!(f32::from(F8::merge(0, E_BIAS)), 1.0);
|
||||
assert_eq!(f32::from(F8::merge(0, E_BIAS - 1)), 0.5);
|
||||
assert_eq!(f32::from(F8::merge(0, E_BIAS + 1)), 2.0);
|
||||
assert_eq!(f32::from(F8::merge(1 << (M_BITS - 1), E_BIAS)), 1.5);
|
||||
assert_eq!(f32::from(F8::merge(1 << (M_BITS - 1), E_BIAS - 1)), 0.75);
|
||||
assert_eq!(
|
||||
f32::from(F8::merge(0, E_STORAGE_MAX)),
|
||||
(E_MAX as f32).exp2()
|
||||
);
|
||||
for k in 0..=EXACT_INT_MAX {
|
||||
assert_eq!(f32::from(F8::from(k)), k as f32);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user