mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-17 01:13:11 +00:00
isqrt: add tests
This commit is contained in:
parent
3e8676c327
commit
1b34f1c6b2
@ -290,6 +290,17 @@ macro_rules! int_module {
|
||||
assert_eq!(r.saturating_pow(0), 1 as $T);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_isqrt() {
|
||||
assert_eq!($T::MIN.checked_isqrt(), None);
|
||||
assert_eq!((-1 as $T).checked_isqrt(), None);
|
||||
assert_eq!((0 as $T).isqrt(), 0 as $T);
|
||||
assert_eq!((1 as $T).isqrt(), 1 as $T);
|
||||
assert_eq!((2 as $T).isqrt(), 1 as $T);
|
||||
assert_eq!((99 as $T).isqrt(), 9 as $T);
|
||||
assert_eq!((100 as $T).isqrt(), 10 as $T);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_div_floor() {
|
||||
let a: $T = 8;
|
||||
|
@ -206,6 +206,16 @@ macro_rules! uint_module {
|
||||
assert_eq!(r.saturating_pow(2), MAX);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_isqrt() {
|
||||
assert_eq!((0 as $T).isqrt(), 0 as $T);
|
||||
assert_eq!((1 as $T).isqrt(), 1 as $T);
|
||||
assert_eq!((2 as $T).isqrt(), 1 as $T);
|
||||
assert_eq!((99 as $T).isqrt(), 9 as $T);
|
||||
assert_eq!((100 as $T).isqrt(), 10 as $T);
|
||||
assert_eq!($T::MAX.isqrt(), (1 << ($T::BITS / 2)) - 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_div_floor() {
|
||||
assert_eq!((8 as $T).div_floor(3), 2);
|
||||
|
Loading…
Reference in New Issue
Block a user