libcoretest: fix unit tests
This commit is contained in:
parent
a672b27cbc
commit
1ec5650ad3
3 changed files with 22 additions and 20 deletions
|
@ -64,11 +64,11 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_bitwise_operators() {
|
||||
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));
|
||||
assert!(0b0111 as $T == (0b1110 as $T).shr(&1));
|
||||
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));
|
||||
assert!(0b0111 as $T == (0b1110 as $T).shr(1));
|
||||
assert!(-(0b11 as $T) - (1 as $T) == (0b11 as $T).not());
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ use core::cmp::PartialEq;
|
|||
use core::fmt::Show;
|
||||
use core::num::{NumCast, cast};
|
||||
use core::ops::{Add, Sub, Mul, Div, Rem};
|
||||
use core::kinds::Copy;
|
||||
|
||||
mod int_macros;
|
||||
mod i8;
|
||||
|
@ -32,18 +33,19 @@ pub fn test_num<T>(ten: T, two: T) where
|
|||
+ Add<T, T> + Sub<T, T>
|
||||
+ Mul<T, T> + Div<T, T>
|
||||
+ Rem<T, T> + Show
|
||||
+ Copy
|
||||
{
|
||||
assert_eq!(ten.add(&two), cast(12i).unwrap());
|
||||
assert_eq!(ten.sub(&two), cast(8i).unwrap());
|
||||
assert_eq!(ten.mul(&two), cast(20i).unwrap());
|
||||
assert_eq!(ten.div(&two), cast(5i).unwrap());
|
||||
assert_eq!(ten.rem(&two), cast(0i).unwrap());
|
||||
assert_eq!(ten.add(two), cast(12i).unwrap());
|
||||
assert_eq!(ten.sub(two), cast(8i).unwrap());
|
||||
assert_eq!(ten.mul(two), cast(20i).unwrap());
|
||||
assert_eq!(ten.div(two), cast(5i).unwrap());
|
||||
assert_eq!(ten.rem(two), cast(0i).unwrap());
|
||||
|
||||
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.rem(&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.rem(two), ten % two);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -31,11 +31,11 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_bitwise_operators() {
|
||||
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(&1u));
|
||||
assert!(0b0111 as $T == (0b1110 as $T).shr(&1u));
|
||||
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(1u));
|
||||
assert!(0b0111 as $T == (0b1110 as $T).shr(1u));
|
||||
assert!(MAX - (0b1011 as $T) == (0b1011 as $T).not());
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue