@@ -1,7 +1,4 @@ |
|
|
1 |
|
-//! This tests the `Integer::{ilog,log2,log10}` methods. These tests are in a |
2 |
|
-//! separate file because there's both a large number of them, and not all tests |
3 |
|
-//! can be run on Android. This is because in Android `ilog2` uses an imprecise |
4 |
|
-//! approximation:https://github.com/rust-lang/rust/blob/4825e12fc9c79954aa0fe18f5521efa6c19c7539/src/libstd/sys/unix/android.rs#L27-L53 |
|
1 |
+//! Tests for the `Integer::{ilog,log2,log10}` methods. |
5 |
2 |
|
6 |
3 |
#[test] |
7 |
4 |
fn checked_ilog() { |
@@ -48,6 +45,10 @@ fn checked_ilog2() { |
|
|
48 |
45 |
assert_eq!(0i8.checked_ilog2(), None); |
49 |
46 |
assert_eq!(0i16.checked_ilog2(), None); |
50 |
47 |
|
|
48 |
+assert_eq!(8192u16.checked_ilog2(), Some((8192f32).log2() as u32)); |
|
49 |
+assert_eq!(32768u16.checked_ilog2(), Some((32768f32).log2() as u32)); |
|
50 |
+assert_eq!(8192i16.checked_ilog2(), Some((8192f32).log2() as u32)); |
|
51 |
+ |
51 |
52 |
for i in 1..=u8::MAX { |
52 |
53 |
assert_eq!(i.checked_ilog2(), Some((i as f32).log2() as u32), "checking {i}"); |
53 |
54 |
} |
@@ -77,15 +78,6 @@ fn checked_ilog2() { |
|
|
77 |
78 |
} |
78 |
79 |
} |
79 |
80 |
|
80 |
|
-// Validate cases that fail on Android's imprecise float ilog2 implementation. |
81 |
|
-#[test] |
82 |
|
-#[cfg(not(target_os = "android"))] |
83 |
|
-fn checked_ilog2_not_android() { |
84 |
|
-assert_eq!(8192u16.checked_ilog2(), Some((8192f32).log2() as u32)); |
85 |
|
-assert_eq!(32768u16.checked_ilog2(), Some((32768f32).log2() as u32)); |
86 |
|
-assert_eq!(8192i16.checked_ilog2(), Some((8192f32).log2() as u32)); |
87 |
|
-} |
88 |
|
- |
89 |
81 |
#[test] |
90 |
82 |
fn checked_ilog10() { |
91 |
83 |
assert_eq!(0u8.checked_ilog10(), None); |