Skip to content

Commit 706ea88

Browse files
committed
Add explicit tests of has_i128-derived methods
1 parent 203a3db commit 706ea88

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

tests/newtype.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,25 @@ fn test_from_primitive() {
3434
assert_eq!(MyFloat::from_u32(25), Some(MyFloat(25.0)));
3535
}
3636

37+
#[test]
38+
#[cfg(has_i128)]
39+
fn test_from_primitive_128() {
40+
assert_eq!(MyFloat::from_i128(std::i128::MIN), Some(MyFloat(-2.0.powi(127))));
41+
}
42+
3743
#[test]
3844
fn test_to_primitive() {
3945
assert_eq!(MyFloat(25.0).to_u32(), Some(25));
4046
}
4147

48+
#[test]
49+
#[cfg(has_i128)]
50+
fn test_to_primitive_128() {
51+
let f = MyFloat::from_f32(std::f32::MAX).unwrap();
52+
assert_eq!(f.to_i128(), None);
53+
assert_eq!(f.to_u128(), Some(0xffff_ff00_0000_0000_0000_0000_0000_0000));
54+
}
55+
4256
#[test]
4357
fn test_num_ops() {
4458
assert_eq!(MyFloat(25.0) + MyFloat(10.0), MyFloat(35.0));

0 commit comments

Comments
 (0)