Skip to content

Commit

Permalink
Add testcase for overflowing_from_sign_and_abs (#696)
Browse files Browse the repository at this point in the history
  • Loading branch information
rongyi authored and klkvr committed Aug 4, 2024
1 parent ff54195 commit a771aba
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions crates/primitives/src/signed/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1650,4 +1650,19 @@ mod tests {
run_test!(I192, U192);
run_test!(I256, U256);
}

#[test]
fn test_overflowing_from_sign_and_abs() {
let a = Uint::<8, 1>::ZERO;
let (_, overflow) = Signed::overflowing_from_sign_and_abs(Sign::Negative, a);
assert!(!overflow);

let a = Uint::<8, 1>::from(128u8);
let (_, overflow) = Signed::overflowing_from_sign_and_abs(Sign::Negative, a);
assert!(!overflow);

let a = Uint::<8, 1>::from(129u8);
let (_, overflow) = Signed::overflowing_from_sign_and_abs(Sign::Negative, a);
assert!(overflow);
}
}

0 comments on commit a771aba

Please sign in to comment.