@@ -453,7 +453,7 @@ mod tests {
453453 Decimal :: percent( 50 ) ,
454454 Ok ( Decimal :: zero( ) )
455455 ) ]
456- fn test_calculate_impact_factor_component (
456+ fn test_calculate_cumulative_impact_factor_component (
457457 #[ case] normalized_balance : Decimal ,
458458 #[ case] ideal_balance_lower_bound : Decimal ,
459459 #[ case] ideal_balance_upper_bound : Decimal ,
@@ -680,6 +680,81 @@ mod tests {
680680 }
681681 }
682682
683- // TODO: tests
684- // - calculate_impact_factor
683+ #[ rstest]
684+ #[ case:: no_change_in_balance(
685+ Decimal :: percent( 50 ) ,
686+ Decimal :: percent( 50 ) ,
687+ Decimal :: percent( 40 ) ,
688+ Decimal :: percent( 60 ) ,
689+ Decimal :: one( ) ,
690+ Ok ( SignedDecimal256 :: zero( ) )
691+ ) ]
692+ #[ case:: move_within_ideal_range(
693+ Decimal :: percent( 45 ) ,
694+ Decimal :: percent( 55 ) ,
695+ Decimal :: percent( 40 ) ,
696+ Decimal :: percent( 60 ) ,
697+ Decimal :: one( ) ,
698+ Ok ( SignedDecimal256 :: zero( ) )
699+ ) ]
700+ #[ case:: move_away_from_ideal_range(
701+ Decimal :: percent( 55 ) ,
702+ Decimal :: percent( 65 ) ,
703+ Decimal :: percent( 40 ) ,
704+ Decimal :: percent( 60 ) ,
705+ Decimal :: one( ) ,
706+ Ok ( SignedDecimal256 :: from_str( "0.015625" ) . unwrap( ) )
707+ ) ]
708+ #[ case:: move_towards_ideal_range(
709+ Decimal :: percent( 55 ) ,
710+ Decimal :: percent( 45 ) ,
711+ Decimal :: percent( 40 ) ,
712+ Decimal :: percent( 50 ) ,
713+ Decimal :: one( ) ,
714+ Ok ( SignedDecimal256 :: from_str( "-0.01" ) . unwrap( ) )
715+ ) ]
716+ #[ case:: cross_ideal_range_negative(
717+ Decimal :: percent( 30 ) ,
718+ Decimal :: percent( 65 ) ,
719+ Decimal :: percent( 40 ) ,
720+ Decimal :: percent( 60 ) ,
721+ Decimal :: one( ) ,
722+ Ok ( SignedDecimal256 :: from_str( "-0.046875" ) . unwrap( ) )
723+ ) ]
724+ #[ case:: cross_ideal_range_positive(
725+ Decimal :: percent( 70 ) ,
726+ Decimal :: percent( 25 ) ,
727+ Decimal :: percent( 40 ) ,
728+ Decimal :: percent( 60 ) ,
729+ Decimal :: one( ) ,
730+ Ok ( SignedDecimal256 :: from_str( "0.078125" ) . unwrap( ) )
731+ ) ]
732+ // #[case::precision_issue(
733+ // Decimal::from_str("0.600000000000000001").unwrap(),
734+ // Decimal::from_str("0.600000000000000002").unwrap(),
735+ // Decimal::percent(40),
736+ // Decimal::percent(60),
737+ // Decimal::one(),
738+ // Ok(SignedDecimal256::from_str("-0.000000000000000001").unwrap())
739+ // )]
740+ fn test_calculate_impact_factor_component (
741+ #[ case] prev_normalized_balance : Decimal ,
742+ #[ case] update_normalized_balance : Decimal ,
743+ #[ case] ideal_balance_lower_bound : Decimal ,
744+ #[ case] ideal_balance_upper_bound : Decimal ,
745+ #[ case] upper_limit : Decimal ,
746+ #[ case] expected : Result < SignedDecimal256 , TransmuterMathError > ,
747+ ) {
748+ let group = ImpactFactorParamGroup :: new (
749+ prev_normalized_balance,
750+ update_normalized_balance,
751+ ideal_balance_lower_bound,
752+ ideal_balance_upper_bound,
753+ upper_limit,
754+ )
755+ . unwrap ( ) ;
756+
757+ let result = group. calculate_impact_factor_component ( ) ;
758+ assert_eq ! ( result, expected) ;
759+ }
685760}
0 commit comments