Exemple #1
0
def test_removeExpenses():
    expense1 = createExpenses(15, 255.55, "Jun/28/2018", 'sewer')
    expense2 = createExpenses(20, 100, "Jan/18/2019", 'maint')
    list = []
    addExpenses(list, expense1)
    addExpenses(list, expense2)
    removeAllExpenses(list,20)
    assert len(list) == 1
def test_modifyExpenses():
    expense1 = createExpenses(15, 255.55, "Jun/28/2018", 'sewer')
    expense2 = createExpenses(20, 100, "Jan/18/2019", 'maint')
    list = []
    addExpenses(list, expense1)
    addExpenses(list, expense2)
    modifyExpenses(list,15, 'sewer', 'Jun/18/2019', 200)
    assert getSum(list[0]) == 200
Exemple #3
0
def test_addExpenses():
    expense1 = createExpenses(15, 255.55, "Jun/28/2018", 'sewer')
    expense2 = createExpenses(20, 100, "Jan/18/2019", 'maint')
    list = []
    addExpenses(list, expense1)
    addExpenses(list, expense2)
    assert len(list) == 2
    assert getId(list[0]) == 15
    assert getSum(list[1]) == 100
    assert getType(list[1]) == 'maint'
Exemple #4
0
def test_descendingOrder():
    ex1 = createExpenses(15, 200.0, '15/June/2000', 'sewer')
    ex2 = createExpenses(15, 166.0, '16/Jan/2000', 'maint')
    ex3 = createExpenses(15, 199.0, '17/March/2000', 'other')
    ex4 = createExpenses(16, 200.0, '15/june/2000', 'sewer')
    ex5 = createExpenses(17, 166.0, '16/jan/2000', 'maint')
    list = []
    addExpenses(list, ex1)
    addExpenses(list, ex2)
    addExpenses(list, ex3)
    addExpenses(list, ex4)
    addExpenses(list, ex5)
    sortExpenses(list)
    assert list == ['15,200.0,15/June/2000,sewer', '16,200.0,15/june/2000,sewer', '15,199.0,17/March/2000,other', '15,166.0,16/Jan/2000,maint', '17,166.0,16/jan/2000,maint']
Exemple #5
0
def test_maxExpenses():
    ex1 = createExpenses(15, 200.0, '15/June/2000', 'sewer')
    ex2 = createExpenses(15, 166.0, '16/Jan/2000', 'maint')
    ex3 = createExpenses(15, 199.0, '17/March/2000', 'other')
    ex4 = createExpenses(16, 200.0, '15/june/2000', 'sewer')
    ex5 = createExpenses(17, 166.0, '16/jan/2000', 'maint')
    list = []
    addExpenses(list, ex1)
    addExpenses(list, ex2)
    addExpenses(list, ex3)
    addExpenses(list, ex4)
    addExpenses(list, ex5)
    assert maxExpenses(list) == [[200.0, 'sewer'], [166.0, 'maintenance'],
                                 [199.0, 'others']]
Exemple #6
0
def test_delAllExpenses():
    ex1 = createExpenses(15, 200.0, '15/June/2000', 'sewer')
    ex2 = createExpenses(15, 166.0, '16/Jan/2000', 'maint')
    ex3 = createExpenses(15, 199.0, '17/March/2000', 'other')
    ex4 = createExpenses(16, 200.0, '15/june/2000', 'sewer')
    ex5 = createExpenses(17, 166.0, '16/jan/2000', 'maint')
    list = []
    addExpenses(list, ex1)
    addExpenses(list, ex2)
    addExpenses(list, ex3)
    addExpenses(list, ex4)
    addExpenses(list, ex5)
    removeAllExpenses(list, 15)
    assert len(list) == 2
Exemple #7
0
def test_addValueToAllExpenses():
    ex1 = createExpenses(15, 200.0, '15/June/2000', 'sewer')
    ex2 = createExpenses(15, 166.0, '16/Jan/2000', 'maint')
    ex3 = createExpenses(15, 199.0, '17/March/2000', 'other')
    ex4 = createExpenses(16, 200.0, '15/June/2000', 'sewer')
    ex5 = createExpenses(17, 166.0, '16/jan/2000', 'maint')
    list = []
    addExpenses(list, ex1)
    addExpenses(list, ex2)
    addExpenses(list, ex3)
    addExpenses(list, ex4)
    addExpenses(list, ex5)
    addValueToAllExpenses(list, 100, '15/June/2000')
    assert list == [
        '15,300.0,15/June/2000,sewer', '15,166.0,16/Jan/2000,maint',
        '15,199.0,17/March/2000,other', '16,300.0,15/June/2000,sewer',
        '17,166.0,16/jan/2000,maint'
    ]
Exemple #8
0
def modifyExpenses(listOfApartments, apartment, newType, newDate, newSum):
    '''
        Desc: Modifies a specific type of expense for a apartment
        In: listOfApartments - list, apartment - int, type - string, date - string
        Out: -
    '''
    for index in range(len(listOfApartments)):
        if getId(listOfApartments[index]) == apartment:
            ap = createExpenses(apartment, newSum, newDate, newType)
            listOfApartments.pop(index)
            listOfApartments.insert(index, ap)
            break
def addValueToAllExpenses(listOfApartments, value, date):
    '''
        Desc: Adds a value to all the expenses
        In: listOfApartments - list, value - int
        Out: -
     '''
    for index in range(len(listOfApartments)):
        if getDate(listOfApartments[index]) == date:
            ap = createExpenses(
                getId(listOfApartments[index]),
                getSum(listOfApartments[index]) + value, date,
                getType(listOfApartments[index]
                        ))  #str(apartment) + str(newSum) + newDate + newType
            listOfApartments.pop(index)
            listOfApartments.insert(index, ap)
            index -= 1
def test_monthlyExpenses():
    ex1 = createExpenses(15, 200.0, '15/6/2000', 'sewer')
    ex2 = createExpenses(16, 166.0, '16/4/2000', 'maint')
    ex3 = createExpenses(15, 199.0, '17/12/2000', 'other')
    ex4 = createExpenses(16, 200.0, '15/5/2000', 'sewer')
    ex5 = createExpenses(15, 166.0, '16/3/2000', 'maint')
    ex6 = createExpenses(15, 166.0, '16/3/2000', 'maint')
    list = []
    addExpenses(list, ex1)
    addExpenses(list, ex2)
    addExpenses(list, ex3)
    addExpenses(list, ex4)
    addExpenses(list, ex5)
    addExpenses(list, ex6)
    assert monthlyExpenses(list) == [[15, '6/2000', 200.0],
                                     [16, '4/2000', 166.0],
                                     [15, '12/2000', 199.0],
                                     [16, '5/2000', 200.0],
                                     [15, '3/2000', 332.0]]
Exemple #11
0
def userInterface(expensesList):
    op = menu()
    commands = []
    commands.append([])
    com_index = 0
    current_index = 0
    while op != 'stop' and op != 'Stop':
        if isInt(op):
            op = int(op)
            if op == 1:
                apart = input("Apartment number: ")
                while isApartment(apart) == False:
                    apart = input(
                        "Apartment number and this time a correct one: ")
                apart = int(apart)
                val = input("Expenses cost: ")
                while isPozFloat(val) == False:
                    val = input("Expenses cost and this time a correct one: ")
                val = float(val)
                date = input("Date DD/MM/YY: ")
                while isDate(date) == False:
                    date = input("Better luck next time with your dates: ")
                type = input("Expenses type: ")
                if type in 'maintenance':
                    type = 'maintenance'
                elif type in 'sewer':
                    type = 'sewer'
                elif type in 'others':
                    type = 'others'
                from Domain.createExpenses import createExpenses
                from Logic.define import addExpenses
                expense = createExpenses(apart, val, date, type)
                addExpenses(expensesList, expense)
                if com_index != current_index:
                    for index in range(current_index + 1, com_index + 1):
                        commands.pop()
                    com_index = current_index
                commands.append(dipCopy(expensesList))
                current_index += 1
                com_index += 1
            elif op == 2:
                if len(expensesList):
                    apart = input("Apartment number: ")
                    while isApartment(apart) == False:
                        apart = input(
                            "Apartment number and this time a correct one: ")
                    apart = int(apart)
                    val = input("New expenses cost: ")
                    while isPozFloat(val) == False:
                        val = input(
                            "New expenses cost and this time a correct one: ")
                    val = float(val)
                    date = input("New date DD/MM/YY: ")
                    while isDate(date) == False:
                        date = input("Better luck next time with your dates: ")
                    type = input("Expenses type: ")
                    if type in 'maintenance':
                        type = 'maintenance'
                    elif type in 'sewer':
                        type = 'sewer'
                    elif type in 'others':
                        type = 'others'
                    from Logic.define import modifyExpenses
                    modifyExpenses(expensesList, apart, type, date, val)
                    if com_index != current_index:
                        for index in range(current_index + 1, com_index + 1):
                            commands.pop()
                        com_index = current_index
                    commands.append(dipCopy(expensesList))
                    current_index += 1
                    com_index += 1
                else:
                    print("There are no expenses to be modified!")
            elif op == 3:
                if len(expensesList):
                    apart = input(
                        "Apartment number to which an expense is to be deleted: "
                    )
                    while isApartment(apart) == False:
                        apart = input(
                            "Apartment number and this time a correct one: ")
                    apart = int(apart)
                    from Logic.define import removeAp
                    removeAp(expensesList, apart)
                    if com_index != current_index:
                        for index in range(current_index + 1, com_index + 1):
                            commands.pop()
                        com_index = current_index
                    commands.append(dipCopy(expensesList))
                    current_index += 1
                    com_index += 1
                else:
                    print("There are no expenses to be deleted!")
            elif op == 4:
                if len(expensesList):
                    apart = input(
                        "Apartment number to which all expenses are to be deleted: "
                    )
                    while isApartment(apart) == False:
                        apart = input(
                            "Apartment number and this time a correct one: ")
                    apart = int(apart)
                    from Logic.removeExpenses import removeAllExpenses
                    removeAllExpenses(expensesList, apart)
                    if com_index != current_index:
                        for index in range(current_index + 1, com_index + 1):
                            commands.pop()
                        com_index = current_index
                    commands.append(dipCopy(expensesList))
                    current_index += 1
                    com_index += 1
                else:
                    print("There are no expenses to be deleted!")
            elif op == 5:
                if len(expensesList):
                    val = input(
                        "The value to be added to the expenses in the certain date: "
                    )
                    while isPozFloat(val) == False:
                        val = input(
                            "Expenses cost and this time a correct one: ")
                    val = float(val)
                    date = input(
                        "The date in which all expenses are to be changed DD/MM/YY: "
                    )
                    while isDate(date) == False:
                        date = input("Better luck next time with your dates: ")
                    from Logic.addValueToAllExpenses import addValueToAllExpenses
                    addValueToAllExpenses(expensesList, val, date)
                    if com_index != current_index:
                        for index in range(current_index + 1, com_index + 1):
                            commands.pop()
                        com_index = current_index
                    commands.append(dipCopy(expensesList))
                    current_index += 1
                    com_index += 1
                else:
                    print("There are no expenses!")
            elif op == 6:
                if len(expensesList):
                    from Logic.maxExpense import maxExpenses
                    print(maxExpenses(expensesList))
                else:
                    print("There are no expenses!")
            elif op == 7:
                if len(expensesList):
                    from Logic.expensesDescendingOrder import sortExpenses
                    sortExpenses(expensesList)
                    if com_index != current_index:
                        for index in range(current_index + 1, com_index + 1):
                            commands.pop()
                        com_index = current_index
                    commands.append(dipCopy(expensesList))
                    current_index += 1
                    com_index += 1
                else:
                    print("There are no expenses to be ordered!")
            elif op == 8:
                if len(expensesList):
                    from Logic.monthlyExpenses import monthlyExpenses
                    print(monthlyExpenses(expensesList))
                else:
                    print("No expenses to be found!")
            elif op == 9:
                if commands:
                    current_index -= 1
                    while len(expensesList):
                        expensesList.pop()
                    if current_index >= 0:
                        expensesList = dipCopy(commands[current_index])
                    else:
                        expensesList = dipCopy([])
                        current_index = -1

                else:
                    print("Nothing to be undone")

            elif op == 10:
                if current_index > len(commands) - 1:
                    print("Invalid action")
                else:
                    current_index += 1
                    expensesList = dipCopy(commands[current_index])

            elif op == 11:
                from UI.commandLine import run
                run(expensesList)
            elif op == 12:
                for ap in expensesList:
                    from Domain.getters import getId, getDate, getSum, getType
                    print('Ap: ' + str(getId(ap)) + ' Date: ' + getDate(ap) +
                          ' Expense: ' + str(getSum(ap)) + ' Type: ' +
                          getType(ap))
        else:
            print("Not a valid option!")
        writeFile(expensesList)
        op = menu()