Consolidate tests of numeric operations

This commit is contained in:
Brendan Zabarauskas 2013-04-14 02:53:00 +10:00
parent ce6ee7bb04
commit c4685477e0
6 changed files with 29 additions and 83 deletions

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -397,18 +397,6 @@ fn test_int_from_str_overflow() {
assert!((i64::from_str(~"-9223372036854775809").is_none()));
}
#[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 = ~[];

View File

@ -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);
}

View File

@ -411,18 +411,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))]