from finance import InvestmentCalc # Define the mock function that bypasses the database logic def mock_get_market_inflation_rate(self): """Bypasses the database and returns a predictable rate instantly """ print("[Patched] Returning static inflation rate (2%) instantly.") return 0.02 # Apply the Monkey Patch: overwrite the database method with mock function InvestmentCalc.get_market_inflation_rate = mock_get_market_inflation_rate # Test the calculation logic with multiple inputs def test_calculator(): print("๐Ÿš€ Starting test...") # Initialize the class with test inputs calc = InvestmentCalc( principal=10000, rate=8.0, years=5.0, account_type="Double Benefit" ) # Process inputs and generate the result actual_payout = calc.calculate_payout() # Define manually verified expected result based on the formula expected_payout = 14546.35 # Assertions to verify values print("๐Ÿงช Running assertions...") # Verify account metadata remains correct assert calc.account_type == "Double Benefit", ( f"Expected 'Double Benefit', but got '{calc.account_type}'" ) # Verify math logic matches expected payout exactly assert actual_payout == expected_payout, ( f"โŒ Payout calculation failed!\n" f" Expected: INR{expected_payout}\n" f" Actual: INR{actual_payout}" ) test_calculator()