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")
예제 #2
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")
def test_delete_functions():
    '''
    Function that
    '''
    l = []
    srv_add_transaction(l, 42, 5, 1500, "OUTCOME")
    srv_add_transaction(l, 43, 2, 500, "INCOME")
    srv_add_transaction(l, 44, 64, 1200, "OUTCOME")
    srv_add_transaction(l, 45, 21, 5400, "INCOME")
    srv_add_transaction(l, 46, 5, 7800, "OUTCOME")
    srv_add_transaction(l, 47, 42, 200, "INCOME")
    dt_at_day(l, 5)

    assert len(l) == 4

    for x in l:
        assert get_day(x) != 5

    l.clear()

    srv_add_transaction(l, 42, 5, 1500, "OUTCOME")
    srv_add_transaction(l, 43, 2, 500, "INCOME")
    srv_add_transaction(l, 44, 64, 1200, "OUTCOME")
    srv_add_transaction(l, 45, 21, 5400, "INCOME")
    srv_add_transaction(l, 46, 6, 7800, "OUTCOME")
    srv_add_transaction(l, 47, 42, 200, "INCOME")

    dt_at_period(l, 5, 42)

    assert len(l) == 2

    for x in l:
        assert (get_day(x) <= 5 or get_day(x) >= 42)

    l.clear()

    srv_add_transaction(l, 42, 5, 1500, "OUTCOME")
    srv_add_transaction(l, 43, 2, 500, "INCOME")
    srv_add_transaction(l, 44, 64, 8200, "OUTCOME")
    srv_add_transaction(l, 45, 21, 5400, "INCOME")
    srv_add_transaction(l, 46, 6, 7800, "OUTCOME")
    srv_add_transaction(l, 47, 42, 200, "INCOME")

    dt_of_type(l, "INCOME")

    assert len(l) == 3

    for x in l:
        assert (get_type(x) != "INCOME")
예제 #4
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")
예제 #5
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")
예제 #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")
예제 #7
0
def ballance(l, day):
    s = 0
    for x in l:
        if get_day(x) <= day:
            if get_type(x) == "INCOME":
                s += get_sum(x)
            elif get_type(x) == "OUTCOME":
                s -= get_sum(x)
    return s
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"
def test_modify_transaction():
    '''
    Function that tests if a transaction can be modified
    INPUT:
    OUTPUT:
    '''
    l = []
    srv_add_transaction(l, 42, 5, 1500, "INCOME")
    srv_modify_transaction(l, 42, 6, 1000, "OUTCOME")
    assert (get_day(l[0]) == 6)
    assert (get_sum(l[0]) == 1000)
    assert (get_type(l[0]) == "OUTCOME")
예제 #10
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)
예제 #11
0
def dt_at_period(l, ds, df):
    res = [x for x in l if not (get_day(x) >= ds and get_day(x) <= df)]
    l[:] = res
예제 #12
0
def dt_at_day(l, day):
    res = [x for x in l if (get_day(x) != day)]
    l[:] = res