Skip to content

Commit

Permalink
Add explicit tests of has_i128-derived methods
Browse files Browse the repository at this point in the history
  • Loading branch information
cuviper committed Oct 3, 2018
1 parent 203a3db commit 706ea88
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/newtype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,25 @@ fn test_from_primitive() {
assert_eq!(MyFloat::from_u32(25), Some(MyFloat(25.0)));
}

#[test]
#[cfg(has_i128)]
fn test_from_primitive_128() {
assert_eq!(MyFloat::from_i128(std::i128::MIN), Some(MyFloat(-2.0.powi(127))));
}

#[test]
fn test_to_primitive() {
assert_eq!(MyFloat(25.0).to_u32(), Some(25));
}

#[test]
#[cfg(has_i128)]
fn test_to_primitive_128() {
let f = MyFloat::from_f32(std::f32::MAX).unwrap();
assert_eq!(f.to_i128(), None);
assert_eq!(f.to_u128(), Some(0xffff_ff00_0000_0000_0000_0000_0000_0000));
}

#[test]
fn test_num_ops() {
assert_eq!(MyFloat(25.0) + MyFloat(10.0), MyFloat(35.0));
Expand Down

0 comments on commit 706ea88

Please sign in to comment.