Skip to content

Commit 21a739f

Browse files
committed
add tests for negative numbers
1 parent e87f138 commit 21a739f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

library/coretests/tests/num/int_macros.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,12 @@ macro_rules! int_module {
690690
const EXACT_DIV_SUCCESS_DIVIDEND2: $T = 18;
691691
const EXACT_DIV_SUCCESS_DIVISOR2: $T = 3;
692692
const EXACT_DIV_SUCCESS_QUOTIENT2: $T = 6;
693+
const EXACT_DIV_SUCCESS_DIVIDEND3: $T = -91;
694+
const EXACT_DIV_SUCCESS_DIVISOR3: $T = 13;
695+
const EXACT_DIV_SUCCESS_QUOTIENT3: $T = -7;
696+
const EXACT_DIV_SUCCESS_DIVIDEND4: $T = -57;
697+
const EXACT_DIV_SUCCESS_DIVISOR4: $T = -3;
698+
const EXACT_DIV_SUCCESS_QUOTIENT4: $T = 19;
693699

694700
test_runtime_and_compiletime! {
695701
fn test_exact_div() {
@@ -701,6 +707,14 @@ macro_rules! int_module {
701707
assert_eq_const_safe!(Option<$T>: <$T>::checked_exact_div(EXACT_DIV_SUCCESS_DIVIDEND2, EXACT_DIV_SUCCESS_DIVISOR2), Some(EXACT_DIV_SUCCESS_QUOTIENT2));
702708
assert_eq_const_safe!($T: <$T>::exact_div(EXACT_DIV_SUCCESS_DIVIDEND2, EXACT_DIV_SUCCESS_DIVISOR2), EXACT_DIV_SUCCESS_QUOTIENT2);
703709

710+
// -91 / 13
711+
assert_eq_const_safe!(Option<$T>: <$T>::checked_exact_div(EXACT_DIV_SUCCESS_DIVIDEND3, EXACT_DIV_SUCCESS_DIVISOR3), Some(EXACT_DIV_SUCCESS_QUOTIENT3));
712+
assert_eq_const_safe!($T: <$T>::exact_div(EXACT_DIV_SUCCESS_DIVIDEND3, EXACT_DIV_SUCCESS_DIVISOR3), EXACT_DIV_SUCCESS_QUOTIENT3);
713+
714+
// -57 / -3
715+
assert_eq_const_safe!(Option<$T>: <$T>::checked_exact_div(EXACT_DIV_SUCCESS_DIVIDEND4, EXACT_DIV_SUCCESS_DIVISOR4), Some(EXACT_DIV_SUCCESS_QUOTIENT4));
716+
assert_eq_const_safe!($T: <$T>::exact_div(EXACT_DIV_SUCCESS_DIVIDEND4, EXACT_DIV_SUCCESS_DIVISOR4), EXACT_DIV_SUCCESS_QUOTIENT4);
717+
704718
// failures
705719
assert_eq_const_safe!(Option<$T>: <$T>::checked_exact_div(1, 2), None);
706720
assert_eq_const_safe!(Option<$T>: <$T>::checked_exact_div(<$T>::MIN, -1), None);

0 commit comments

Comments
 (0)