libstd: Fix BigUint::is_even
This commit is contained in:
parent
9ee8d506d9
commit
a2b81ccba4
@ -447,7 +447,7 @@ impl Integer for BigUint {
|
||||
if self.data.is_empty() {
|
||||
true
|
||||
} else {
|
||||
self.data.last().is_even()
|
||||
self.data[0].is_even()
|
||||
}
|
||||
}
|
||||
|
||||
@ -1448,6 +1448,17 @@ mod biguint_tests {
|
||||
check(99, 17, 1683);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_even() {
|
||||
assert!(FromStr::from_str::<BigUint>("1").get().is_odd());
|
||||
assert!(FromStr::from_str::<BigUint>("2").get().is_even());
|
||||
assert!(FromStr::from_str::<BigUint>("1000").get().is_even());
|
||||
assert!(FromStr::from_str::<BigUint>("1000000000000000000000").get().is_even());
|
||||
assert!(FromStr::from_str::<BigUint>("1000000000000000000001").get().is_odd());
|
||||
assert!((BigUint::from_uint(1) << 64).is_even());
|
||||
assert!(((BigUint::from_uint(1) << 64) + BigUint::from_uint(1)).is_odd());
|
||||
}
|
||||
|
||||
fn to_str_pairs() -> ~[ (BigUint, ~[(uint, ~str)]) ] {
|
||||
let bits = BigDigit::bits;
|
||||
~[( Zero::zero(), ~[
|
||||
|
Loading…
Reference in New Issue
Block a user