diff options
| author | bors <bors@rust-lang.org> | 2014-05-14 19:31:52 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-05-14 19:31:52 -0700 |
| commit | e10fd317211511c3fb4656aee10eb4fd17dc8586 (patch) | |
| tree | 751c444f333d465d11aa20ae6bbd377755bf8aa3 /src/libnum | |
| parent | 2a7a39191a83fc2a63df6cb47acd344ae669d9c7 (diff) | |
| parent | 351a564df5d62175696a1f87c40629f212f1ee1e (diff) | |
| download | rust-e10fd317211511c3fb4656aee10eb4fd17dc8586.tar.gz rust-e10fd317211511c3fb4656aee10eb4fd17dc8586.zip | |
auto merge of #14170 : pcwalton/rust/detildestr-misclibs, r=alexcrichton
r? @brson
Diffstat (limited to 'src/libnum')
| -rw-r--r-- | src/libnum/bigint.rs | 83 | ||||
| -rw-r--r-- | src/libnum/complex.rs | 18 | ||||
| -rw-r--r-- | src/libnum/rational.rs | 65 |
3 files changed, 85 insertions, 81 deletions
diff --git a/src/libnum/bigint.rs b/src/libnum/bigint.rs index ac8da664de7..9f66f767f20 100644 --- a/src/libnum/bigint.rs +++ b/src/libnum/bigint.rs @@ -1865,60 +1865,60 @@ mod biguint_tests { assert!(((one << 64) + one).is_odd()); } - fn to_str_pairs() -> Vec<(BigUint, Vec<(uint, ~str)>)> { + fn to_str_pairs() -> Vec<(BigUint, Vec<(uint, StrBuf)>)> { let bits = BigDigit::bits; vec!(( Zero::zero(), vec!( - (2, "0".to_owned()), (3, "0".to_owned()) + (2, "0".to_strbuf()), (3, "0".to_strbuf()) )), ( BigUint::from_slice([ 0xff ]), vec!( - (2, "11111111".to_owned()), - (3, "100110".to_owned()), - (4, "3333".to_owned()), - (5, "2010".to_owned()), - (6, "1103".to_owned()), - (7, "513".to_owned()), - (8, "377".to_owned()), - (9, "313".to_owned()), - (10, "255".to_owned()), - (11, "212".to_owned()), - (12, "193".to_owned()), - (13, "168".to_owned()), - (14, "143".to_owned()), - (15, "120".to_owned()), - (16, "ff".to_owned()) + (2, "11111111".to_strbuf()), + (3, "100110".to_strbuf()), + (4, "3333".to_strbuf()), + (5, "2010".to_strbuf()), + (6, "1103".to_strbuf()), + (7, "513".to_strbuf()), + (8, "377".to_strbuf()), + (9, "313".to_strbuf()), + (10, "255".to_strbuf()), + (11, "212".to_strbuf()), + (12, "193".to_strbuf()), + (13, "168".to_strbuf()), + (14, "143".to_strbuf()), + (15, "120".to_strbuf()), + (16, "ff".to_strbuf()) )), ( BigUint::from_slice([ 0xfff ]), vec!( - (2, "111111111111".to_owned()), - (4, "333333".to_owned()), - (16, "fff".to_owned()) + (2, "111111111111".to_strbuf()), + (4, "333333".to_strbuf()), + (16, "fff".to_strbuf()) )), ( BigUint::from_slice([ 1, 2 ]), vec!( (2, - "10".to_owned() + - "0".repeat(bits - 1) + "1"), + format_strbuf!("10{}1", "0".repeat(bits - 1))), (4, - "2".to_owned() + - "0".repeat(bits / 2 - 1) + "1"), + format_strbuf!("2{}1", "0".repeat(bits / 2 - 1))), (10, match bits { - 32 => "8589934593".to_owned(), 16 => "131073".to_owned(), _ => fail!() + 32 => "8589934593".to_strbuf(), + 16 => "131073".to_strbuf(), + _ => fail!() }), (16, - "2".to_owned() + - "0".repeat(bits / 4 - 1) + "1") + format_strbuf!("2{}1", "0".repeat(bits / 4 - 1))) )), ( BigUint::from_slice([ 1, 2, 3 ]), vec!( (2, - "11".to_owned() + - "0".repeat(bits - 2) + "10" + - "0".repeat(bits - 1) + "1"), + format_strbuf!("11{}10{}1", + "0".repeat(bits - 2), + "0".repeat(bits - 1))), (4, - "3".to_owned() + - "0".repeat(bits / 2 - 1) + "2" + - "0".repeat(bits / 2 - 1) + "1"), + format_strbuf!("3{}2{}1", + "0".repeat(bits / 2 - 1), + "0".repeat(bits / 2 - 1))), (10, match bits { - 32 => "55340232229718589441".to_owned(), - 16 => "12885032961".to_owned(), + 32 => "55340232229718589441".to_strbuf(), + 16 => "12885032961".to_strbuf(), _ => fail!() }), - (16, "3".to_owned() + - "0".repeat(bits / 4 - 1) + "2" + - "0".repeat(bits / 4 - 1) + "1") + (16, + format_strbuf!("3{}2{}1", + "0".repeat(bits / 4 - 1), + "0".repeat(bits / 4 - 1))) )) ) } @@ -1929,7 +1929,8 @@ mod biguint_tests { let &(ref n, ref rs) = num_pair; for str_pair in rs.iter() { let &(ref radix, ref str) = str_pair; - assert_eq!(&n.to_str_radix(*radix), str); + assert_eq!(n.to_str_radix(*radix).as_slice(), + str.as_slice()); } } } @@ -1941,7 +1942,9 @@ mod biguint_tests { let &(ref n, ref rs) = num_pair; for str_pair in rs.iter() { let &(ref radix, ref str) = str_pair; - assert_eq!(n, &FromStrRadix::from_str_radix(*str, *radix).unwrap()); + assert_eq!(n, + &FromStrRadix::from_str_radix(str.as_slice(), + *radix).unwrap()); } } diff --git a/src/libnum/complex.rs b/src/libnum/complex.rs index 3a666273d4a..b82c4d177ba 100644 --- a/src/libnum/complex.rs +++ b/src/libnum/complex.rs @@ -348,15 +348,15 @@ mod test { #[test] fn test_to_str() { - fn test(c : Complex64, s: ~str) { - assert_eq!(c.to_str(), s); + fn test(c : Complex64, s: StrBuf) { + assert_eq!(c.to_str().to_strbuf(), s); } - test(_0_0i, "0+0i".to_owned()); - test(_1_0i, "1+0i".to_owned()); - test(_0_1i, "0+1i".to_owned()); - test(_1_1i, "1+1i".to_owned()); - test(_neg1_1i, "-1+1i".to_owned()); - test(-_neg1_1i, "1-1i".to_owned()); - test(_05_05i, "0.5+0.5i".to_owned()); + test(_0_0i, "0+0i".to_strbuf()); + test(_1_0i, "1+0i".to_strbuf()); + test(_0_1i, "0+1i".to_strbuf()); + test(_1_1i, "1+1i".to_strbuf()); + test(_neg1_1i, "-1+1i".to_strbuf()); + test(-_neg1_1i, "1-1i".to_strbuf()); + test(_05_05i, "0.5+0.5i".to_strbuf()); } } diff --git a/src/libnum/rational.rs b/src/libnum/rational.rs index 825890e5619..bffca79f351 100644 --- a/src/libnum/rational.rs +++ b/src/libnum/rational.rs @@ -555,16 +555,16 @@ mod test { #[test] fn test_to_from_str() { - fn test(r: Rational, s: ~str) { - assert_eq!(FromStr::from_str(s), Some(r)); - assert_eq!(r.to_str(), s); + fn test(r: Rational, s: StrBuf) { + assert_eq!(FromStr::from_str(s.as_slice()), Some(r)); + assert_eq!(r.to_str().to_strbuf(), s); } - test(_1, "1/1".to_owned()); - test(_0, "0/1".to_owned()); - test(_1_2, "1/2".to_owned()); - test(_3_2, "3/2".to_owned()); - test(_2, "2/1".to_owned()); - test(_neg1_2, "-1/2".to_owned()); + test(_1, "1/1".to_strbuf()); + test(_0, "0/1".to_strbuf()); + test(_1_2, "1/2".to_strbuf()); + test(_3_2, "3/2".to_strbuf()); + test(_2, "2/1".to_strbuf()); + test(_neg1_2, "-1/2".to_strbuf()); } #[test] fn test_from_str_fail() { @@ -581,30 +581,31 @@ mod test { #[test] fn test_to_from_str_radix() { - fn test(r: Rational, s: ~str, n: uint) { - assert_eq!(FromStrRadix::from_str_radix(s, n), Some(r)); - assert_eq!(r.to_str_radix(n), s); + fn test(r: Rational, s: StrBuf, n: uint) { + assert_eq!(FromStrRadix::from_str_radix(s.to_owned(), n), + Some(r)); + assert_eq!(r.to_str_radix(n).to_strbuf(), s); } - fn test3(r: Rational, s: ~str) { test(r, s, 3) } - fn test16(r: Rational, s: ~str) { test(r, s, 16) } - - test3(_1, "1/1".to_owned()); - test3(_0, "0/1".to_owned()); - test3(_1_2, "1/2".to_owned()); - test3(_3_2, "10/2".to_owned()); - test3(_2, "2/1".to_owned()); - test3(_neg1_2, "-1/2".to_owned()); - test3(_neg1_2 / _2, "-1/11".to_owned()); - - test16(_1, "1/1".to_owned()); - test16(_0, "0/1".to_owned()); - test16(_1_2, "1/2".to_owned()); - test16(_3_2, "3/2".to_owned()); - test16(_2, "2/1".to_owned()); - test16(_neg1_2, "-1/2".to_owned()); - test16(_neg1_2 / _2, "-1/4".to_owned()); - test16(Ratio::new(13,15), "d/f".to_owned()); - test16(_1_2*_1_2*_1_2*_1_2, "1/10".to_owned()); + fn test3(r: Rational, s: StrBuf) { test(r, s, 3) } + fn test16(r: Rational, s: StrBuf) { test(r, s, 16) } + + test3(_1, "1/1".to_strbuf()); + test3(_0, "0/1".to_strbuf()); + test3(_1_2, "1/2".to_strbuf()); + test3(_3_2, "10/2".to_strbuf()); + test3(_2, "2/1".to_strbuf()); + test3(_neg1_2, "-1/2".to_strbuf()); + test3(_neg1_2 / _2, "-1/11".to_strbuf()); + + test16(_1, "1/1".to_strbuf()); + test16(_0, "0/1".to_strbuf()); + test16(_1_2, "1/2".to_strbuf()); + test16(_3_2, "3/2".to_strbuf()); + test16(_2, "2/1".to_strbuf()); + test16(_neg1_2, "-1/2".to_strbuf()); + test16(_neg1_2 / _2, "-1/4".to_strbuf()); + test16(Ratio::new(13,15), "d/f".to_strbuf()); + test16(_1_2*_1_2*_1_2*_1_2, "1/10".to_strbuf()); } #[test] |
