def test_list_expenses_equal(): transactions = [] add_expense(transactions, 1, "gas", 100) add_expense(transactions, 2, "electricity", 100) assert list_expenses_equal(transactions,100)==[ {'apartment':1, "type":"gas", "amount":100},{'apartment':2, "type":"electricity", "amount":100}]
def ui_add_expense(transactions, backup, apartment, expense_type, amount): """Add an expense to the end of the transactions list. Args: transactions(list): the list containing the expenses. apartment(uint): the apartment number. expense_type(str): the type of the expense. amount(uint): the amount of money. Returns: None Raises: ValueError: if the apartment number is negative if the amount of money is negative if the expense type is invalid """ apartment = int(apartment) amount = int(amount) if apartment < 0: raise ValueError("Negative value given for apartment number.") if amount < 0: raise ValueError("Negative value given for the amount.") if not is_valid_expense_type(expense_type.lower()): raise ValueError("Invalid expense type provided.") # if expense_exists(transactions, apartment, expense_type): # raise ValueError("Transaction already in list.") # backup the data before making any changes backup.append(transactions[:]) add_expense(transactions, apartment, expense_type.lower(), amount)
def test_add_expense(): transactions = [] add_expense(transactions,12,"gas",100) assert len(transactions)==1 add_expense(transactions,1,"heating",200) assert len(transactions)==2
def test_replace_expense_ammount(): transactions = [] add_expense(transactions,1,"heating",100) replace_expenses_amount(transactions,1,"heating",200) assert transactions[0]["amount"]==200
def test_remove_expense_by_apartment(): transactions = [] add_expense(transactions, 1, "gas", 100) add_expense(transactions, 1, "heating", 50) remove_expenses_by_apartment(transactions,1) assert len(transactions)==0
def test_undo_command(): transactions = [] backup = [] add_expense(transactions, 1, "gas", 100) backup.append(transactions[:]) undo_command(transactions,backup) assert len(transactions)==0
def test_filter_expenses_by_value(): transactions = [] add_expense(transactions, 1, "gas", 100) add_expense(transactions, 1, "electricity", 200) add_expense(transactions, 2, "electricity", 50) add_expense(transactions, 2, "gas", 20) assert filter_expenses_by_value(transactions,100) == [{'amount': 50, 'apartment': 2, 'type': 'electricity'}, {'amount': 20, 'apartment': 2, 'type': 'gas'}]
def test_filter_expenses_by_type(): transactions = [] add_expense(transactions, 1, "gas", 100) add_expense(transactions, 1, "electricity", 200) add_expense(transactions, 2, "electricity", 50) add_expense(transactions, 2, "gas", 20) assert filter_expenses_by_type(transactions,"gas")==[{'type': 'gas', 'amount': 100, 'apartment': 1}, {'type': 'gas', 'amount': 20, 'apartment': 2}]
def test_sort_expenses_by_type(): transactions = [] add_expense(transactions, 1, "gas", 100) add_expense(transactions, 1, "electricity", 200) add_expense(transactions, 2, "electricity", 50) add_expense(transactions, 2, "gas", 20) assert sort_expenses_by_type(transactions) == [('gas', 120), ('electricity', 250)]
def test_sort_expenses_by_apartment(): transactions = [] add_expense(transactions, 1, "gas", 100) add_expense(transactions, 1, "electricity", 200) add_expense(transactions, 2, "electricity", 50) add_expense(transactions, 2, "gas", 20) assert sort_expenses_by_apartment(transactions)==[(1, 2), (2, 2)]
def test_max_expense_amount(): transactions = [] add_expense(transactions, 1, "gas", 100) add_expense(transactions, 1, "electricity", 200) add_expense(transactions, 1, "electricity", 50) add_expense(transactions, 1, "gas", 20) max_expenses = max_expense_amount(transactions,1) assert max_expenses[0]["amount"] == 100 assert max_expenses[1]["amount"] == 200
def test_list_expenses_smaller(): transactions = [] add_expense(transactions, 1, "gas", 100) add_expense(transactions, 2, "gas", 50) add_expense(transactions, 3, "heating", 20) assert list_expenses_smaller(transactions,100)==[ {'apartment':2, "type":"gas", "amount":50},{'apartment':3, "type":"heating", "amount":20}]
def test_list_expenses_greater(): transactions = [] add_expense(transactions, 1, "gas", 100) add_expense(transactions, 2, "gas", 50) add_expense(transactions, 3, "heating", 20) assert list_expenses_greater(transactions,50) == [{'apartment':1, "type":"gas", "amount":100}]
def test_list_expenses(): transactions = [] add_expense(transactions, 1, "gas", 20) add_expense(transactions, 2, "gas", 50) add_expense(transactions, 3, "heating", 20) assert transactions == list_expenses(transactions)
def test_sum_expenses_by_type(): transactions = [] add_expense(transactions, 1, "gas", 100) add_expense(transactions, 2, "electricity", 200) add_expense(transactions, 3, "electricity", 50) assert sum_expenses_by_type(transactions,"electricity")==250
def test_remove_expense_by_type(): transactions = [] add_expense(transactions, 1, "gas", 20) add_expense(transactions, 2, "gas", 50) add_expense(transactions, 3, "heating", 20) remove_expenses_by_type(transactions,"gas") assert len(transactions)==1
def load_predefined_data(transactions): add_expense(transactions, 1, "gas", 100) add_expense(transactions, 1, "other", 50) add_expense(transactions, 2, "water", 20) add_expense(transactions, 3, "electricity", 70) add_expense(transactions, 3, "heating", 100) add_expense(transactions, 5, "gas", 200) add_expense(transactions, 6, "other", 500) add_expense(transactions, 7, "heating", 1000) add_expense(transactions, 7, "other", 300) add_expense(transactions, 8, "gas", 900) add_expense(transactions, 9, "electricity", 250)