Get tests passing again

This commit is contained in:
Alex Crichton 2015-04-02 09:37:32 -07:00
parent 69afe1a3c6
commit fcd3760625
2 changed files with 15 additions and 13 deletions

View File

@ -1796,7 +1796,7 @@ mod biguint_tests {
#[test]
fn test_from_slice() {
fn check(slice: &[BigDigit], data: &[BigDigit]) {
assert!(data == BigUint::from_slice(slice).data);
assert!(BigUint::from_slice(slice).data == data);
}
check(&[1], &[1]);
check(&[0, 0, 0], &[]);
@ -1823,7 +1823,7 @@ mod biguint_tests {
fn test_to_bytes_be() {
fn check(s: &str, result: &str) {
let b = BigUint::parse_bytes(result.as_bytes(), 10).unwrap();
assert_eq!(s.as_bytes(), b.to_bytes_be());
assert_eq!(b.to_bytes_be(), s.as_bytes());
}
check("A", "65");
check("AA", "16705");
@ -1854,7 +1854,7 @@ mod biguint_tests {
fn test_to_bytes_le() {
fn check(s: &str, result: &str) {
let b = BigUint::parse_bytes(result.as_bytes(), 10).unwrap();
assert_eq!(s.as_bytes(), b.to_bytes_le());
assert_eq!(b.to_bytes_le(), s.as_bytes());
}
check("A", "65");
check("AA", "16705");
@ -2306,6 +2306,7 @@ mod biguint_tests {
a - b;
}
const M: u32 = ::std::u32::MAX;
const MUL_TRIPLES: &'static [(&'static [BigDigit],
&'static [BigDigit],
&'static [BigDigit])] = &[
@ -2323,8 +2324,8 @@ mod biguint_tests {
(&[-1, -1], &[-1], &[ 1, -1, -2]),
(&[-1, -1, -1], &[-1], &[ 1, -1, -1, -2]),
(&[-1, -1, -1, -1], &[-1], &[ 1, -1, -1, -1, -2]),
(&[-1/2 + 1], &[ 2], &[ 0, 1]),
(&[0, -1/2 + 1], &[ 2], &[ 0, 0, 1]),
(&[ M/2 + 1], &[ 2], &[ 0, 1]),
(&[0, M/2 + 1], &[ 2], &[ 0, 0, 1]),
(&[ 1, 2], &[ 1, 2, 3], &[1, 4, 7, 6]),
(&[-1, -1], &[-1, -1, -1], &[1, 0, -1, -2, -1]),
(&[-1, -1, -1], &[-1, -1, -1, -1], &[1, 0, 0, -1, -2, -1, -1]),
@ -2338,8 +2339,8 @@ mod biguint_tests {
&'static [BigDigit])]
= &[
(&[ 1], &[ 2], &[], &[1]),
(&[ 1, 1], &[ 2], &[-1/2+1], &[1]),
(&[ 1, 1, 1], &[ 2], &[-1/2+1, -1/2+1], &[1]),
(&[ 1, 1], &[ 2], &[ M/2+1], &[1]),
(&[ 1, 1, 1], &[ 2], &[ M/2+1, M/2+1], &[1]),
(&[ 0, 1], &[-1], &[1], &[1]),
(&[-1, -1], &[-2], &[2, 1], &[3])
];
@ -2980,6 +2981,7 @@ mod bigint_tests {
}
}
const M: u32 = ::std::u32::MAX;
static MUL_TRIPLES: &'static [(&'static [BigDigit],
&'static [BigDigit],
&'static [BigDigit])] = &[
@ -2997,8 +2999,8 @@ mod bigint_tests {
(&[-1, -1], &[-1], &[ 1, -1, -2]),
(&[-1, -1, -1], &[-1], &[ 1, -1, -1, -2]),
(&[-1, -1, -1, -1], &[-1], &[ 1, -1, -1, -1, -2]),
(&[-1/2 + 1], &[ 2], &[ 0, 1]),
(&[0, -1/2 + 1], &[ 2], &[ 0, 0, 1]),
(&[ M/2 + 1], &[ 2], &[ 0, 1]),
(&[0, M/2 + 1], &[ 2], &[ 0, 0, 1]),
(&[ 1, 2], &[ 1, 2, 3], &[1, 4, 7, 6]),
(&[-1, -1], &[-1, -1, -1], &[1, 0, -1, -2, -1]),
(&[-1, -1, -1], &[-1, -1, -1, -1], &[1, 0, 0, -1, -2, -1, -1]),
@ -3012,8 +3014,8 @@ mod bigint_tests {
&'static [BigDigit])]
= &[
(&[ 1], &[ 2], &[], &[1]),
(&[ 1, 1], &[ 2], &[-1/2+1], &[1]),
(&[ 1, 1, 1], &[ 2], &[-1/2+1, -1/2+1], &[1]),
(&[ 1, 1], &[ 2], &[ M/2+1], &[1]),
(&[ 1, 1, 1], &[ 2], &[ M/2+1, M/2+1], &[1]),
(&[ 0, 1], &[-1], &[1], &[1]),
(&[-1, -1], &[-2], &[2, 1], &[3])
];

View File

@ -424,7 +424,7 @@ impl<T: FromStr + Clone + Integer + PartialOrd>
/// Parses `numer/denom` or just `numer`.
fn from_str(s: &str) -> Result<Ratio<T>, ParseRatioError> {
let mut split = s.splitn(1, '/');
let mut split = s.splitn(2, '/');
let n = try!(split.next().ok_or(ParseRatioError));
let num = try!(FromStr::from_str(n).map_err(|_| ParseRatioError));
@ -442,7 +442,7 @@ impl<T: FromStrRadix + Clone + Integer + PartialOrd>
/// Parses `numer/denom` where the numbers are in base `radix`.
fn from_str_radix(s: &str, radix: u32) -> Result<Ratio<T>, ParseRatioError> {
let split: Vec<&str> = s.splitn(1, '/').collect();
let split: Vec<&str> = s.splitn(2, '/').collect();
if split.len() < 2 {
Err(ParseRatioError)
} else {