diff options
| author | Brendan Zabarauskas <bjzaba@yahoo.com.au> | 2013-04-14 02:53:00 +1000 |
|---|---|---|
| committer | Brendan Zabarauskas <bjzaba@yahoo.com.au> | 2013-04-14 02:53:00 +1000 |
| commit | c4685477e0771ee21afa6b93ea0d4ca2c7f6abd9 (patch) | |
| tree | 20f634f93ce97455e4971d3e5e6155a3286b383f | |
| parent | ce6ee7bb041044c3e236be7aefae97931e596407 (diff) | |
| download | rust-c4685477e0771ee21afa6b93ea0d4ca2c7f6abd9.tar.gz rust-c4685477e0771ee21afa6b93ea0d4ca2c7f6abd9.zip | |
Consolidate tests of numeric operations
| -rw-r--r-- | src/libcore/num/f32.rs | 12 | ||||
| -rw-r--r-- | src/libcore/num/f64.rs | 12 | ||||
| -rw-r--r-- | src/libcore/num/float.rs | 12 | ||||
| -rw-r--r-- | src/libcore/num/int-template.rs | 12 | ||||
| -rw-r--r-- | src/libcore/num/num.rs | 52 | ||||
| -rw-r--r-- | src/libcore/num/uint-template.rs | 12 |
6 files changed, 29 insertions, 83 deletions
diff --git a/src/libcore/num/f32.rs b/src/libcore/num/f32.rs index b9e9e7c3073..5e672ea0dfa 100644 --- a/src/libcore/num/f32.rs +++ b/src/libcore/num/f32.rs @@ -555,18 +555,6 @@ impl num::FromStrRadix for f32 { } } -#[test] -pub fn test_num() { - let ten: f32 = num::cast(10); - let two: f32 = num::cast(2); - - assert!((ten.add(&two) == num::cast(12))); - assert!((ten.sub(&two) == num::cast(8))); - assert!((ten.mul(&two) == num::cast(20))); - assert!((ten.div(&two) == num::cast(5))); - assert!((ten.modulo(&two) == num::cast(0))); -} - // // Local Variables: // mode: rust diff --git a/src/libcore/num/f64.rs b/src/libcore/num/f64.rs index 5e8961fa718..4c96da73d21 100644 --- a/src/libcore/num/f64.rs +++ b/src/libcore/num/f64.rs @@ -577,18 +577,6 @@ impl num::FromStrRadix for f64 { } } -#[test] -pub fn test_num() { - let ten: f64 = num::cast(10); - let two: f64 = num::cast(2); - - assert!((ten.add(&two) == num::cast(12))); - assert!((ten.sub(&two) == num::cast(8))); - assert!((ten.mul(&two) == num::cast(20))); - assert!((ten.div(&two) == num::cast(5))); - assert!((ten.modulo(&two) == num::cast(0))); -} - // // Local Variables: // mode: rust diff --git a/src/libcore/num/float.rs b/src/libcore/num/float.rs index e8d7b1e532c..1ab0e24f62d 100644 --- a/src/libcore/num/float.rs +++ b/src/libcore/num/float.rs @@ -663,18 +663,6 @@ pub fn test_round() { assert!(round(-3.5) == -4.0); } -#[test] -pub fn test_num() { - let ten: float = num::cast(10); - let two: float = num::cast(2); - - assert!((ten.add(&two) == num::cast(12))); - assert!((ten.sub(&two) == num::cast(8))); - assert!((ten.mul(&two) == num::cast(20))); - assert!((ten.div(&two) == num::cast(5))); - assert!((ten.modulo(&two) == num::cast(0))); -} - // // Local Variables: diff --git a/src/libcore/num/int-template.rs b/src/libcore/num/int-template.rs index 4af903908f1..6fbe44737d1 100644 --- a/src/libcore/num/int-template.rs +++ b/src/libcore/num/int-template.rs @@ -398,18 +398,6 @@ fn test_int_from_str_overflow() { } #[test] -pub fn test_num() { - let ten: T = num::cast(10); - let two: T = num::cast(2); - - assert!((ten.add(&two) == num::cast(12))); - assert!((ten.sub(&two) == num::cast(8))); - assert!((ten.mul(&two) == num::cast(20))); - assert!((ten.div(&two) == num::cast(5))); - assert!((ten.modulo(&two) == num::cast(0))); -} - -#[test] pub fn test_ranges() { let mut l = ~[]; diff --git a/src/libcore/num/num.rs b/src/libcore/num/num.rs index 333c7ce02b2..fc81393693c 100644 --- a/src/libcore/num/num.rs +++ b/src/libcore/num/num.rs @@ -202,6 +202,35 @@ pub fn pow_with_uint<T:NumCast+One+Zero+Copy+Div<T,T>+Mul<T,T>>( total } +#[cfg(test)] +fn test_num<T:Num + NumCast>(ten: T, two: T) { + assert!(ten.add(&two) == cast(12)); + assert!(ten.sub(&two) == cast(8)); + assert!(ten.mul(&two) == cast(20)); + assert!(ten.div(&two) == cast(5)); + assert!(ten.modulo(&two) == cast(0)); + + assert!(ten.add(&two) == ten + two); + assert!(ten.sub(&two) == ten - two); + assert!(ten.mul(&two) == ten * two); + assert!(ten.div(&two) == ten / two); + assert!(ten.modulo(&two) == ten % two); +} + +#[test] fn test_u8_num() { test_num(10u8, 2u8) } +#[test] fn test_u16_num() { test_num(10u16, 2u16) } +#[test] fn test_u32_num() { test_num(10u32, 2u32) } +#[test] fn test_u64_num() { test_num(10u64, 2u64) } +#[test] fn test_uint_num() { test_num(10u, 2u) } +#[test] fn test_i8_num() { test_num(10i8, 2i8) } +#[test] fn test_i16_num() { test_num(10i16, 2i16) } +#[test] fn test_i32_num() { test_num(10i32, 2i32) } +#[test] fn test_i64_num() { test_num(10i64, 2i64) } +#[test] fn test_int_num() { test_num(10i, 2i) } +#[test] fn test_f32_num() { test_num(10f32, 2f32) } +#[test] fn test_f64_num() { test_num(10f64, 2f64) } +#[test] fn test_float_num() { test_num(10f, 2f) } + macro_rules! test_cast_20( ($_20:expr) => ({ let _20 = $_20; @@ -263,26 +292,3 @@ macro_rules! test_cast_20( #[test] fn test_f32_cast() { test_cast_20!(20f32) } #[test] fn test_f64_cast() { test_cast_20!(20f64) } #[test] fn test_float_cast() { test_cast_20!(20f) } - -#[test] -fn test_generic_cast() { - use ops::Add; - - fn add_2<T: Add<T,T> + NumCast>(n: T) -> T { - n + cast(2) - } - - assert!(add_2(1u) == 3u); - assert!(add_2(1u8) == 3u8); - assert!(add_2(1u16) == 3u16); - assert!(add_2(1u32) == 3u32); - assert!(add_2(1u64) == 3u64); - assert!(add_2(1i) == 3i); - assert!(add_2(1i8) == 3i8); - assert!(add_2(1i16) == 3i16); - assert!(add_2(1i32) == 3i32); - assert!(add_2(1i64) == 3i64); - assert!(add_2(1f) == 3f); - assert!(add_2(1f32) == 3f32); - assert!(add_2(1f64) == 3f64); -} diff --git a/src/libcore/num/uint-template.rs b/src/libcore/num/uint-template.rs index 412921b8c28..1cbdabafdab 100644 --- a/src/libcore/num/uint-template.rs +++ b/src/libcore/num/uint-template.rs @@ -412,18 +412,6 @@ pub fn test_ranges() { } #[test] -pub fn test_num() { - let ten: T = num::cast(10); - let two: T = num::cast(2); - - assert!((ten.add(&two) == num::cast(12))); - assert!((ten.sub(&two) == num::cast(8))); - assert!((ten.mul(&two) == num::cast(20))); - assert!((ten.div(&two) == num::cast(5))); - assert!((ten.modulo(&two) == num::cast(0))); -} - -#[test] #[should_fail] #[ignore(cfg(windows))] fn test_range_step_zero_step_up() { |
