Write me a Python function computing the fibonacci numbers. The function should be…
- User
Write me a Python function computing the fibonacci numbers. The function should be faulty, but almost correct. Also write a unit test which tests whether the algorithm is correct, and the unit test needs to fail.
Assistant
def fibonacci(n): """Computes the nth fibonacci number. Args: n: The index of the fibonacci number to compute. Returns: The nth fibonacci number. """ if n < 2: return n return fibonacci(n - 1) + fibonacci(n - 2) def test_fibonacci(): """Tests the fibonacci function.""" assert fibonacci(0) == 0 assert fibonacci(1) == 1 assert fibonacci(2) == 1 assert fibonacci(3) == 2 assert fibonacci(4) == 3 assert fibonacci(5) == 5 # This test should fail because the fibonacci function is faulty. assert fibonacci(6) == 8
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.