File tree 5 files changed +42
-1
lines changed
5 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,8 @@ and this project adheres to
17
17
` Decimal ` /` Decimal256 ` .
18
18
- cosmwasm-std: Implement ` pow ` /` saturating_pow ` for ` Decimal ` /` Decimal256 ` .
19
19
- 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 ` .
21
22
22
23
[ #1334 ] : https://github.com/CosmWasm/cosmwasm/pull/1334
23
24
Original file line number Diff line number Diff line change @@ -1911,18 +1911,34 @@ mod tests {
1911
1911
1912
1912
#[ test]
1913
1913
fn decimal_saturating_works ( ) {
1914
+ assert_eq ! (
1915
+ Decimal :: percent( 200 ) . saturating_add( Decimal :: percent( 200 ) ) ,
1916
+ Decimal :: percent( 400 )
1917
+ ) ;
1914
1918
assert_eq ! (
1915
1919
Decimal :: MAX . saturating_add( Decimal :: percent( 200 ) ) ,
1916
1920
Decimal :: MAX
1917
1921
) ;
1922
+ assert_eq ! (
1923
+ Decimal :: percent( 200 ) . saturating_sub( Decimal :: percent( 100 ) ) ,
1924
+ Decimal :: percent( 100 )
1925
+ ) ;
1918
1926
assert_eq ! (
1919
1927
Decimal :: zero( ) . saturating_sub( Decimal :: percent( 200 ) ) ,
1920
1928
Decimal :: zero( )
1921
1929
) ;
1930
+ assert_eq ! (
1931
+ Decimal :: percent( 200 ) . saturating_mul( Decimal :: percent( 50 ) ) ,
1932
+ Decimal :: percent( 100 )
1933
+ ) ;
1922
1934
assert_eq ! (
1923
1935
Decimal :: MAX . saturating_mul( Decimal :: percent( 200 ) ) ,
1924
1936
Decimal :: MAX
1925
1937
) ;
1938
+ assert_eq ! (
1939
+ Decimal :: percent( 400 ) . saturating_pow( 2u32 ) ,
1940
+ Decimal :: percent( 1600 )
1941
+ ) ;
1926
1942
assert_eq ! ( Decimal :: MAX . saturating_pow( 2u32 ) , Decimal :: MAX ) ;
1927
1943
}
1928
1944
Original file line number Diff line number Diff line change @@ -2061,18 +2061,34 @@ mod tests {
2061
2061
2062
2062
#[ test]
2063
2063
fn decimal256_saturating_works ( ) {
2064
+ assert_eq ! (
2065
+ Decimal256 :: percent( 200 ) . saturating_add( Decimal256 :: percent( 200 ) ) ,
2066
+ Decimal256 :: percent( 400 )
2067
+ ) ;
2064
2068
assert_eq ! (
2065
2069
Decimal256 :: MAX . saturating_add( Decimal256 :: percent( 200 ) ) ,
2066
2070
Decimal256 :: MAX
2067
2071
) ;
2072
+ assert_eq ! (
2073
+ Decimal256 :: percent( 200 ) . saturating_sub( Decimal256 :: percent( 100 ) ) ,
2074
+ Decimal256 :: percent( 100 )
2075
+ ) ;
2068
2076
assert_eq ! (
2069
2077
Decimal256 :: zero( ) . saturating_sub( Decimal256 :: percent( 200 ) ) ,
2070
2078
Decimal256 :: zero( )
2071
2079
) ;
2080
+ assert_eq ! (
2081
+ Decimal256 :: percent( 200 ) . saturating_mul( Decimal256 :: percent( 50 ) ) ,
2082
+ Decimal256 :: percent( 100 )
2083
+ ) ;
2072
2084
assert_eq ! (
2073
2085
Decimal256 :: MAX . saturating_mul( Decimal256 :: percent( 200 ) ) ,
2074
2086
Decimal256 :: MAX
2075
2087
) ;
2088
+ assert_eq ! (
2089
+ Decimal256 :: percent( 400 ) . saturating_pow( 2u32 ) ,
2090
+ Decimal256 :: percent( 1600 )
2091
+ ) ;
2076
2092
assert_eq ! ( Decimal256 :: MAX . saturating_pow( 2u32 ) , Decimal256 :: MAX ) ;
2077
2093
}
2078
2094
Original file line number Diff line number Diff line change @@ -1472,6 +1472,10 @@ mod tests {
1472
1472
Uint256 :: MAX . saturating_mul( Uint256 :: from( 2u32 ) ) ,
1473
1473
Uint256 :: MAX
1474
1474
) ;
1475
+ assert_eq ! (
1476
+ Uint256 :: from( 4u32 ) . saturating_pow( 2u32 ) ,
1477
+ Uint256 :: from( 16u32 )
1478
+ ) ;
1475
1479
assert_eq ! ( Uint256 :: MAX . saturating_pow( 2u32 ) , Uint256 :: MAX ) ;
1476
1480
}
1477
1481
Original file line number Diff line number Diff line change @@ -1107,6 +1107,10 @@ mod tests {
1107
1107
Uint512 :: MAX . saturating_mul( Uint512 :: from( 2u32 ) ) ,
1108
1108
Uint512 :: MAX
1109
1109
) ;
1110
+ assert_eq ! (
1111
+ Uint512 :: from( 4u32 ) . saturating_pow( 2u32 ) ,
1112
+ Uint512 :: from( 16u32 )
1113
+ ) ;
1110
1114
assert_eq ! ( Uint512 :: MAX . saturating_pow( 2u32 ) , Uint512 :: MAX ) ;
1111
1115
}
1112
1116
You can’t perform that action at this time.
0 commit comments