File tree Expand file tree Collapse file tree 3 files changed +34
-1
lines changed Expand file tree Collapse file tree 3 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,8 @@ and this project adheres to
1616- cosmwasm-std: Implement ` checked_add ` /` _sub ` /` _div ` /` _rem ` for
1717 ` Decimal ` /` Decimal256 ` .
1818- cosmwasm-std: Implement ` pow ` /` saturating_pow ` for ` Decimal ` /` Decimal256 ` .
19- - cosmwasm-std: Implement ` saturating_add ` /` sub ` /` mul ` for ` Decimal ` /` Decimal256 ` .
19+ - cosmwasm-std: Implement ` saturating_add ` /` sub ` /` mul ` for
20+ ` Decimal ` /` Decimal256 ` .
2021
2122[ #1334 ] : https://github.com/CosmWasm/cosmwasm/pull/1334
2223
Original file line number Diff line number Diff line change @@ -1886,18 +1886,34 @@ mod tests {
18861886
18871887 #[ test]
18881888 fn decimal_saturating_works ( ) {
1889+ assert_eq ! (
1890+ Decimal :: percent( 200 ) . saturating_add( Decimal :: percent( 200 ) ) ,
1891+ Decimal :: percent( 400 )
1892+ ) ;
18891893 assert_eq ! (
18901894 Decimal :: MAX . saturating_add( Decimal :: percent( 200 ) ) ,
18911895 Decimal :: MAX
18921896 ) ;
1897+ assert_eq ! (
1898+ Decimal :: percent( 200 ) . saturating_sub( Decimal :: percent( 100 ) ) ,
1899+ Decimal :: percent( 100 )
1900+ ) ;
18931901 assert_eq ! (
18941902 Decimal :: zero( ) . saturating_sub( Decimal :: percent( 200 ) ) ,
18951903 Decimal :: zero( )
18961904 ) ;
1905+ assert_eq ! (
1906+ Decimal :: percent( 200 ) . saturating_mul( Decimal :: percent( 50 ) ) ,
1907+ Decimal :: percent( 100 )
1908+ ) ;
18971909 assert_eq ! (
18981910 Decimal :: MAX . saturating_mul( Decimal :: percent( 200 ) ) ,
18991911 Decimal :: MAX
19001912 ) ;
1913+ assert_eq ! (
1914+ Decimal :: percent( 400 ) . saturating_pow( 2u32 ) ,
1915+ Decimal :: percent( 1600 )
1916+ ) ;
19011917 assert_eq ! ( Decimal :: MAX . saturating_pow( 2u32 ) , Decimal :: MAX ) ;
19021918 }
19031919}
Original file line number Diff line number Diff line change @@ -2036,18 +2036,34 @@ mod tests {
20362036
20372037 #[ test]
20382038 fn decimal256_saturating_works ( ) {
2039+ assert_eq ! (
2040+ Decimal256 :: percent( 200 ) . saturating_add( Decimal256 :: percent( 200 ) ) ,
2041+ Decimal256 :: percent( 400 )
2042+ ) ;
20392043 assert_eq ! (
20402044 Decimal256 :: MAX . saturating_add( Decimal256 :: percent( 200 ) ) ,
20412045 Decimal256 :: MAX
20422046 ) ;
2047+ assert_eq ! (
2048+ Decimal256 :: percent( 200 ) . saturating_sub( Decimal256 :: percent( 100 ) ) ,
2049+ Decimal256 :: percent( 100 )
2050+ ) ;
20432051 assert_eq ! (
20442052 Decimal256 :: zero( ) . saturating_sub( Decimal256 :: percent( 200 ) ) ,
20452053 Decimal256 :: zero( )
20462054 ) ;
2055+ assert_eq ! (
2056+ Decimal256 :: percent( 200 ) . saturating_mul( Decimal256 :: percent( 50 ) ) ,
2057+ Decimal256 :: percent( 100 )
2058+ ) ;
20472059 assert_eq ! (
20482060 Decimal256 :: MAX . saturating_mul( Decimal256 :: percent( 200 ) ) ,
20492061 Decimal256 :: MAX
20502062 ) ;
2063+ assert_eq ! (
2064+ Decimal256 :: percent( 400 ) . saturating_pow( 2u32 ) ,
2065+ Decimal256 :: percent( 1600 )
2066+ ) ;
20512067 assert_eq ! ( Decimal256 :: MAX . saturating_pow( 2u32 ) , Decimal256 :: MAX ) ;
20522068 }
20532069}
You can’t perform that action at this time.
0 commit comments