mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-21 19:33:16 +00:00
libnum: Remove all uses of ~str
from libnum
This commit is contained in:
parent
1ef8246946
commit
351a564df5
@ -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!()
|
||||
}),
|
||||
(16,
|
||||
"2".to_owned() +
|
||||
"0".repeat(bits / 4 - 1) + "1")
|
||||
)), ( BigUint::from_slice([ 1, 2, 3 ]), vec!(
|
||||
(2,
|
||||
"11".to_owned() +
|
||||
"0".repeat(bits - 2) + "10" +
|
||||
"0".repeat(bits - 1) + "1"),
|
||||
(4,
|
||||
"3".to_owned() +
|
||||
"0".repeat(bits / 2 - 1) + "2" +
|
||||
"0".repeat(bits / 2 - 1) + "1"),
|
||||
(10, match bits {
|
||||
32 => "55340232229718589441".to_owned(),
|
||||
16 => "12885032961".to_owned(),
|
||||
32 => "8589934593".to_strbuf(),
|
||||
16 => "131073".to_strbuf(),
|
||||
_ => fail!()
|
||||
}),
|
||||
(16, "3".to_owned() +
|
||||
"0".repeat(bits / 4 - 1) + "2" +
|
||||
"0".repeat(bits / 4 - 1) + "1")
|
||||
(16,
|
||||
format_strbuf!("2{}1", "0".repeat(bits / 4 - 1)))
|
||||
)), ( BigUint::from_slice([ 1, 2, 3 ]), vec!(
|
||||
(2,
|
||||
format_strbuf!("11{}10{}1",
|
||||
"0".repeat(bits - 2),
|
||||
"0".repeat(bits - 1))),
|
||||
(4,
|
||||
format_strbuf!("3{}2{}1",
|
||||
"0".repeat(bits / 2 - 1),
|
||||
"0".repeat(bits / 2 - 1))),
|
||||
(10, match bits {
|
||||
32 => "55340232229718589441".to_strbuf(),
|
||||
16 => "12885032961".to_strbuf(),
|
||||
_ => fail!()
|
||||
}),
|
||||
(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());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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) }
|
||||
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_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());
|
||||
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_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());
|
||||
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]
|
||||
|
Loading…
Reference in New Issue
Block a user