bigint: un-ignore test_shr
This commit is contained in:
parent
17c8f8bd0c
commit
fc41ba167c
@ -1167,83 +1167,78 @@ mod biguint_tests {
|
||||
|
||||
#[test]
|
||||
fn test_shl() {
|
||||
fn check(v: ~[BigDigit], shift: uint, ans: ~[BigDigit]) {
|
||||
assert_eq!(BigUint::new(v) << shift, BigUint::new(ans));
|
||||
fn check(s: &str, shift: uint, ans: &str) {
|
||||
let bu = (FromStrRadix::from_str_radix::<BigUint>(s, 16).unwrap() << shift)
|
||||
.to_str_radix(16);
|
||||
assert_eq!(bu.as_slice(), ans);
|
||||
}
|
||||
|
||||
check(~[], 3, ~[]);
|
||||
check(~[1, 1, 1], 3, ~[1 << 3, 1 << 3, 1 << 3]);
|
||||
check(~[1 << (BigDigit::bits - 2)], 2, ~[0, 1]);
|
||||
check(~[1 << (BigDigit::bits - 2)], 3, ~[0, 2]);
|
||||
check(~[1 << (BigDigit::bits - 2)], 3 + BigDigit::bits, ~[0, 0, 2]);
|
||||
check("0", 3, "0");
|
||||
check("1", 3, "8");
|
||||
|
||||
test_shl_bits();
|
||||
check("1" + "0000" + "0000" + "0000" + "0001" + "0000" + "0000" + "0000" + "0001", 3,
|
||||
"8" + "0000" + "0000" + "0000" + "0008" + "0000" + "0000" + "0000" + "0008");
|
||||
check("1" + "0000" + "0001" + "0000" + "0001", 2,
|
||||
"4" + "0000" + "0004" + "0000" + "0004");
|
||||
check("1" + "0001" + "0001", 1,
|
||||
"2" + "0002" + "0002");
|
||||
|
||||
#[cfg(target_word_size = "64")]
|
||||
fn test_shl_bits() {
|
||||
check(~[0x7654_3210, 0xfedc_ba98,
|
||||
0x7654_3210, 0xfedc_ba98], 4,
|
||||
~[0x6543_2100, 0xedcb_a987,
|
||||
0x6543_210f, 0xedcb_a987, 0xf]);
|
||||
check(~[0x2222_1111, 0x4444_3333,
|
||||
0x6666_5555, 0x8888_7777], 16,
|
||||
~[0x1111_0000, 0x3333_2222,
|
||||
0x5555_4444, 0x7777_6666, 0x8888]);
|
||||
}
|
||||
check("" + "4000" + "0000" + "0000" + "0000", 3,
|
||||
"2" + "0000" + "0000" + "0000" + "0000");
|
||||
check("" + "4000" + "0000", 2,
|
||||
"1" + "0000" + "0000");
|
||||
check("" + "4000", 2,
|
||||
"1" + "0000");
|
||||
|
||||
#[cfg(target_word_size = "32")]
|
||||
fn test_shl_bits() {
|
||||
check(~[0x3210, 0x7654, 0xba98, 0xfedc,
|
||||
0x3210, 0x7654, 0xba98, 0xfedc], 4,
|
||||
~[0x2100, 0x6543, 0xa987, 0xedcb,
|
||||
0x210f, 0x6543, 0xa987, 0xedcb, 0xf]);
|
||||
check(~[0x1111, 0x2222, 0x3333, 0x4444,
|
||||
0x5555, 0x6666, 0x7777, 0x8888], 16,
|
||||
~[0x0000, 0x1111, 0x2222, 0x3333,
|
||||
0x4444, 0x5555, 0x6666, 0x7777, 0x8888]);
|
||||
}
|
||||
check("" + "4000" + "0000" + "0000" + "0000", 67,
|
||||
"2" + "0000" + "0000" + "0000" + "0000" + "0000" + "0000" + "0000" + "0000");
|
||||
check("" + "4000" + "0000", 35,
|
||||
"2" + "0000" + "0000" + "0000" + "0000");
|
||||
check("" + "4000", 19,
|
||||
"2" + "0000" + "0000");
|
||||
|
||||
check("" + "fedc" + "ba98" + "7654" + "3210" + "fedc" + "ba98" + "7654" + "3210", 4,
|
||||
"f" + "edcb" + "a987" + "6543" + "210f" + "edcb" + "a987" + "6543" + "2100");
|
||||
check("88887777666655554444333322221111", 16,
|
||||
"888877776666555544443333222211110000");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore(cfg(target_word_size = "32"))]
|
||||
fn test_shr() {
|
||||
fn check(v: ~[BigDigit], shift: uint, ans: ~[BigDigit]) {
|
||||
assert_eq!(BigUint::new(v) >> shift, BigUint::new(ans));
|
||||
fn check(s: &str, shift: uint, ans: &str) {
|
||||
let bu = (FromStrRadix::from_str_radix::<BigUint>(s, 16).unwrap() >> shift)
|
||||
.to_str_radix(16);
|
||||
assert_eq!(bu.as_slice(), ans);
|
||||
}
|
||||
|
||||
check(~[], 3, ~[]);
|
||||
check(~[1, 1, 1], 3,
|
||||
~[1 << (BigDigit::bits - 3), 1 << (BigDigit::bits - 3)]);
|
||||
check(~[1 << 2], 2, ~[1]);
|
||||
check(~[1, 2], 3, ~[1 << (BigDigit::bits - 2)]);
|
||||
check(~[1, 1, 2], 3 + BigDigit::bits, ~[1 << (BigDigit::bits - 2)]);
|
||||
check(~[0, 1], 1, ~[0x80000000]);
|
||||
test_shr_bits();
|
||||
check("0", 3, "0");
|
||||
check("f", 3, "1");
|
||||
|
||||
#[cfg(target_word_size = "64")]
|
||||
fn test_shr_bits() {
|
||||
check(~[0x6543_2100, 0xedcb_a987,
|
||||
0x6543_210f, 0xedcb_a987, 0xf], 4,
|
||||
~[0x7654_3210, 0xfedc_ba98,
|
||||
0x7654_3210, 0xfedc_ba98]);
|
||||
check(~[0x1111_0000, 0x3333_2222,
|
||||
0x5555_4444, 0x7777_6666, 0x8888], 16,
|
||||
~[0x2222_1111, 0x4444_3333,
|
||||
0x6666_5555, 0x8888_7777]);
|
||||
}
|
||||
check("1" + "0000" + "0000" + "0000" + "0001" + "0000" + "0000" + "0000" + "0001", 3,
|
||||
"" + "2000" + "0000" + "0000" + "0000" + "2000" + "0000" + "0000" + "0000");
|
||||
check("1" + "0000" + "0001" + "0000" + "0001", 2,
|
||||
"" + "4000" + "0000" + "4000" + "0000");
|
||||
check("1" + "0001" + "0001", 1,
|
||||
"" + "8000" + "8000");
|
||||
|
||||
#[cfg(target_word_size = "32")]
|
||||
fn test_shr_bits() {
|
||||
check(~[0x2100, 0x6543, 0xa987, 0xedcb,
|
||||
0x210f, 0x6543, 0xa987, 0xedcb, 0xf], 4,
|
||||
~[0x3210, 0x7654, 0xba98, 0xfedc,
|
||||
0x3210, 0x7654, 0xba98, 0xfedc]);
|
||||
check(~[0x0000, 0x1111, 0x2222, 0x3333,
|
||||
0x4444, 0x5555, 0x6666, 0x7777, 0x8888], 16,
|
||||
~[0x1111, 0x2222, 0x3333, 0x4444,
|
||||
0x5555, 0x6666, 0x7777, 0x8888]);
|
||||
}
|
||||
check("2" + "0000" + "0000" + "0000" + "0001" + "0000" + "0000" + "0000" + "0001", 67,
|
||||
"" + "4000" + "0000" + "0000" + "0000");
|
||||
check("2" + "0000" + "0001" + "0000" + "0001", 35,
|
||||
"" + "4000" + "0000");
|
||||
check("2" + "0001" + "0001", 19,
|
||||
"" + "4000");
|
||||
|
||||
check("1" + "0000" + "0000" + "0000" + "0000", 1,
|
||||
"" + "8000" + "0000" + "0000" + "0000");
|
||||
check("1" + "0000" + "0000", 1,
|
||||
"" + "8000" + "0000");
|
||||
check("1" + "0000", 1,
|
||||
"" + "8000");
|
||||
check("f" + "edcb" + "a987" + "6543" + "210f" + "edcb" + "a987" + "6543" + "2100", 4,
|
||||
"" + "fedc" + "ba98" + "7654" + "3210" + "fedc" + "ba98" + "7654" + "3210");
|
||||
|
||||
check("888877776666555544443333222211110000", 16,
|
||||
"88887777666655554444333322221111");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
x
Reference in New Issue
Block a user