def test_srv_add_transaction():
    '''
    Function that test if srv_add_transaction adds a transaction to the transaction list correctly
    INPUT: -
    OUTPUT: Assertion error if test fails
    '''
    l = []
    srv_add_transaction(l, 23, 5, 1500, "INCOME")
    assert len(l) == 1
    assert get_id(l[0]) == 23
    assert get_day(l[0]) == 5
    assert get_sum(l[0]) == 1500
    assert get_type(l[0]) == "INCOME"

    srv_add_transaction(l, 22, 6, 500, "OUTCOME")
    assert len(l) == 2
    assert get_id(l[1]) == 22
    assert get_day(l[1]) == 6
    assert get_sum(l[1]) == 500
    assert get_type(l[1]) == "OUTCOME"

    try:
        srv_add_transaction(l, -2, 23, 1500, "INCOME")
        assert False
    except Exception as ex:
        assert (str(ex) == "Invalid ID!\n")
Ejemplo n.º 2
0
def repo_add_transaction(l, t):
    '''
    Function that adds a transaction to the list if the ID is not existent
    INPUT: l - a list, t - a transaction
    OUTPUT: Raises exception if ID is existent
    '''
    error = ""
    for tr in l:
        if get_id(tr) == get_id(t):
            error += "ID already exists!\n"
            raise Exception(error)
    l.append(t)
Ejemplo n.º 3
0
def pt_all(l):
    print("All transactions \n")
    for x in l:
        print("Transaction with ID: " + str(get_id(x)))
        print("Day: " + str(get_day(x)) + " Sum: " +
              str(get_sum(x)) + " Type: " + str(get_type(x)))
        print("\n")
Ejemplo n.º 4
0
def pt_type(l, tp):
    print("All transactions of a given type:\n")
    for x in l:
        if get_type(x) == tp:
            print("Transaction with ID: " + str(get_id(x)))
            print("Day: " + str(get_day(x)) + " Sum: " +
                  str(get_sum(x)) + " Type: " + str(get_type(x)))
            print("\n")
Ejemplo n.º 5
0
def pt_untilday_bigger(l, day, s):
    print("All transactions made until the given date with the sum larger than the given number.\n")
    for x in l:
        if get_day(x) < day and get_sum(x) > s:
            print("Transaction with ID: " + str(get_id(x)))
            print("Day: " + str(get_day(x)) + " Sum: " +
                  str(get_sum(x)) + " Type: " + str(get_type(x)))
            print("\n")
Ejemplo n.º 6
0
def pt_bigger(l, s):
    print("All transactions bigger than a given sum \n")
    for x in l:
        if get_sum(x) > s:
            print("Transaction with ID: " + str(get_id(x)))
            print("Day: " + str(get_day(x)) + " Sum: " +
                  str(get_sum(x)) + " Type: " + str(get_type(x)))
            print("\n")
def test_add_transaction():
    '''
    Function that tests if a transaction can be added
    INPUT: -
    OUTPUT: Assertion error if test fails
    '''

    t = create_transaction(21, 5, 1500, "INCOME")

    assert get_id(t) == 21
    assert get_day(t) == 5
    assert get_sum(t) == 1500
    assert get_type(t) == "INCOME"

    modify_transaction(t, 13, 1000, "OUTCOME")

    assert get_id(t) == 21
    assert get_day(t) == 13
    assert get_sum(t) == 1000
    assert get_type(t) == "OUTCOME"
Ejemplo n.º 8
0
def validate_transaction(t):
    '''
    Function that validates a transaction
    INPUT: A transaction
    RAISES: Exception if:
        tid < 0
        day < 0
        sum < 0
        type != "INCOME" / "OUTCOME
    '''
    errors = ""
    if get_id(t) < 0:
        errors += "Invalid ID!\n"
    if get_day(t) < 0:
        errors += "Invalid Day!\n"
    if get_sum(t) < 0:
        errors += "Invalid Sum!\n"
    if str(get_type(t)) != "INCOME":
        if str(get_type(t)) != "OUTCOME":
            errors += "Invalid Type!\n"
    if len(errors) > 0:
        raise Exception(errors)
def srv_modify_transaction(l, tid, day, s, tp):
    for x in l:
        if get_id(x) == tid:
            modify_transaction(x, day, s, tp)