@@ -544,7 +544,7 @@ impl PartialEq<Uint128> for &Uint128 {
544
544
mod tests {
545
545
use crate :: errors:: CheckedMultiplyFractionalError :: { ConversionOverflow , DivideByZero } ;
546
546
use crate :: math:: fraction:: { Fraction , FractionMath } ;
547
- use crate :: { from_slice, to_vec, Decimal } ;
547
+ use crate :: { from_slice, to_vec, Decimal , Decimal256 } ;
548
548
549
549
use super :: * ;
550
550
@@ -1069,13 +1069,27 @@ mod tests {
1069
1069
assert_eq ! ( Uint128 :: new( 47030 ) , res)
1070
1070
}
1071
1071
1072
+ #[ test]
1073
+ fn mul_floored_works_with_higher_bit_sizes ( ) {
1074
+ let fraction = Fraction :: new ( Uint256 :: from ( 8u128 ) , Uint256 :: from ( 21u128 ) ) ;
1075
+ let res = Uint128 :: new ( 123456 ) . mul_floored ( fraction) ; // 47030.8571
1076
+ assert_eq ! ( Uint128 :: new( 47030 ) , res)
1077
+ }
1078
+
1072
1079
#[ test]
1073
1080
fn mul_floored_works_with_decimal ( ) {
1074
1081
let decimal = Decimal :: from_ratio ( 8u128 , 21u128 ) ;
1075
1082
let res = Uint128 :: new ( 123456 ) . mul_floored ( decimal) ; // 47030.8571
1076
1083
assert_eq ! ( Uint128 :: new( 47030 ) , res)
1077
1084
}
1078
1085
1086
+ #[ test]
1087
+ fn mul_floored_works_with_decimal256 ( ) {
1088
+ let decimal = Decimal256 :: from_ratio ( 8u128 , 21u128 ) ;
1089
+ let res = Uint128 :: new ( 123456 ) . mul_floored ( decimal) ; // 47030.8571
1090
+ assert_eq ! ( Uint128 :: new( 47030 ) , res)
1091
+ }
1092
+
1079
1093
#[ test]
1080
1094
#[ should_panic( expected = "ConversionOverflowError" ) ]
1081
1095
fn mul_floored_panics_on_overflow ( ) {
@@ -1135,13 +1149,27 @@ mod tests {
1135
1149
assert_eq ! ( Uint128 :: new( 47031 ) , res)
1136
1150
}
1137
1151
1152
+ #[ test]
1153
+ fn mul_ceil_works_with_higher_bit_sizes ( ) {
1154
+ let fraction = Fraction :: new ( Uint256 :: from ( 8u128 ) , Uint256 :: from ( 21u128 ) ) ;
1155
+ let res = Uint128 :: new ( 123456 ) . mul_ceil ( fraction) ; // 47030.8571
1156
+ assert_eq ! ( Uint128 :: new( 47031 ) , res)
1157
+ }
1158
+
1138
1159
#[ test]
1139
1160
fn mul_ceil_works_with_decimal ( ) {
1140
1161
let decimal = Decimal :: from_ratio ( 8u128 , 21u128 ) ;
1141
1162
let res = Uint128 :: new ( 123456 ) . mul_ceil ( decimal) ; // 47030.8571
1142
1163
assert_eq ! ( Uint128 :: new( 47031 ) , res)
1143
1164
}
1144
1165
1166
+ #[ test]
1167
+ fn mul_ceil_works_with_decimal256 ( ) {
1168
+ let decimal = Decimal256 :: from_ratio ( 8u128 , 21u128 ) ;
1169
+ let res = Uint128 :: new ( 123456 ) . mul_ceil ( decimal) ; // 47030.8571
1170
+ assert_eq ! ( Uint128 :: new( 47031 ) , res)
1171
+ }
1172
+
1145
1173
#[ test]
1146
1174
#[ should_panic( expected = "ConversionOverflowError" ) ]
1147
1175
fn mul_ceil_panics_on_overflow ( ) {
0 commit comments