4 line solution, cannot handle large test cases due to recursivity constraint.
def fib(x): if x >= 2: return fib(x-1) + fib(x-2) return max(x, 0)
def fibonacci(x):if x == 0:return 0elif x == 1:return 1else :return fibonacci(x-1) + fibonacci(x-2)- def fib(x):
- if x >= 2:
- return fib(x-1) + fib(x-2)
- return max(x, 0)
test.assert_equals(fib(5), 5) test.assert_equals(fib(8), 21) Test.describe("Large test cases") test.assert_equals(fib(20), 6765) Test.describe("Negative test cases") test.assert_equals(fib(-9999), 0) test.assert_equals(fib(-1), 0)
# TODO: Replace examples and use TDD development by writing your own tests# These are some of the methods available:# test.expect(boolean, [optional] message)test.assert_equals(fibonacci(8),21 )# test.assert_not_equals(actual, expected, [optional] message)- test.assert_equals(fib(5), 5)
- test.assert_equals(fib(8), 21)
# You can use Test.describe and Test.it to write BDD style test groupings- Test.describe("Large test cases")
- test.assert_equals(fib(20), 6765)
- Test.describe("Negative test cases")
- test.assert_equals(fib(-9999), 0)
- test.assert_equals(fib(-1), 0)