Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Derive various num traits for newtypes #17

Merged
merged 11 commits into from
Oct 3, 2018
Prev Previous commit
Add explicit tests of has_i128-derived methods
  • Loading branch information
cuviper committed Oct 3, 2018
commit 706ea88d1459ea9e803249eff5a3790295b302c4
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