Esempio n. 1
0
    def test_loan_and_payment(self):
        """General test using list of tests above."""
        for a_test in self.tests:
            my_loan = loans.Loan(
                name=a_test['name'],
                balance=a_test['initial_balance'],
                monthly_payment=a_test['monthly_payment'],
                partial_payment_allowed=a_test['partial_payment_allowed'])

            result = my_loan.make_payment(a_test['payment'])
            self.assertEqual(result, a_test['result'])
            self.assertEqual(my_loan.balance, a_test['new_balance'])
 def buy_business(self, business_asset, verbose=True):
     """Buy a business."""
     if business_asset.down_payment > self.savings:
         loan_amount = int(round((float(business_asset.down_payment -
                                        self.savings) / 1000) + 0.4999,
                                 0) * 1000)
         if player_choice.choose_to_get_loan_to_buy_asset(
                 self, business_asset, loan_amount, verbose):
             self.make_loan(loans.Loan("Bank Loan", loan_amount,
                                       int(loan_amount / 10), True))
         else:
             return False
     self.business_assets.append(business_asset)
     self.savings -= business_asset.down_payment
     return True
 def buy_real_estate(self, real_estate_asset, verbose=True):
     """Buy real estate."""
     if real_estate_asset.down_payment > self.savings:
         loan_amount = int(round((float(real_estate_asset.down_payment -
                                        self.savings) / 1000) + 0.4999, 0) *
                           1000)
         if player_choice.choose_to_get_loan_to_buy_asset(
                 self, real_estate_asset, loan_amount, verbose):
             self.make_loan(loans.Loan("Bank Loan", loan_amount,
                                       int(loan_amount / 10), True))
         else:
             return False
     self.real_estate_assets.append(real_estate_asset)
     self.savings -= real_estate_asset.down_payment
     return True
 def buy_stock(self, stock_asset, cost_per_share=0, verbose=True):
     """Buy stock."""
     if cost_per_share == 0:
         cost_per_share = stock_asset.cost_per_share
     if ((stock_asset.no_shares * stock_asset.cost_per_share) >
             self.savings):
         loan_amount = int(round((float(cost_per_share *
                                        stock_asset.no_shares -
                                        self.savings)/1000) + 0.4999, 0) *
                           1000)
         if assets.choose_to_get_loan_to_buy_asset(
                 self, stock_asset, loan_amount, verbose):
             self.make_loan(loans.Loan("Bank Loan", loan_amount,
                                       int(loan_amount / 10), True))
         else:
             return False
     self.stock_assets.append(stock_asset)
     self.savings -= stock_asset.no_shares * cost_per_share
     return True
Esempio n. 5
0
def get_profession_defs(profession_defs_fn):
    """Load Professions."""
    try:
        profession_defs_temp = json_read_write_file.load_json(
            profession_defs_fn)
    except OSError:
        print("No good Profession dict json file found, file not found, " +
              "please fix")
        raise OSError
    except ValueError:
        print("No good Profession dict json file found, ValueError, " +
              "please fix")
        raise ValueError
    else:
        profession_defs = {}
        for profession in iter(profession_defs_temp):
            loan_list = []
            for a_loan in iter(profession_defs_temp[profession]["Loans"]):
                partial_payment_allowed = (True if a_loan == 'Bank Loan'
                                           else False)
                loan_list.append(loans.Loan(
                    a_loan,
                    profession_defs_temp[profession]["Loans"][a_loan][
                        "Balance"],
                    profession_defs_temp[profession]["Loans"][a_loan][
                        "Payment"],
                    partial_payment_allowed))
            profession_defs[profession] = Profession(
                profession,
                profession_defs_temp[profession]["Salary"],
                profession_defs_temp[profession]["ExpenseTaxes"],
                profession_defs_temp[profession]["ExpenseOther"],
                profession_defs_temp[profession]["CostPerChild"],
                profession_defs_temp[profession]["Savings"],
                loan_list)
    return profession_defs