diff --git a/src/bigint.rs b/src/bigint.rs index fd90ab2..bfc74a0 100644 --- a/src/bigint.rs +++ b/src/bigint.rs @@ -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]) ]; diff --git a/src/rational.rs b/src/rational.rs index 85f1484..753bde1 100644 --- a/src/rational.rs +++ b/src/rational.rs @@ -424,7 +424,7 @@ impl /// Parses `numer/denom` or just `numer`. fn from_str(s: &str) -> Result, 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 /// Parses `numer/denom` where the numbers are in base `radix`. fn from_str_radix(s: &str, radix: u32) -> Result, ParseRatioError> { - let split: Vec<&str> = s.splitn(1, '/').collect(); + let split: Vec<&str> = s.splitn(2, '/').collect(); if split.len() < 2 { Err(ParseRatioError) } else {