From 18fadb61c4aab3d1b2fc49ac7d7fea85b3914fb3 Mon Sep 17 00:00:00 2001 From: Irfan Hudda Date: Wed, 31 May 2017 22:25:15 +0530 Subject: Simplify helper functions Based on @scottmcm 's suggestion --- src/libstd/num.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/libstd') diff --git a/src/libstd/num.rs b/src/libstd/num.rs index 5f83d077a13..894a6e6796c 100644 --- a/src/libstd/num.rs +++ b/src/libstd/num.rs @@ -176,7 +176,10 @@ mod tests { fn $test_name() { #![test] assert_eq!((0 as $T).checked_next_power_of_two(), Some(1)); - assert!(($T::MAX / 2).checked_next_power_of_two().is_some()); + let smax = $T::MAX >> 1; + assert_eq!(smax.checked_next_power_of_two(), Some(smax+1)); + assert_eq!((smax + 1).checked_next_power_of_two(), Some(smax + 1)); + assert_eq!((smax + 2).checked_next_power_of_two(), None); assert_eq!(($T::MAX - 1).checked_next_power_of_two(), None); assert_eq!($T::MAX.checked_next_power_of_two(), None); let mut next_power = 1; -- cgit 1.4.1-3-g733a5