Skip to content

Commit fc41ba1

Browse files
committed
bigint: un-ignore test_shr
1 parent 17c8f8b commit fc41ba1

File tree

1 file changed

+68
-73
lines changed

1 file changed

+68
-73
lines changed

src/libextra/num/bigint.rs

+68-73
Original file line numberDiff line numberDiff line change
@@ -1167,83 +1167,78 @@ mod biguint_tests {
11671167
11681168
#[test]
11691169
fn test_shl() {
1170-
fn check(v: ~[BigDigit], shift: uint, ans: ~[BigDigit]) {
1171-
assert_eq!(BigUint::new(v) << shift, BigUint::new(ans));
1172-
}
1173-
1174-
check(~[], 3, ~[]);
1175-
check(~[1, 1, 1], 3, ~[1 << 3, 1 << 3, 1 << 3]);
1176-
check(~[1 << (BigDigit::bits - 2)], 2, ~[0, 1]);
1177-
check(~[1 << (BigDigit::bits - 2)], 3, ~[0, 2]);
1178-
check(~[1 << (BigDigit::bits - 2)], 3 + BigDigit::bits, ~[0, 0, 2]);
1179-
1180-
test_shl_bits();
1181-
1182-
#[cfg(target_word_size = "64")]
1183-
fn test_shl_bits() {
1184-
check(~[0x7654_3210, 0xfedc_ba98,
1185-
0x7654_3210, 0xfedc_ba98], 4,
1186-
~[0x6543_2100, 0xedcb_a987,
1187-
0x6543_210f, 0xedcb_a987, 0xf]);
1188-
check(~[0x2222_1111, 0x4444_3333,
1189-
0x6666_5555, 0x8888_7777], 16,
1190-
~[0x1111_0000, 0x3333_2222,
1191-
0x5555_4444, 0x7777_6666, 0x8888]);
1192-
}
1193-
1194-
#[cfg(target_word_size = "32")]
1195-
fn test_shl_bits() {
1196-
check(~[0x3210, 0x7654, 0xba98, 0xfedc,
1197-
0x3210, 0x7654, 0xba98, 0xfedc], 4,
1198-
~[0x2100, 0x6543, 0xa987, 0xedcb,
1199-
0x210f, 0x6543, 0xa987, 0xedcb, 0xf]);
1200-
check(~[0x1111, 0x2222, 0x3333, 0x4444,
1201-
0x5555, 0x6666, 0x7777, 0x8888], 16,
1202-
~[0x0000, 0x1111, 0x2222, 0x3333,
1203-
0x4444, 0x5555, 0x6666, 0x7777, 0x8888]);
1204-
}
1205-
1170+
fn check(s: &str, shift: uint, ans: &str) {
1171+
let bu = (FromStrRadix::from_str_radix::<BigUint>(s, 16).unwrap() << shift)
1172+
.to_str_radix(16);
1173+
assert_eq!(bu.as_slice(), ans);
1174+
}
1175+
1176+
check("0", 3, "0");
1177+
check("1", 3, "8");
1178+
1179+
check("1" + "0000" + "0000" + "0000" + "0001" + "0000" + "0000" + "0000" + "0001", 3,
1180+
"8" + "0000" + "0000" + "0000" + "0008" + "0000" + "0000" + "0000" + "0008");
1181+
check("1" + "0000" + "0001" + "0000" + "0001", 2,
1182+
"4" + "0000" + "0004" + "0000" + "0004");
1183+
check("1" + "0001" + "0001", 1,
1184+
"2" + "0002" + "0002");
1185+
1186+
check("" + "4000" + "0000" + "0000" + "0000", 3,
1187+
"2" + "0000" + "0000" + "0000" + "0000");
1188+
check("" + "4000" + "0000", 2,
1189+
"1" + "0000" + "0000");
1190+
check("" + "4000", 2,
1191+
"1" + "0000");
1192+
1193+
check("" + "4000" + "0000" + "0000" + "0000", 67,
1194+
"2" + "0000" + "0000" + "0000" + "0000" + "0000" + "0000" + "0000" + "0000");
1195+
check("" + "4000" + "0000", 35,
1196+
"2" + "0000" + "0000" + "0000" + "0000");
1197+
check("" + "4000", 19,
1198+
"2" + "0000" + "0000");
1199+
1200+
check("" + "fedc" + "ba98" + "7654" + "3210" + "fedc" + "ba98" + "7654" + "3210", 4,
1201+
"f" + "edcb" + "a987" + "6543" + "210f" + "edcb" + "a987" + "6543" + "2100");
1202+
check("88887777666655554444333322221111", 16,
1203+
"888877776666555544443333222211110000");
12061204
}
12071205

12081206
#[test]
1209-
#[ignore(cfg(target_word_size = "32"))]
12101207
fn test_shr() {
1211-
fn check(v: ~[BigDigit], shift: uint, ans: ~[BigDigit]) {
1212-
assert_eq!(BigUint::new(v) >> shift, BigUint::new(ans));
1213-
}
1214-
1215-
check(~[], 3, ~[]);
1216-
check(~[1, 1, 1], 3,
1217-
~[1 << (BigDigit::bits - 3), 1 << (BigDigit::bits - 3)]);
1218-
check(~[1 << 2], 2, ~[1]);
1219-
check(~[1, 2], 3, ~[1 << (BigDigit::bits - 2)]);
1220-
check(~[1, 1, 2], 3 + BigDigit::bits, ~[1 << (BigDigit::bits - 2)]);
1221-
check(~[0, 1], 1, ~[0x80000000]);
1222-
test_shr_bits();
1223-
1224-
#[cfg(target_word_size = "64")]
1225-
fn test_shr_bits() {
1226-
check(~[0x6543_2100, 0xedcb_a987,
1227-
0x6543_210f, 0xedcb_a987, 0xf], 4,
1228-
~[0x7654_3210, 0xfedc_ba98,
1229-
0x7654_3210, 0xfedc_ba98]);
1230-
check(~[0x1111_0000, 0x3333_2222,
1231-
0x5555_4444, 0x7777_6666, 0x8888], 16,
1232-
~[0x2222_1111, 0x4444_3333,
1233-
0x6666_5555, 0x8888_7777]);
1234-
}
1235-
1236-
#[cfg(target_word_size = "32")]
1237-
fn test_shr_bits() {
1238-
check(~[0x2100, 0x6543, 0xa987, 0xedcb,
1239-
0x210f, 0x6543, 0xa987, 0xedcb, 0xf], 4,
1240-
~[0x3210, 0x7654, 0xba98, 0xfedc,
1241-
0x3210, 0x7654, 0xba98, 0xfedc]);
1242-
check(~[0x0000, 0x1111, 0x2222, 0x3333,
1243-
0x4444, 0x5555, 0x6666, 0x7777, 0x8888], 16,
1244-
~[0x1111, 0x2222, 0x3333, 0x4444,
1245-
0x5555, 0x6666, 0x7777, 0x8888]);
1246-
}
1208+
fn check(s: &str, shift: uint, ans: &str) {
1209+
let bu = (FromStrRadix::from_str_radix::<BigUint>(s, 16).unwrap() >> shift)
1210+
.to_str_radix(16);
1211+
assert_eq!(bu.as_slice(), ans);
1212+
}
1213+
1214+
check("0", 3, "0");
1215+
check("f", 3, "1");
1216+
1217+
check("1" + "0000" + "0000" + "0000" + "0001" + "0000" + "0000" + "0000" + "0001", 3,
1218+
"" + "2000" + "0000" + "0000" + "0000" + "2000" + "0000" + "0000" + "0000");
1219+
check("1" + "0000" + "0001" + "0000" + "0001", 2,
1220+
"" + "4000" + "0000" + "4000" + "0000");
1221+
check("1" + "0001" + "0001", 1,
1222+
"" + "8000" + "8000");
1223+
1224+
check("2" + "0000" + "0000" + "0000" + "0001" + "0000" + "0000" + "0000" + "0001", 67,
1225+
"" + "4000" + "0000" + "0000" + "0000");
1226+
check("2" + "0000" + "0001" + "0000" + "0001", 35,
1227+
"" + "4000" + "0000");
1228+
check("2" + "0001" + "0001", 19,
1229+
"" + "4000");
1230+
1231+
check("1" + "0000" + "0000" + "0000" + "0000", 1,
1232+
"" + "8000" + "0000" + "0000" + "0000");
1233+
check("1" + "0000" + "0000", 1,
1234+
"" + "8000" + "0000");
1235+
check("1" + "0000", 1,
1236+
"" + "8000");
1237+
check("f" + "edcb" + "a987" + "6543" + "210f" + "edcb" + "a987" + "6543" + "2100", 4,
1238+
"" + "fedc" + "ba98" + "7654" + "3210" + "fedc" + "ba98" + "7654" + "3210");
1239+
1240+
check("888877776666555544443333222211110000", 16,
1241+
"88887777666655554444333322221111");
12471242
}
12481243

12491244
#[test]

0 commit comments

Comments
 (0)