Skip to content

Commit 36771ef

Browse files
committed
auto merge of #6429 : gifnksm/rust/bigint-is_even, r=catamorphism
`BigUint::is_even()` didn't return correct value.
2 parents 1f62b23 + a2b81cc commit 36771ef

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/libstd/num/bigint.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ impl Integer for BigUint {
445445
if self.data.is_empty() {
446446
true
447447
} else {
448-
self.data.last().is_even()
448+
self.data[0].is_even()
449449
}
450450
}
451451

@@ -1446,6 +1446,17 @@ mod biguint_tests {
14461446
check(99, 17, 1683);
14471447
}
14481448

1449+
#[test]
1450+
fn test_is_even() {
1451+
assert!(FromStr::from_str::<BigUint>("1").get().is_odd());
1452+
assert!(FromStr::from_str::<BigUint>("2").get().is_even());
1453+
assert!(FromStr::from_str::<BigUint>("1000").get().is_even());
1454+
assert!(FromStr::from_str::<BigUint>("1000000000000000000000").get().is_even());
1455+
assert!(FromStr::from_str::<BigUint>("1000000000000000000001").get().is_odd());
1456+
assert!((BigUint::from_uint(1) << 64).is_even());
1457+
assert!(((BigUint::from_uint(1) << 64) + BigUint::from_uint(1)).is_odd());
1458+
}
1459+
14491460
fn to_str_pairs() -> ~[ (BigUint, ~[(uint, ~str)]) ] {
14501461
let bits = BigDigit::bits;
14511462
~[( Zero::zero(), ~[

0 commit comments

Comments
 (0)