Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chipshort committed Sep 4, 2023
1 parent b232b5a commit 034ade9
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/std/src/math/int128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,22 @@ mod tests {
assert_eq!(c.abs_diff(b), Uint128::from(10u32));
}

#[test]
fn int128_abs_works() {
let a = Int128::from(42i32);
assert_eq!(a.abs(), a);

let b = Int128::from(-42i32);
assert_eq!(b.abs(), a);
assert_eq!((Int128::MIN + Int128::one()).abs(), Int128::MAX);
}

#[test]
#[should_panic = "attempt to negate with overflow"]
fn int128_abs_min_panics() {
_ = Int128::MIN.abs();
}

#[test]
#[should_panic = "attempt to negate with overflow"]
fn int128_neg_min_panics() {
Expand Down
16 changes: 16 additions & 0 deletions packages/std/src/math/int256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,22 @@ mod tests {
assert_eq!(c.abs_diff(b), Uint256::from(10u32));
}

#[test]
fn int256_abs_works() {
let a = Int256::from(42i32);
assert_eq!(a.abs(), a);

let b = Int256::from(-42i32);
assert_eq!(b.abs(), a);
assert_eq!((Int256::MIN + Int256::one()).abs(), Int256::MAX);
}

#[test]
#[should_panic = "attempt to negate with overflow"]
fn int256_abs_min_panics() {
_ = Int256::MIN.abs();
}

#[test]
#[should_panic = "attempt to negate with overflow"]
fn int256_neg_min_panics() {
Expand Down
16 changes: 16 additions & 0 deletions packages/std/src/math/int512.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,22 @@ mod tests {
assert_eq!(c.abs_diff(b), Uint512::from(10u32));
}

#[test]
fn int512_abs_works() {
let a = Int512::from(42i32);
assert_eq!(a.abs(), a);

let b = Int512::from(-42i32);
assert_eq!(b.abs(), a);
assert_eq!((Int512::MIN + Int512::one()).abs(), Int512::MAX);
}

#[test]
#[should_panic = "attempt to negate with overflow"]
fn int512_abs_min_panics() {
_ = Int512::MIN.abs();
}

#[test]
#[should_panic = "attempt to negate with overflow"]
fn int512_neg_min_panics() {
Expand Down
16 changes: 16 additions & 0 deletions packages/std/src/math/int64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,22 @@ mod tests {
assert_eq!(c.abs_diff(b), Uint64::from(10u32));
}

#[test]
fn int64_abs_works() {
let a = Int64::from(42i32);
assert_eq!(a.abs(), a);

let b = Int64::from(-42i32);
assert_eq!(b.abs(), a);
assert_eq!((Int64::MIN + Int64::one()).abs(), Int64::MAX);
}

#[test]
#[should_panic = "attempt to negate with overflow"]
fn int64_abs_min_panics() {
_ = Int64::MIN.abs();
}

#[test]
#[should_panic = "attempt to negate with overflow"]
fn int64_neg_min_panics() {
Expand Down

0 comments on commit 034ade9

Please sign in to comment.