From a2b81ccba45fc2dbeee83815f5463e48f29c7569 Mon Sep 17 00:00:00 2001 From: gifnksm Date: Sun, 12 May 2013 10:15:14 +0900 Subject: [PATCH] libstd: Fix BigUint::is_even --- src/libstd/num/bigint.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/libstd/num/bigint.rs b/src/libstd/num/bigint.rs index e64e97adfa3..0f3a6f63c47 100644 --- a/src/libstd/num/bigint.rs +++ b/src/libstd/num/bigint.rs @@ -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::("1").get().is_odd()); + assert!(FromStr::from_str::("2").get().is_even()); + assert!(FromStr::from_str::("1000").get().is_even()); + assert!(FromStr::from_str::("1000000000000000000000").get().is_even()); + assert!(FromStr::from_str::("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(), ~[