add math utils; integrate checked expression macros
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
611f09829e
commit
5e72d36800
7 changed files with 68 additions and 0 deletions
|
@ -62,3 +62,22 @@ fn common_prefix_none() {
|
|||
let output = string::common_prefix(&input);
|
||||
assert_eq!(output, "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn checked_add() {
|
||||
use utils::math::checked;
|
||||
|
||||
let a = 1234;
|
||||
let res = checked!(a + 1).unwrap();
|
||||
assert_eq!(res, 1235);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "overflow")]
|
||||
fn checked_add_overflow() {
|
||||
use utils::math::checked;
|
||||
|
||||
let a: u64 = u64::MAX;
|
||||
let res = checked!(a + 1).expect("overflow");
|
||||
assert_eq!(res, 0);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue