You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
be-lcca/tests/unit/test_masterdata_logic.py

25 lines
762 B
Python

import pytest
from src.masterdata.service import calculate_pmt
def test_calculate_pmt_zero_rate():
# PMT = -PV / nper when rate is 0
pv = 1000
nper = 10
rate = 0
result = calculate_pmt(rate, nper, pv)
assert result == -100
def test_calculate_pmt_standard():
# Example: Loan 1000, 5% rate, 2 periods
# PMT = -1000 * (0.05 * (1.05)^2) / ((1.05)^2 - 1)
# PMT = -1000 * (0.05 * 1.1025) / (0.1025)
# PMT = -1000 * (0.055125) / (0.1025) = -537.8048...
result = calculate_pmt(5, 2, 1000)
assert round(result, 2) == -537.80
def test_calculate_pmt_percentage():
# If rate > 1, it divides by 100
result_5 = calculate_pmt(5, 10, 1000)
result_05 = calculate_pmt(0.05, 10, 1000)
assert result_5 == result_05