Skip to content

Commit

Permalink
Merge pull request #1802 from CosmWasm/improve-padding-test-coverage
Browse files Browse the repository at this point in the history
Test both long and short width for integer padding
  • Loading branch information
webmaster128 authored Jul 27, 2023
2 parents 2dfe895 + 10d2fa7 commit c8491b8
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 4 deletions.
8 changes: 7 additions & 1 deletion packages/std/src/math/int128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,11 +625,17 @@ mod tests {

#[test]
fn int128_display_padding_works() {
// width > natural representation
let a = Int128::from(123u64);
assert_eq!(format!("Embedded: {a:05}"), "Embedded: 00123");

let a = Int128::from(-123i64);
assert_eq!(format!("Embedded: {a:05}"), "Embedded: -0123");

// width < natural representation
let a = Int128::from(123u64);
assert_eq!(format!("Embedded: {a:02}"), "Embedded: 123");
let a = Int128::from(-123i64);
assert_eq!(format!("Embedded: {a:02}"), "Embedded: -123");
}

#[test]
Expand Down
8 changes: 7 additions & 1 deletion packages/std/src/math/int256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,11 +693,17 @@ mod tests {

#[test]
fn int256_display_padding_works() {
// width > natural representation
let a = Int256::from(123u64);
assert_eq!(format!("Embedded: {a:05}"), "Embedded: 00123");

let a = Int256::from(-123i64);
assert_eq!(format!("Embedded: {a:05}"), "Embedded: -0123");

// width < natural representation
let a = Int256::from(123u64);
assert_eq!(format!("Embedded: {a:02}"), "Embedded: 123");
let a = Int256::from(-123i64);
assert_eq!(format!("Embedded: {a:02}"), "Embedded: -123");
}

#[test]
Expand Down
8 changes: 7 additions & 1 deletion packages/std/src/math/int512.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,11 +732,17 @@ mod tests {

#[test]
fn int512_display_padding_works() {
// width > natural representation
let a = Int512::from(123u64);
assert_eq!(format!("Embedded: {a:05}"), "Embedded: 00123");

let a = Int512::from(-123i64);
assert_eq!(format!("Embedded: {a:05}"), "Embedded: -0123");

// width < natural representation
let a = Int512::from(123u64);
assert_eq!(format!("Embedded: {a:02}"), "Embedded: 123");
let a = Int512::from(-123i64);
assert_eq!(format!("Embedded: {a:02}"), "Embedded: -123");
}

#[test]
Expand Down
8 changes: 7 additions & 1 deletion packages/std/src/math/int64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,11 +595,17 @@ mod tests {

#[test]
fn int64_display_padding_works() {
// width > natural representation
let a = Int64::from(123i64);
assert_eq!(format!("Embedded: {a:05}"), "Embedded: 00123");

let a = Int64::from(-123i64);
assert_eq!(format!("Embedded: {a:05}"), "Embedded: -0123");

// width < natural representation
let a = Int64::from(123i64);
assert_eq!(format!("Embedded: {a:02}"), "Embedded: 123");
let a = Int64::from(-123i64);
assert_eq!(format!("Embedded: {a:02}"), "Embedded: -123");
}

#[test]
Expand Down
5 changes: 5 additions & 0 deletions packages/std/src/math/uint128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,8 +690,13 @@ mod tests {

#[test]
fn uint128_display_padding_works() {
// width > natural representation
let a = Uint128::from(123u64);
assert_eq!(format!("Embedded: {a:05}"), "Embedded: 00123");

// width < natural representation
let a = Uint128::from(123u64);
assert_eq!(format!("Embedded: {a:02}"), "Embedded: 123");
}

#[test]
Expand Down
5 changes: 5 additions & 0 deletions packages/std/src/math/uint256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1123,8 +1123,13 @@ mod tests {

#[test]
fn uint256_display_padding_works() {
// width > natural representation
let a = Uint256::from(123u64);
assert_eq!(format!("Embedded: {a:05}"), "Embedded: 00123");

// width < natural representation
let a = Uint256::from(123u64);
assert_eq!(format!("Embedded: {a:02}"), "Embedded: 123");
}

#[test]
Expand Down
5 changes: 5 additions & 0 deletions packages/std/src/math/uint512.rs
Original file line number Diff line number Diff line change
Expand Up @@ -809,8 +809,13 @@ mod tests {

#[test]
fn uint512_display_padding_works() {
// width > natural representation
let a = Uint512::from(123u64);
assert_eq!(format!("Embedded: {a:05}"), "Embedded: 00123");

// width < natural representation
let a = Uint512::from(123u64);
assert_eq!(format!("Embedded: {a:02}"), "Embedded: 123");
}

#[test]
Expand Down
5 changes: 5 additions & 0 deletions packages/std/src/math/uint64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,8 +631,13 @@ mod tests {

#[test]
fn uint64_display_padding_works() {
// width > natural representation
let a = Uint64::from(123u64);
assert_eq!(format!("Embedded: {a:05}"), "Embedded: 00123");

// width < natural representation
let a = Uint64::from(123u64);
assert_eq!(format!("Embedded: {a:02}"), "Embedded: 123");
}

#[test]
Expand Down

0 comments on commit c8491b8

Please sign in to comment.