Use assert_eq! instead of assert! and remove extraneous parentheses

This commit is contained in:
Brendan Zabarauskas 2013-04-19 01:37:21 +10:00
parent 939a97f5cb
commit a7f6ec8542
4 changed files with 255 additions and 262 deletions

View file

@ -486,29 +486,29 @@ mod tests {
#[test]
pub fn test_to_str_exact_do_decimal() {
let s = to_str_exact(5.0, 4u);
assert!(s == ~"5.0000");
assert_eq!(s, ~"5.0000");
}
#[test]
pub fn test_from_str() {
assert!(from_str(~"3") == Some(3.));
assert!(from_str(~"3.14") == Some(3.14));
assert!(from_str(~"+3.14") == Some(3.14));
assert!(from_str(~"-3.14") == Some(-3.14));
assert!(from_str(~"2.5E10") == Some(25000000000.));
assert!(from_str(~"2.5e10") == Some(25000000000.));
assert!(from_str(~"25000000000.E-10") == Some(2.5));
assert!(from_str(~".") == Some(0.));
assert!(from_str(~".e1") == Some(0.));
assert!(from_str(~".e-1") == Some(0.));
assert!(from_str(~"5.") == Some(5.));
assert!(from_str(~".5") == Some(0.5));
assert!(from_str(~"0.5") == Some(0.5));
assert!(from_str(~"-.5") == Some(-0.5));
assert!(from_str(~"-5") == Some(-5.));
assert!(from_str(~"inf") == Some(infinity));
assert!(from_str(~"+inf") == Some(infinity));
assert!(from_str(~"-inf") == Some(neg_infinity));
assert_eq!(from_str(~"3"), Some(3.));
assert_eq!(from_str(~"3.14"), Some(3.14));
assert_eq!(from_str(~"+3.14"), Some(3.14));
assert_eq!(from_str(~"-3.14"), Some(-3.14));
assert_eq!(from_str(~"2.5E10"), Some(25000000000.));
assert_eq!(from_str(~"2.5e10"), Some(25000000000.));
assert_eq!(from_str(~"25000000000.E-10"), Some(2.5));
assert_eq!(from_str(~"."), Some(0.));
assert_eq!(from_str(~".e1"), Some(0.));
assert_eq!(from_str(~".e-1"), Some(0.));
assert_eq!(from_str(~"5."), Some(5.));
assert_eq!(from_str(~".5"), Some(0.5));
assert_eq!(from_str(~"0.5"), Some(0.5));
assert_eq!(from_str(~"-.5"), Some(-0.5));
assert_eq!(from_str(~"-5"), Some(-5.));
assert_eq!(from_str(~"inf"), Some(infinity));
assert_eq!(from_str(~"+inf"), Some(infinity));
assert_eq!(from_str(~"-inf"), Some(neg_infinity));
// note: NaN != NaN, hence this slightly complex test
match from_str(~"NaN") {
Some(f) => assert!(is_NaN(f)),
@ -538,24 +538,24 @@ mod tests {
#[test]
pub fn test_from_str_hex() {
assert!(from_str_hex(~"a4") == Some(164.));
assert!(from_str_hex(~"a4.fe") == Some(164.9921875));
assert!(from_str_hex(~"-a4.fe") == Some(-164.9921875));
assert!(from_str_hex(~"+a4.fe") == Some(164.9921875));
assert!(from_str_hex(~"ff0P4") == Some(0xff00 as float));
assert!(from_str_hex(~"ff0p4") == Some(0xff00 as float));
assert!(from_str_hex(~"ff0p-4") == Some(0xff as float));
assert!(from_str_hex(~".") == Some(0.));
assert!(from_str_hex(~".p1") == Some(0.));
assert!(from_str_hex(~".p-1") == Some(0.));
assert!(from_str_hex(~"f.") == Some(15.));
assert!(from_str_hex(~".f") == Some(0.9375));
assert!(from_str_hex(~"0.f") == Some(0.9375));
assert!(from_str_hex(~"-.f") == Some(-0.9375));
assert!(from_str_hex(~"-f") == Some(-15.));
assert!(from_str_hex(~"inf") == Some(infinity));
assert!(from_str_hex(~"+inf") == Some(infinity));
assert!(from_str_hex(~"-inf") == Some(neg_infinity));
assert_eq!(from_str_hex(~"a4"), Some(164.));
assert_eq!(from_str_hex(~"a4.fe"), Some(164.9921875));
assert_eq!(from_str_hex(~"-a4.fe"), Some(-164.9921875));
assert_eq!(from_str_hex(~"+a4.fe"), Some(164.9921875));
assert_eq!(from_str_hex(~"ff0P4"), Some(0xff00 as float));
assert_eq!(from_str_hex(~"ff0p4"), Some(0xff00 as float));
assert_eq!(from_str_hex(~"ff0p-4"), Some(0xff as float));
assert_eq!(from_str_hex(~"."), Some(0.));
assert_eq!(from_str_hex(~".p1"), Some(0.));
assert_eq!(from_str_hex(~".p-1"), Some(0.));
assert_eq!(from_str_hex(~"f."), Some(15.));
assert_eq!(from_str_hex(~".f"), Some(0.9375));
assert_eq!(from_str_hex(~"0.f"), Some(0.9375));
assert_eq!(from_str_hex(~"-.f"), Some(-0.9375));
assert_eq!(from_str_hex(~"-f"), Some(-15.));
assert_eq!(from_str_hex(~"inf"), Some(infinity));
assert_eq!(from_str_hex(~"+inf"), Some(infinity));
assert_eq!(from_str_hex(~"-inf"), Some(neg_infinity));
// note: NaN != NaN, hence this slightly complex test
match from_str_hex(~"NaN") {
Some(f) => assert!(is_NaN(f)),
@ -570,11 +570,11 @@ mod tests {
Some(v) if is_zero(v) => assert!(is_positive(v)),
_ => fail!()
}
assert!(from_str_hex(~"e") == Some(14.));
assert!(from_str_hex(~"E") == Some(14.));
assert!(from_str_hex(~"E1") == Some(225.));
assert!(from_str_hex(~"1e1e1") == Some(123361.));
assert!(from_str_hex(~"1e1.1") == Some(481.0625));
assert_eq!(from_str_hex(~"e"), Some(14.));
assert_eq!(from_str_hex(~"E"), Some(14.));
assert_eq!(from_str_hex(~"E1"), Some(225.));
assert_eq!(from_str_hex(~"1e1e1"), Some(123361.));
assert_eq!(from_str_hex(~"1e1.1"), Some(481.0625));
assert!(from_str_hex(~"").is_none());
assert!(from_str_hex(~"x").is_none());
@ -590,92 +590,92 @@ mod tests {
#[test]
pub fn test_to_str_hex() {
assert!(to_str_hex(164.) == ~"a4");
assert!(to_str_hex(164.9921875) == ~"a4.fe");
assert!(to_str_hex(-164.9921875) == ~"-a4.fe");
assert!(to_str_hex(0xff00 as float) == ~"ff00");
assert!(to_str_hex(-(0xff00 as float)) == ~"-ff00");
assert!(to_str_hex(0.) == ~"0");
assert!(to_str_hex(15.) == ~"f");
assert!(to_str_hex(-15.) == ~"-f");
assert!(to_str_hex(0.9375) == ~"0.f");
assert!(to_str_hex(-0.9375) == ~"-0.f");
assert!(to_str_hex(infinity) == ~"inf");
assert!(to_str_hex(neg_infinity) == ~"-inf");
assert!(to_str_hex(NaN) == ~"NaN");
assert!(to_str_hex(0.) == ~"0");
assert!(to_str_hex(-0.) == ~"-0");
assert_eq!(to_str_hex(164.), ~"a4");
assert_eq!(to_str_hex(164.9921875), ~"a4.fe");
assert_eq!(to_str_hex(-164.9921875), ~"-a4.fe");
assert_eq!(to_str_hex(0xff00 as float), ~"ff00");
assert_eq!(to_str_hex(-(0xff00 as float)), ~"-ff00");
assert_eq!(to_str_hex(0.), ~"0");
assert_eq!(to_str_hex(15.), ~"f");
assert_eq!(to_str_hex(-15.), ~"-f");
assert_eq!(to_str_hex(0.9375), ~"0.f");
assert_eq!(to_str_hex(-0.9375), ~"-0.f");
assert_eq!(to_str_hex(infinity), ~"inf");
assert_eq!(to_str_hex(neg_infinity), ~"-inf");
assert_eq!(to_str_hex(NaN), ~"NaN");
assert_eq!(to_str_hex(0.), ~"0");
assert_eq!(to_str_hex(-0.), ~"-0");
}
#[test]
pub fn test_to_str_radix() {
assert!(to_str_radix(36., 36u) == ~"10");
assert!(to_str_radix(8.125, 2u) == ~"1000.001");
assert_eq!(to_str_radix(36., 36u), ~"10");
assert_eq!(to_str_radix(8.125, 2u), ~"1000.001");
}
#[test]
pub fn test_from_str_radix() {
assert!(from_str_radix(~"10", 36u) == Some(36.));
assert!(from_str_radix(~"1000.001", 2u) == Some(8.125));
assert_eq!(from_str_radix(~"10", 36u), Some(36.));
assert_eq!(from_str_radix(~"1000.001", 2u), Some(8.125));
}
#[test]
pub fn test_positive() {
assert!((is_positive(infinity)));
assert!((is_positive(1.)));
assert!((is_positive(0.)));
assert!((!is_positive(-1.)));
assert!((!is_positive(neg_infinity)));
assert!((!is_positive(1./neg_infinity)));
assert!((!is_positive(NaN)));
assert!(is_positive(infinity));
assert!(is_positive(1.));
assert!(is_positive(0.));
assert!(!is_positive(-1.));
assert!(!is_positive(neg_infinity));
assert!(!is_positive(1./neg_infinity));
assert!(!is_positive(NaN));
}
#[test]
pub fn test_negative() {
assert!((!is_negative(infinity)));
assert!((!is_negative(1.)));
assert!((!is_negative(0.)));
assert!((is_negative(-1.)));
assert!((is_negative(neg_infinity)));
assert!((is_negative(1./neg_infinity)));
assert!((!is_negative(NaN)));
assert!(!is_negative(infinity));
assert!(!is_negative(1.));
assert!(!is_negative(0.));
assert!(is_negative(-1.));
assert!(is_negative(neg_infinity));
assert!(is_negative(1./neg_infinity));
assert!(!is_negative(NaN));
}
#[test]
pub fn test_nonpositive() {
assert!((!is_nonpositive(infinity)));
assert!((!is_nonpositive(1.)));
assert!((!is_nonpositive(0.)));
assert!((is_nonpositive(-1.)));
assert!((is_nonpositive(neg_infinity)));
assert!((is_nonpositive(1./neg_infinity)));
assert!((!is_nonpositive(NaN)));
assert!(!is_nonpositive(infinity));
assert!(!is_nonpositive(1.));
assert!(!is_nonpositive(0.));
assert!(is_nonpositive(-1.));
assert!(is_nonpositive(neg_infinity));
assert!(is_nonpositive(1./neg_infinity));
assert!(!is_nonpositive(NaN));
}
#[test]
pub fn test_nonnegative() {
assert!((is_nonnegative(infinity)));
assert!((is_nonnegative(1.)));
assert!((is_nonnegative(0.)));
assert!((!is_nonnegative(-1.)));
assert!((!is_nonnegative(neg_infinity)));
assert!((!is_nonnegative(1./neg_infinity)));
assert!((!is_nonnegative(NaN)));
assert!(is_nonnegative(infinity));
assert!(is_nonnegative(1.));
assert!(is_nonnegative(0.));
assert!(!is_nonnegative(-1.));
assert!(!is_nonnegative(neg_infinity));
assert!(!is_nonnegative(1./neg_infinity));
assert!(!is_nonnegative(NaN));
}
#[test]
pub fn test_to_str_inf() {
assert!(to_str_digits(infinity, 10u) == ~"inf");
assert!(to_str_digits(-infinity, 10u) == ~"-inf");
assert_eq!(to_str_digits(infinity, 10u), ~"inf");
assert_eq!(to_str_digits(-infinity, 10u), ~"-inf");
}
#[test]
pub fn test_round() {
assert!(round(5.8) == 6.0);
assert!(round(5.2) == 5.0);
assert!(round(3.0) == 3.0);
assert!(round(2.5) == 3.0);
assert!(round(-3.5) == -4.0);
assert_eq!(round(5.8), 6.0);
assert_eq!(round(5.2), 5.0);
assert_eq!(round(3.0), 3.0);
assert_eq!(round(2.5), 3.0);
assert_eq!(round(-3.5), -4.0);
}
}

View file

@ -322,27 +322,27 @@ mod tests {
#[test]
fn test_bitwise_ops() {
assert!(0b1110 as T == (0b1100 as T).bitor(&(0b1010 as T)));
assert!(0b1000 as T == (0b1100 as T).bitand(&(0b1010 as T)));
assert!(0b0110 as T == (0b1100 as T).bitxor(&(0b1010 as T)));
assert!(0b1110 as T == (0b0111 as T).shl(&(1 as T)));
assert!(0b0111 as T == (0b1110 as T).shr(&(1 as T)));
assert!(-(0b11 as T) - (1 as T) == (0b11 as T).not());
assert_eq!(0b1110 as T, (0b1100 as T).bitor(&(0b1010 as T)));
assert_eq!(0b1000 as T, (0b1100 as T).bitand(&(0b1010 as T)));
assert_eq!(0b0110 as T, (0b1100 as T).bitxor(&(0b1010 as T)));
assert_eq!(0b1110 as T, (0b0111 as T).shl(&(1 as T)));
assert_eq!(0b0111 as T, (0b1110 as T).shr(&(1 as T)));
assert_eq!(-(0b11 as T) - (1 as T), (0b11 as T).not());
}
#[test]
fn test_from_str() {
assert!(from_str(~"0") == Some(0 as T));
assert!(from_str(~"3") == Some(3 as T));
assert!(from_str(~"10") == Some(10 as T));
assert!(i32::from_str(~"123456789") == Some(123456789 as i32));
assert!(from_str(~"00100") == Some(100 as T));
assert_eq!(from_str(~"0"), Some(0 as T));
assert_eq!(from_str(~"3"), Some(3 as T));
assert_eq!(from_str(~"10"), Some(10 as T));
assert_eq!(i32::from_str(~"123456789"), Some(123456789 as i32));
assert_eq!(from_str(~"00100"), Some(100 as T));
assert!(from_str(~"-1") == Some(-1 as T));
assert!(from_str(~"-3") == Some(-3 as T));
assert!(from_str(~"-10") == Some(-10 as T));
assert!(i32::from_str(~"-123456789") == Some(-123456789 as i32));
assert!(from_str(~"-00100") == Some(-100 as T));
assert_eq!(from_str(~"-1"), Some(-1 as T));
assert_eq!(from_str(~"-3"), Some(-3 as T));
assert_eq!(from_str(~"-10"), Some(-10 as T));
assert_eq!(i32::from_str(~"-123456789"), Some(-123456789 as i32));
assert_eq!(from_str(~"-00100"), Some(-100 as T));
assert!(from_str(~" ").is_none());
assert!(from_str(~"x").is_none());
@ -351,28 +351,23 @@ mod tests {
#[test]
fn test_parse_bytes() {
use str::to_bytes;
assert!(parse_bytes(to_bytes(~"123"), 10u) == Some(123 as T));
assert!(parse_bytes(to_bytes(~"1001"), 2u) == Some(9 as T));
assert!(parse_bytes(to_bytes(~"123"), 8u) == Some(83 as T));
assert!(i32::parse_bytes(to_bytes(~"123"), 16u) == Some(291 as i32));
assert!(i32::parse_bytes(to_bytes(~"ffff"), 16u) ==
Some(65535 as i32));
assert!(i32::parse_bytes(to_bytes(~"FFFF"), 16u) ==
Some(65535 as i32));
assert!(parse_bytes(to_bytes(~"z"), 36u) == Some(35 as T));
assert!(parse_bytes(to_bytes(~"Z"), 36u) == Some(35 as T));
assert_eq!(parse_bytes(to_bytes(~"123"), 10u), Some(123 as T));
assert_eq!(parse_bytes(to_bytes(~"1001"), 2u), Some(9 as T));
assert_eq!(parse_bytes(to_bytes(~"123"), 8u), Some(83 as T));
assert_eq!(i32::parse_bytes(to_bytes(~"123"), 16u), Some(291 as i32));
assert_eq!(i32::parse_bytes(to_bytes(~"ffff"), 16u), Some(65535 as i32));
assert_eq!(i32::parse_bytes(to_bytes(~"FFFF"), 16u), Some(65535 as i32));
assert_eq!(parse_bytes(to_bytes(~"z"), 36u), Some(35 as T));
assert_eq!(parse_bytes(to_bytes(~"Z"), 36u), Some(35 as T));
assert!(parse_bytes(to_bytes(~"-123"), 10u) == Some(-123 as T));
assert!(parse_bytes(to_bytes(~"-1001"), 2u) == Some(-9 as T));
assert!(parse_bytes(to_bytes(~"-123"), 8u) == Some(-83 as T));
assert!(i32::parse_bytes(to_bytes(~"-123"), 16u) ==
Some(-291 as i32));
assert!(i32::parse_bytes(to_bytes(~"-ffff"), 16u) ==
Some(-65535 as i32));
assert!(i32::parse_bytes(to_bytes(~"-FFFF"), 16u) ==
Some(-65535 as i32));
assert!(parse_bytes(to_bytes(~"-z"), 36u) == Some(-35 as T));
assert!(parse_bytes(to_bytes(~"-Z"), 36u) == Some(-35 as T));
assert_eq!(parse_bytes(to_bytes(~"-123"), 10u), Some(-123 as T));
assert_eq!(parse_bytes(to_bytes(~"-1001"), 2u), Some(-9 as T));
assert_eq!(parse_bytes(to_bytes(~"-123"), 8u), Some(-83 as T));
assert_eq!(i32::parse_bytes(to_bytes(~"-123"), 16u), Some(-291 as i32));
assert_eq!(i32::parse_bytes(to_bytes(~"-ffff"), 16u), Some(-65535 as i32));
assert_eq!(i32::parse_bytes(to_bytes(~"-FFFF"), 16u), Some(-65535 as i32));
assert_eq!(parse_bytes(to_bytes(~"-z"), 36u), Some(-35 as T));
assert_eq!(parse_bytes(to_bytes(~"-Z"), 36u), Some(-35 as T));
assert!(parse_bytes(to_bytes(~"Z"), 35u).is_none());
assert!(parse_bytes(to_bytes(~"-9"), 2u).is_none());
@ -380,74 +375,74 @@ mod tests {
#[test]
fn test_to_str() {
assert!((to_str_radix(0 as T, 10u) == ~"0"));
assert!((to_str_radix(1 as T, 10u) == ~"1"));
assert!((to_str_radix(-1 as T, 10u) == ~"-1"));
assert!((to_str_radix(127 as T, 16u) == ~"7f"));
assert!((to_str_radix(100 as T, 10u) == ~"100"));
assert_eq!(to_str_radix(0 as T, 10u), ~"0");
assert_eq!(to_str_radix(1 as T, 10u), ~"1");
assert_eq!(to_str_radix(-1 as T, 10u), ~"-1");
assert_eq!(to_str_radix(127 as T, 16u), ~"7f");
assert_eq!(to_str_radix(100 as T, 10u), ~"100");
}
#[test]
fn test_int_to_str_overflow() {
let mut i8_val: i8 = 127_i8;
assert!((i8::to_str(i8_val) == ~"127"));
assert_eq!(i8::to_str(i8_val), ~"127");
i8_val += 1 as i8;
assert!((i8::to_str(i8_val) == ~"-128"));
assert_eq!(i8::to_str(i8_val), ~"-128");
let mut i16_val: i16 = 32_767_i16;
assert!((i16::to_str(i16_val) == ~"32767"));
assert_eq!(i16::to_str(i16_val), ~"32767");
i16_val += 1 as i16;
assert!((i16::to_str(i16_val) == ~"-32768"));
assert_eq!(i16::to_str(i16_val), ~"-32768");
let mut i32_val: i32 = 2_147_483_647_i32;
assert!((i32::to_str(i32_val) == ~"2147483647"));
assert_eq!(i32::to_str(i32_val), ~"2147483647");
i32_val += 1 as i32;
assert!((i32::to_str(i32_val) == ~"-2147483648"));
assert_eq!(i32::to_str(i32_val), ~"-2147483648");
let mut i64_val: i64 = 9_223_372_036_854_775_807_i64;
assert!((i64::to_str(i64_val) == ~"9223372036854775807"));
assert_eq!(i64::to_str(i64_val), ~"9223372036854775807");
i64_val += 1 as i64;
assert!((i64::to_str(i64_val) == ~"-9223372036854775808"));
assert_eq!(i64::to_str(i64_val), ~"-9223372036854775808");
}
#[test]
fn test_int_from_str_overflow() {
let mut i8_val: i8 = 127_i8;
assert!((i8::from_str(~"127") == Some(i8_val)));
assert!((i8::from_str(~"128").is_none()));
assert_eq!(i8::from_str(~"127"), Some(i8_val));
assert!(i8::from_str(~"128").is_none());
i8_val += 1 as i8;
assert!((i8::from_str(~"-128") == Some(i8_val)));
assert!((i8::from_str(~"-129").is_none()));
assert_eq!(i8::from_str(~"-128"), Some(i8_val));
assert!(i8::from_str(~"-129").is_none());
let mut i16_val: i16 = 32_767_i16;
assert!((i16::from_str(~"32767") == Some(i16_val)));
assert!((i16::from_str(~"32768").is_none()));
assert_eq!(i16::from_str(~"32767"), Some(i16_val));
assert!(i16::from_str(~"32768").is_none());
i16_val += 1 as i16;
assert!((i16::from_str(~"-32768") == Some(i16_val)));
assert!((i16::from_str(~"-32769").is_none()));
assert_eq!(i16::from_str(~"-32768"), Some(i16_val));
assert!(i16::from_str(~"-32769").is_none());
let mut i32_val: i32 = 2_147_483_647_i32;
assert!((i32::from_str(~"2147483647") == Some(i32_val)));
assert!((i32::from_str(~"2147483648").is_none()));
assert_eq!(i32::from_str(~"2147483647"), Some(i32_val));
assert!(i32::from_str(~"2147483648").is_none());
i32_val += 1 as i32;
assert!((i32::from_str(~"-2147483648") == Some(i32_val)));
assert!((i32::from_str(~"-2147483649").is_none()));
assert_eq!(i32::from_str(~"-2147483648"), Some(i32_val));
assert!(i32::from_str(~"-2147483649").is_none());
let mut i64_val: i64 = 9_223_372_036_854_775_807_i64;
assert!((i64::from_str(~"9223372036854775807") == Some(i64_val)));
assert!((i64::from_str(~"9223372036854775808").is_none()));
assert_eq!(i64::from_str(~"9223372036854775807"), Some(i64_val));
assert!(i64::from_str(~"9223372036854775808").is_none());
i64_val += 1 as i64;
assert!((i64::from_str(~"-9223372036854775808") == Some(i64_val)));
assert!((i64::from_str(~"-9223372036854775809").is_none()));
assert_eq!(i64::from_str(~"-9223372036854775808"), Some(i64_val));
assert!(i64::from_str(~"-9223372036854775809").is_none());
}
#[test]

View file

@ -77,7 +77,7 @@ pub enum RoundMode {
*
* ~~~
* let twenty: f32 = num::cast(0x14);
* assert!(twenty == 20f32);
* assert_eq!(twenty, 20f32);
* ~~~
*/
#[inline(always)]
@ -196,17 +196,17 @@ pub fn pow_with_uint<T:NumCast+One+Zero+Copy+Div<T,T>+Mul<T,T>>(
#[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_eq!(ten.add(&two), cast(12));
assert_eq!(ten.sub(&two), cast(8));
assert_eq!(ten.mul(&two), cast(20));
assert_eq!(ten.div(&two), cast(5));
assert_eq!(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);
assert_eq!(ten.add(&two), ten + two);
assert_eq!(ten.sub(&two), ten - two);
assert_eq!(ten.mul(&two), ten * two);
assert_eq!(ten.div(&two), ten / two);
assert_eq!(ten.modulo(&two), ten % two);
}
#[test] fn test_u8_num() { test_num(10u8, 2u8) }
@ -227,47 +227,47 @@ macro_rules! test_cast_20(
($_20:expr) => ({
let _20 = $_20;
assert!(20u == _20.to_uint());
assert!(20u8 == _20.to_u8());
assert!(20u16 == _20.to_u16());
assert!(20u32 == _20.to_u32());
assert!(20u64 == _20.to_u64());
assert!(20i == _20.to_int());
assert!(20i8 == _20.to_i8());
assert!(20i16 == _20.to_i16());
assert!(20i32 == _20.to_i32());
assert!(20i64 == _20.to_i64());
assert!(20f == _20.to_float());
assert!(20f32 == _20.to_f32());
assert!(20f64 == _20.to_f64());
assert_eq!(20u, _20.to_uint());
assert_eq!(20u8, _20.to_u8());
assert_eq!(20u16, _20.to_u16());
assert_eq!(20u32, _20.to_u32());
assert_eq!(20u64, _20.to_u64());
assert_eq!(20i, _20.to_int());
assert_eq!(20i8, _20.to_i8());
assert_eq!(20i16, _20.to_i16());
assert_eq!(20i32, _20.to_i32());
assert_eq!(20i64, _20.to_i64());
assert_eq!(20f, _20.to_float());
assert_eq!(20f32, _20.to_f32());
assert_eq!(20f64, _20.to_f64());
assert!(_20 == NumCast::from(20u));
assert!(_20 == NumCast::from(20u8));
assert!(_20 == NumCast::from(20u16));
assert!(_20 == NumCast::from(20u32));
assert!(_20 == NumCast::from(20u64));
assert!(_20 == NumCast::from(20i));
assert!(_20 == NumCast::from(20i8));
assert!(_20 == NumCast::from(20i16));
assert!(_20 == NumCast::from(20i32));
assert!(_20 == NumCast::from(20i64));
assert!(_20 == NumCast::from(20f));
assert!(_20 == NumCast::from(20f32));
assert!(_20 == NumCast::from(20f64));
assert_eq!(_20, NumCast::from(20u));
assert_eq!(_20, NumCast::from(20u8));
assert_eq!(_20, NumCast::from(20u16));
assert_eq!(_20, NumCast::from(20u32));
assert_eq!(_20, NumCast::from(20u64));
assert_eq!(_20, NumCast::from(20i));
assert_eq!(_20, NumCast::from(20i8));
assert_eq!(_20, NumCast::from(20i16));
assert_eq!(_20, NumCast::from(20i32));
assert_eq!(_20, NumCast::from(20i64));
assert_eq!(_20, NumCast::from(20f));
assert_eq!(_20, NumCast::from(20f32));
assert_eq!(_20, NumCast::from(20f64));
assert!(_20 == cast(20u));
assert!(_20 == cast(20u8));
assert!(_20 == cast(20u16));
assert!(_20 == cast(20u32));
assert!(_20 == cast(20u64));
assert!(_20 == cast(20i));
assert!(_20 == cast(20i8));
assert!(_20 == cast(20i16));
assert!(_20 == cast(20i32));
assert!(_20 == cast(20i64));
assert!(_20 == cast(20f));
assert!(_20 == cast(20f32));
assert!(_20 == cast(20f64));
assert_eq!(_20, cast(20u));
assert_eq!(_20, cast(20u8));
assert_eq!(_20, cast(20u16));
assert_eq!(_20, cast(20u32));
assert_eq!(_20, cast(20u64));
assert_eq!(_20, cast(20i));
assert_eq!(_20, cast(20i8));
assert_eq!(_20, cast(20i16));
assert_eq!(_20, cast(20i32));
assert_eq!(_20, cast(20i64));
assert_eq!(_20, cast(20f));
assert_eq!(_20, cast(20f32));
assert_eq!(_20, cast(20f64));
})
)

View file

@ -287,32 +287,32 @@ mod tests {
#[test]
fn test_bitwise_ops() {
assert!(0b1110 as T == (0b1100 as T).bitor(&(0b1010 as T)));
assert!(0b1000 as T == (0b1100 as T).bitand(&(0b1010 as T)));
assert!(0b0110 as T == (0b1100 as T).bitxor(&(0b1010 as T)));
assert!(0b1110 as T == (0b0111 as T).shl(&(1 as T)));
assert!(0b0111 as T == (0b1110 as T).shr(&(1 as T)));
assert!(max_value - (0b1011 as T) == (0b1011 as T).not());
assert_eq!(0b1110 as T, (0b1100 as T).bitor(&(0b1010 as T)));
assert_eq!(0b1000 as T, (0b1100 as T).bitand(&(0b1010 as T)));
assert_eq!(0b0110 as T, (0b1100 as T).bitxor(&(0b1010 as T)));
assert_eq!(0b1110 as T, (0b0111 as T).shl(&(1 as T)));
assert_eq!(0b0111 as T, (0b1110 as T).shr(&(1 as T)));
assert_eq!(max_value - (0b1011 as T), (0b1011 as T).not());
}
#[test]
pub fn test_to_str() {
assert!(to_str_radix(0 as T, 10u) == ~"0");
assert!(to_str_radix(1 as T, 10u) == ~"1");
assert!(to_str_radix(2 as T, 10u) == ~"2");
assert!(to_str_radix(11 as T, 10u) == ~"11");
assert!(to_str_radix(11 as T, 16u) == ~"b");
assert!(to_str_radix(255 as T, 16u) == ~"ff");
assert!(to_str_radix(0xff as T, 10u) == ~"255");
assert_eq!(to_str_radix(0 as T, 10u), ~"0");
assert_eq!(to_str_radix(1 as T, 10u), ~"1");
assert_eq!(to_str_radix(2 as T, 10u), ~"2");
assert_eq!(to_str_radix(11 as T, 10u), ~"11");
assert_eq!(to_str_radix(11 as T, 16u), ~"b");
assert_eq!(to_str_radix(255 as T, 16u), ~"ff");
assert_eq!(to_str_radix(0xff as T, 10u), ~"255");
}
#[test]
pub fn test_from_str() {
assert!(from_str(~"0") == Some(0u as T));
assert!(from_str(~"3") == Some(3u as T));
assert!(from_str(~"10") == Some(10u as T));
assert!(u32::from_str(~"123456789") == Some(123456789 as u32));
assert!(from_str(~"00100") == Some(100u as T));
assert_eq!(from_str(~"0"), Some(0u as T));
assert_eq!(from_str(~"3"), Some(3u as T));
assert_eq!(from_str(~"10"), Some(10u as T));
assert_eq!(u32::from_str(~"123456789"), Some(123456789 as u32));
assert_eq!(from_str(~"00100"), Some(100u as T));
assert!(from_str(~"").is_none());
assert!(from_str(~" ").is_none());
@ -322,14 +322,12 @@ mod tests {
#[test]
pub fn test_parse_bytes() {
use str::to_bytes;
assert!(parse_bytes(to_bytes(~"123"), 10u) == Some(123u as T));
assert!(parse_bytes(to_bytes(~"1001"), 2u) == Some(9u as T));
assert!(parse_bytes(to_bytes(~"123"), 8u) == Some(83u as T));
assert!(u16::parse_bytes(to_bytes(~"123"), 16u) ==
Some(291u as u16));
assert!(u16::parse_bytes(to_bytes(~"ffff"), 16u) ==
Some(65535u as u16));
assert!(parse_bytes(to_bytes(~"z"), 36u) == Some(35u as T));
assert_eq!(parse_bytes(to_bytes(~"123"), 10u), Some(123u as T));
assert_eq!(parse_bytes(to_bytes(~"1001"), 2u), Some(9u as T));
assert_eq!(parse_bytes(to_bytes(~"123"), 8u), Some(83u as T));
assert_eq!(u16::parse_bytes(to_bytes(~"123"), 16u), Some(291u as u16));
assert_eq!(u16::parse_bytes(to_bytes(~"ffff"), 16u), Some(65535u as u16));
assert_eq!(parse_bytes(to_bytes(~"z"), 36u), Some(35u as T));
assert!(parse_bytes(to_bytes(~"Z"), 10u).is_none());
assert!(parse_bytes(to_bytes(~"_"), 2u).is_none());
@ -338,63 +336,63 @@ mod tests {
#[test]
fn test_uint_to_str_overflow() {
let mut u8_val: u8 = 255_u8;
assert!((u8::to_str(u8_val) == ~"255"));
assert_eq!(u8::to_str(u8_val), ~"255");
u8_val += 1 as u8;
assert!((u8::to_str(u8_val) == ~"0"));
assert_eq!(u8::to_str(u8_val), ~"0");
let mut u16_val: u16 = 65_535_u16;
assert!((u16::to_str(u16_val) == ~"65535"));
assert_eq!(u16::to_str(u16_val), ~"65535");
u16_val += 1 as u16;
assert!((u16::to_str(u16_val) == ~"0"));
assert_eq!(u16::to_str(u16_val), ~"0");
let mut u32_val: u32 = 4_294_967_295_u32;
assert!((u32::to_str(u32_val) == ~"4294967295"));
assert_eq!(u32::to_str(u32_val), ~"4294967295");
u32_val += 1 as u32;
assert!((u32::to_str(u32_val) == ~"0"));
assert_eq!(u32::to_str(u32_val), ~"0");
let mut u64_val: u64 = 18_446_744_073_709_551_615_u64;
assert!((u64::to_str(u64_val) == ~"18446744073709551615"));
assert_eq!(u64::to_str(u64_val), ~"18446744073709551615");
u64_val += 1 as u64;
assert!((u64::to_str(u64_val) == ~"0"));
assert_eq!(u64::to_str(u64_val), ~"0");
}
#[test]
fn test_uint_from_str_overflow() {
let mut u8_val: u8 = 255_u8;
assert!((u8::from_str(~"255") == Some(u8_val)));
assert!((u8::from_str(~"256").is_none()));
assert_eq!(u8::from_str(~"255"), Some(u8_val));
assert!(u8::from_str(~"256").is_none());
u8_val += 1 as u8;
assert!((u8::from_str(~"0") == Some(u8_val)));
assert!((u8::from_str(~"-1").is_none()));
assert_eq!(u8::from_str(~"0"), Some(u8_val));
assert!(u8::from_str(~"-1").is_none());
let mut u16_val: u16 = 65_535_u16;
assert!((u16::from_str(~"65535") == Some(u16_val)));
assert!((u16::from_str(~"65536").is_none()));
assert_eq!(u16::from_str(~"65535"), Some(u16_val));
assert!(u16::from_str(~"65536").is_none());
u16_val += 1 as u16;
assert!((u16::from_str(~"0") == Some(u16_val)));
assert!((u16::from_str(~"-1").is_none()));
assert_eq!(u16::from_str(~"0"), Some(u16_val));
assert!(u16::from_str(~"-1").is_none());
let mut u32_val: u32 = 4_294_967_295_u32;
assert!((u32::from_str(~"4294967295") == Some(u32_val)));
assert!((u32::from_str(~"4294967296").is_none()));
assert_eq!(u32::from_str(~"4294967295"), Some(u32_val));
assert!(u32::from_str(~"4294967296").is_none());
u32_val += 1 as u32;
assert!((u32::from_str(~"0") == Some(u32_val)));
assert!((u32::from_str(~"-1").is_none()));
assert_eq!(u32::from_str(~"0"), Some(u32_val));
assert!(u32::from_str(~"-1").is_none());
let mut u64_val: u64 = 18_446_744_073_709_551_615_u64;
assert!((u64::from_str(~"18446744073709551615") == Some(u64_val)));
assert!((u64::from_str(~"18446744073709551616").is_none()));
assert_eq!(u64::from_str(~"18446744073709551615"), Some(u64_val));
assert!(u64::from_str(~"18446744073709551616").is_none());
u64_val += 1 as u64;
assert!((u64::from_str(~"0") == Some(u64_val)));
assert!((u64::from_str(~"-1").is_none()));
assert_eq!(u64::from_str(~"0"), Some(u64_val));
assert!(u64::from_str(~"-1").is_none());
}
#[test]