52 lines
1.4 KiB
Python
52 lines
1.4 KiB
Python
import unittest
|
|
|
|
class TestSolution(unittest.TestCase):
|
|
def test_simple(self):
|
|
test_cases = [
|
|
(0, 0), # Base case: n = 0
|
|
(1, 1), # Base case: n = 1
|
|
(2, 1), # Fibonacci(2) = 1
|
|
(3, 2), # Fibonacci(3) = 2
|
|
(5, 5), # Fibonacci(5) = 5
|
|
(9, 34), # Fibonacci(9) = 34
|
|
]
|
|
|
|
print("\n=== Function Output Test Results ===")
|
|
for input_val, expected in test_cases:
|
|
try:
|
|
actual = fibonacci(input_val) # pyright: ignore[reportUndefinedVariable]
|
|
status = "✓ PASS" if actual == expected else "✗ FAIL"
|
|
print(f"{status} | Input: {input_val} -> Got: {actual} | Expected: {expected}")
|
|
self.assertEqual(actual, expected)
|
|
except Exception as e:
|
|
print(f"✗ ERROR | Input: {input_val} -> Exception: {e}")
|
|
raise
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main(verbosity=2)
|
|
|
|
"""
|
|
def fibonacci(n):
|
|
a = 0
|
|
b = 1
|
|
|
|
# Check if n is less than 0
|
|
if n < 0:
|
|
print("Incorrect input")
|
|
|
|
# Check if n is equal to 0
|
|
elif n == 0:
|
|
return 0
|
|
|
|
# Check if n is equal to 1
|
|
elif n == 1:
|
|
return b
|
|
else:
|
|
for i in range(1, n):
|
|
c = a + b
|
|
a = b
|
|
b = c
|
|
return b
|
|
|
|
print(fibonacci(9))
|
|
""" |