def test_invalid_parameter(self): with raises(ValueError) as e: fibonacci("123") assert str(e.value) == "Usage: fibonacci(num=<int>, cahce=<dict>)" with raises(ValueError) as e: fibonacci(123, cache=[]) assert str(e.value) == "Usage: fibonacci(num=<int>, cahce=<dict>)"
def test_cache(self): def _verify_result(num, cache): for i in range(num + 1): assert i in cache # === Case 1 === cache = {0: 1, 1: 1} fibonacci(3, cache=cache) _verify_result(3, cache) # === Case 2 === cache = {} fibonacci(5, cache=cache) _verify_result(5, cache)
def test_as_array(self): expected = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55] got = [] for i in range(1, 11): got.append(my_math.fibonacci(i)) assert expected == got
def test_value(self): assert fibonacci(0) == 1 assert fibonacci(1) == 1 assert fibonacci(2) == 2 assert fibonacci(3) == 3 assert fibonacci(4) == 5 assert fibonacci(5) == 8
def test_fibonacci(): assert fibonacci(0) == 1 assert fibonacci(1) == 1 assert fibonacci(2) == 2 assert fibonacci(3) == 3 assert fibonacci(4) == 5 assert fibonacci(5) == 8
def test(self): assert my_math.fibonacci(1) == 1 assert my_math.fibonacci(5) == 5 assert my_math.fibonacci(10) == 55 assert my_math.fibonacci(20) == 6765 assert my_math.fibonacci(30) == 832040 assert my_math.fibonacci(35) == 9227465
def test(self): assert my_math.fibonacci(1) == 1 assert my_math.fibonacci(2) == 1 assert my_math.fibonacci(3) == 2 assert my_math.fibonacci(4) > 2 assert (my_math.fibonacci(5) == 5) is True
def test_bool(self): with pytest.raises(TypeError): my_math.fibonacci(True) with pytest.raises(TypeError): my_math.fibonacci(False)
def test_is_instance(self): assert isinstance(my_math.fibonacci(2), int)