Skip to content

Commit 28063e0

Browse files
Add default values to constructor for issue #72
Set all variables in affordability_calculator constructor to default to "0". Created a test case for a scenario where user does not enter information, so the constructor defaults the values to "0".
1 parent 48d65ec commit 28063e0

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

home-choice-pro/models/affordability_calculator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ class AffordabilityCalculator:
2929
hoa_monthly_fee: float
3030

3131
# Constructor
32-
def __init__(self, monthly_payment: str, down_payment: str, interest_rate: str, loan_term: str,
33-
hoa_monthly_fee: str):
32+
def __init__(self, monthly_payment: str = "0", down_payment: str = "0",
33+
interest_rate: str = "0", loan_term: str = "0", hoa_monthly_fee: str = "0"):
3434
"""Initializes class variables."""
3535
self.monthly_payment = self.convert_string_number_into_float(monthly_payment)
3636
self.down_payment = self.convert_string_number_into_float(down_payment)

home-choice-pro/tests/test_models/test_affordability_calculator.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ def calculator():
1010
def zero_interest_calculator():
1111
return AffordabilityCalculator("1500.0", "20000.0", "0", "30", "50")
1212

13+
@pytest.fixture
14+
def empty_calculator_fields():
15+
return AffordabilityCalculator()
16+
1317

1418
def test_user_inputs_are_valid(calculator):
1519
assert calculator._user_inputs_are_valid() == True
@@ -35,6 +39,11 @@ def test_calculate_home_affordability_price_with_zero_interest(zero_interest_cal
3539
assert result != "Invalid User Inputs"
3640
assert result == "542000"
3741

42+
def test_empty_calculator_fields(empty_calculator_fields):
43+
result = empty_calculator_fields.calculate_home_affordability_price()
44+
assert result != "Invalid User Inputs"
45+
assert result == "0"
46+
3847

3948
def test_calculate_total_home_loan_price(calculator):
4049
calculator.calculate_home_affordability_price()

0 commit comments

Comments
 (0)