Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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")
Ejemplo n.º 4
0
def test_should_compute_fibonacci_of_1_correctly():
    assert fibonacci(1) == 1
Ejemplo n.º 5
0
def test_should_compute_fibonacci_of_0_correctly():
    assert fibonacci(0) == 0
Ejemplo n.º 6
0
def test_should_handle_negative_number():
    assert fibonacci(-1) == -1
Ejemplo n.º 7
0
def test_should_compute_fibonacci_of_100_correctly():
    assert fibonacci(100) == 354224848179261915075
Ejemplo n.º 8
0
def test_should_compute_fibonacci_of_3_correctly():
    assert fibonacci(3) == 2
Ejemplo n.º 9
0
def fibonacci_view(model: FibonacciModel):
    result, time = fibonacci(model.n)
    return {"result": result, "time": time}