Beispiel #1
0
def test_function_calling_single_dict():
    c = session8.counter(session8.add)
    c(3, 4)
    c(5, 2)
    c(6, 8)
    c = session8.counter(session8.mul)
    c(3, 4)
    c = session8.counter(session8.div)
    k = c(12, 3)
    assert k == {'add': 3, 'div': 1, 'mul': 1}
Beispiel #2
0
def test_counter():
    counter_add = session8.counter(add)
    counter_mul = session8.counter(mul)
    counter_div = session8.counter(div)
    counter_add(1, 2)
    counter_add(3, 4)
    counter_add(6, 5)
    counter_mul(20, 2)
    counter_mul(40, 3)
    counter_mul(100, 6)
    counter_div(10, 2)
    assert session8.counters == {'add': 3, 'mul': 3, 'div': 1}
    counter_mul(100, 6)
    counter_div(10, 2)
    assert session8.counters == {'add': 3, 'mul': 4, 'div': 2}
Beispiel #3
0
def test_func_count_custom_parameter_type():
    with pytest.raises(TypeError):
        fc = session8.counter_users(1)

    with pytest.raises(TypeError):
        fc = session8.counter({})
        fc("This is not a function and should throw error!")
Beispiel #4
0
def test_func_count():
    def add(a, b):
        return a + b

    def mul(a, b):
        return a * b

    def div(a, b):
        return b and a / b

    fc = session8.counter()
    for _ in range(10):
        fc(add, 2, 5)
    for _ in range(7):
        fc(mul, 2, 5)
    for _ in range(15):
        fc(div, 2, 5)
    for _ in range(3):
        fc(print, "Apple")

    assert session8.func_count[
        'add'] == 10, "Something wrong with the func_count function."
    assert session8.func_count[
        'mul'] == 7, "Something wrong with the func_count function."
    assert session8.func_count[
        'div'] == 15, "Something wrong with the func_count function."
    assert session8.func_count[
        'print'] == 3, "Something wrong with the func_count function."
def test_counter_mul():
    cnt_mul = session8.counter(session8.mul)
    for i in range(10):
        cnt_mul(4, 5)
    assert session8.cnt['mul'] == 10, "Counter function is not working"
def test_counter_add():
    cnt_add = session8.counter(session8.add)
    for i in range(10):
        cnt_add(4, 5)
    assert session8.cnt['add'] == 10, "Counter function is not working"
def test_counter_div():
    cnt_div = session8.counter(session8.div)
    for i in range(10):
        cnt_div(4, 5)
    assert session8.cnt['div'] == 10, "Counter function is not working"