Beispiel #1
0
def test_fibonacci_with_valid_data():
    """Function tests Fibonacci with valid data"""
    fib_sequence = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]

    for index, value in enumerate(fib_sequence):
        fib, _ = fibonacci(index)
        assert fib == value

    fib, _ = fibonacci(15)
    assert fib == 610
Beispiel #2
0
def fib():
    raw = request.args.get("n")

    number = safe_cast(raw)

    if not is_valid(number):
        abort(400)

    result = fibonacci(number)

    response = make_response(str(result), 200)
    response.mimetype = "text/plain"
    return response
Beispiel #3
0
def test_fibonacci_raises_exception_with_invalid_values():
    """Function tests Factorial with invalid input
        1. Negative value input
        2. Value that exceeds the max limit
        3. Non-integer value
    """
    with pytest.raises(ValidationError):
        fibonacci(-1)

    with pytest.raises(ValidationError):
        fibonacci(config.FIBONACCI_MAX_VALUE + 1)

    with pytest.raises(TypeError):
        fibonacci("string")
Beispiel #4
0
def test_should_compute_fibonacci_of_1_correctly():
    assert fibonacci(1) == 1
Beispiel #5
0
def test_should_compute_fibonacci_of_0_correctly():
    assert fibonacci(0) == 0
Beispiel #6
0
def test_should_handle_negative_number():
    assert fibonacci(-1) == -1
Beispiel #7
0
def test_should_compute_fibonacci_of_100_correctly():
    assert fibonacci(100) == 354224848179261915075
Beispiel #8
0
def test_should_compute_fibonacci_of_3_correctly():
    assert fibonacci(3) == 2
Beispiel #9
0
def fibonacci_view(model: FibonacciModel):
    result, time = fibonacci(model.n)
    return {"result": result, "time": time}