Ejemplo n.º 1
0
def run_console():
    #This is the console method, where the user introduces the input
    #input: an operation
    #output: -
    
    print(" Welcome to my application for Assignment03-04!")
    print(" This application helps an apartment building administrator to store, for a given month, the expenses for each apartment.")
    print(" Each expense is stored in the application using the following elements: apartment(number of apartment, positive integer),")
    print(" amount (positive integer), type (from one of the predefined categories: water, heating, electricity, gas, other).")
    input_syntax()
    operations = {"exit": exit, "add": add, "list": list, "replace": replace, "remove": remove, 
                  "sum": sum, "max": max, "sort": sort, "filter": filter, "undo": undo}
    apartments = []
    Stack = []
    predef_apartments(apartments)
    print("\nThe list already contains 10 items, which are: ")
    list_all(apartments)
    print("\nNow choose an operation from the list presented in the documentation or type 'exit' if you want to exit the program")
    
    while (True):
        print("Choose an operation")
        try:
            operation = input()
            ops = re.split(' ', operation)
            operations[ops[0]](ops, apartments, Stack)
        except KeyError:
            print("Invalid input! Read again the instructions!")
        except ValueError:
            print("Invalid input! Read again the instructions!")
        except IndexError:
            print("Invalid input! Read again the instructions!")
            
            
Ejemplo n.º 2
0
def test_replace():
    V = []
    Stack = []
    predef_apartments(V)
    A = V
    A[0]["amount"] = 50
    ops = ["replace", "1", "gas", "with", "50"]
    assert replace(ops, V, Stack) == A
Ejemplo n.º 3
0
def test_my_type_filter():
    V = []
    type = "gas"
    predef_apartments(V)
    A = [
        create_apartment(1, "gas", 10),
        create_apartment(2, "gas", 30),
        create_apartment(3, "gas", 10),
        create_apartment(4, "gas", 50)
    ]
    assert my_type_filter(V, type) == A
Ejemplo n.º 4
0
def test_my_value_filter():
    V = []
    predef_apartments(V)
    val = 15
    A = [
        create_apartment(1, "gas", 10),
        create_apartment(2, "electricity", 10),
        create_apartment(3, "gas", 10),
        create_apartment(4, "electricity", 10)
    ]
    assert my_value_filter(V, val) == A
Ejemplo n.º 5
0
def test_max():
    V = []
    Stack = []
    predef_apartments(V)
    ops = ["max", "1"]
    assert max(ops, V, Stack) == 30
Ejemplo n.º 6
0
def test_sum():
    V = []
    Stack = []
    predef_apartments(V)
    ops = ["sum", "gas"]
    assert sum(ops, V, Stack) == 100
Ejemplo n.º 7
0
def test_search():
    V = []
    predef_apartments(V)
    apart = (1, "water")
    assert search(apart, V) == 1
Ejemplo n.º 8
0
def test_calculate_expenses_by_type():
    V = []
    predef_apartments(V)
    assert calculate_expenses_by_type("gas", V) == 100
Ejemplo n.º 9
0
def test_calculate_expenses():
    V = []
    predef_apartments(V)
    assert calculate_expenses(3, V) == 110