-
Notifications
You must be signed in to change notification settings - Fork 13.4k
exact_div: add tests #141939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
exact_div: add tests #141939
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -516,5 +516,28 @@ macro_rules! uint_module { | |
assert_eq_const_safe!($T: <$T>::unbounded_shr(17, SHIFT_AMOUNT_OVERFLOW3), 0); | ||
} | ||
} | ||
|
||
const EXACT_DIV_SUCCESS_DIVIDEND1: $T = 42; | ||
const EXACT_DIV_SUCCESS_DIVISOR1: $T = 6; | ||
const EXACT_DIV_SUCCESS_QUOTIENT1: $T = 7; | ||
const EXACT_DIV_SUCCESS_DIVIDEND2: $T = 18; | ||
const EXACT_DIV_SUCCESS_DIVISOR2: $T = 3; | ||
const EXACT_DIV_SUCCESS_QUOTIENT2: $T = 6; | ||
|
||
test_runtime_and_compiletime! { | ||
fn test_exact_div() { | ||
// 42 / 6 | ||
assert_eq_const_safe!(Option<$T>: <$T>::checked_exact_div(EXACT_DIV_SUCCESS_DIVIDEND1, EXACT_DIV_SUCCESS_DIVISOR1), Some(EXACT_DIV_SUCCESS_QUOTIENT1)); | ||
assert_eq_const_safe!($T: <$T>::exact_div(EXACT_DIV_SUCCESS_DIVIDEND1, EXACT_DIV_SUCCESS_DIVISOR1), EXACT_DIV_SUCCESS_QUOTIENT1); | ||
|
||
// 18 / 3 | ||
assert_eq_const_safe!(Option<$T>: <$T>::checked_exact_div(EXACT_DIV_SUCCESS_DIVIDEND2, EXACT_DIV_SUCCESS_DIVISOR2), Some(EXACT_DIV_SUCCESS_QUOTIENT2)); | ||
assert_eq_const_safe!($T: <$T>::exact_div(EXACT_DIV_SUCCESS_DIVIDEND2, EXACT_DIV_SUCCESS_DIVISOR2), EXACT_DIV_SUCCESS_QUOTIENT2); | ||
|
||
// failures | ||
assert_eq_const_safe!(Option<$T>: <$T>::checked_exact_div(1, 2), None); | ||
assert_eq_const_safe!(Option<$T>: <$T>::checked_exact_div(0, 0), None); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose we could test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what, if anything, you want me to change here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nada, just thought process effluvia. |
||
} | ||
} | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not to necessarily block anything, but maybe want to hand wrap these so they don't wrap in the UI?