Skip to content

Commit 5bfe2d1

Browse files
committed
Fix formatting in CHANGELOG; add more cases to saturating_ tests to increase coverage
1 parent a2d9897 commit 5bfe2d1

File tree

5 files changed

+42
-1
lines changed

5 files changed

+42
-1
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ and this project adheres to
1717
`Decimal`/`Decimal256`.
1818
- cosmwasm-std: Implement `pow`/`saturating_pow` for `Decimal`/`Decimal256`.
1919
- cosmwasm-std: Implement `ceil`/`floor` for `Decimal`/`Decimal256`.
20-
- cosmwasm-std: Implement `saturating_add`/`sub`/`mul` for `Decimal`/`Decimal256`.
20+
- cosmwasm-std: Implement `saturating_add`/`sub`/`mul` for
21+
`Decimal`/`Decimal256`.
2122

2223
[#1334]: https://github.com/CosmWasm/cosmwasm/pull/1334
2324

packages/std/src/math/decimal.rs

+16
Original file line numberDiff line numberDiff line change
@@ -1911,18 +1911,34 @@ mod tests {
19111911

19121912
#[test]
19131913
fn decimal_saturating_works() {
1914+
assert_eq!(
1915+
Decimal::percent(200).saturating_add(Decimal::percent(200)),
1916+
Decimal::percent(400)
1917+
);
19141918
assert_eq!(
19151919
Decimal::MAX.saturating_add(Decimal::percent(200)),
19161920
Decimal::MAX
19171921
);
1922+
assert_eq!(
1923+
Decimal::percent(200).saturating_sub(Decimal::percent(100)),
1924+
Decimal::percent(100)
1925+
);
19181926
assert_eq!(
19191927
Decimal::zero().saturating_sub(Decimal::percent(200)),
19201928
Decimal::zero()
19211929
);
1930+
assert_eq!(
1931+
Decimal::percent(200).saturating_mul(Decimal::percent(50)),
1932+
Decimal::percent(100)
1933+
);
19221934
assert_eq!(
19231935
Decimal::MAX.saturating_mul(Decimal::percent(200)),
19241936
Decimal::MAX
19251937
);
1938+
assert_eq!(
1939+
Decimal::percent(400).saturating_pow(2u32),
1940+
Decimal::percent(1600)
1941+
);
19261942
assert_eq!(Decimal::MAX.saturating_pow(2u32), Decimal::MAX);
19271943
}
19281944

packages/std/src/math/decimal256.rs

+16
Original file line numberDiff line numberDiff line change
@@ -2061,18 +2061,34 @@ mod tests {
20612061

20622062
#[test]
20632063
fn decimal256_saturating_works() {
2064+
assert_eq!(
2065+
Decimal256::percent(200).saturating_add(Decimal256::percent(200)),
2066+
Decimal256::percent(400)
2067+
);
20642068
assert_eq!(
20652069
Decimal256::MAX.saturating_add(Decimal256::percent(200)),
20662070
Decimal256::MAX
20672071
);
2072+
assert_eq!(
2073+
Decimal256::percent(200).saturating_sub(Decimal256::percent(100)),
2074+
Decimal256::percent(100)
2075+
);
20682076
assert_eq!(
20692077
Decimal256::zero().saturating_sub(Decimal256::percent(200)),
20702078
Decimal256::zero()
20712079
);
2080+
assert_eq!(
2081+
Decimal256::percent(200).saturating_mul(Decimal256::percent(50)),
2082+
Decimal256::percent(100)
2083+
);
20722084
assert_eq!(
20732085
Decimal256::MAX.saturating_mul(Decimal256::percent(200)),
20742086
Decimal256::MAX
20752087
);
2088+
assert_eq!(
2089+
Decimal256::percent(400).saturating_pow(2u32),
2090+
Decimal256::percent(1600)
2091+
);
20762092
assert_eq!(Decimal256::MAX.saturating_pow(2u32), Decimal256::MAX);
20772093
}
20782094

packages/std/src/math/uint256.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1472,6 +1472,10 @@ mod tests {
14721472
Uint256::MAX.saturating_mul(Uint256::from(2u32)),
14731473
Uint256::MAX
14741474
);
1475+
assert_eq!(
1476+
Uint256::from(4u32).saturating_pow(2u32),
1477+
Uint256::from(16u32)
1478+
);
14751479
assert_eq!(Uint256::MAX.saturating_pow(2u32), Uint256::MAX);
14761480
}
14771481

packages/std/src/math/uint512.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,10 @@ mod tests {
11071107
Uint512::MAX.saturating_mul(Uint512::from(2u32)),
11081108
Uint512::MAX
11091109
);
1110+
assert_eq!(
1111+
Uint512::from(4u32).saturating_pow(2u32),
1112+
Uint512::from(16u32)
1113+
);
11101114
assert_eq!(Uint512::MAX.saturating_pow(2u32), Uint512::MAX);
11111115
}
11121116

0 commit comments

Comments
 (0)