$ F_0 = 0, \\ F_1 = 1, \\ F_n = F_{n-1} + F_{n-2} $
In [ ]:
import unittest
def run_tests():
suite = unittest.TestLoader().loadTestsFromTestCase(TestFibonacci)
unittest.TextTestRunner().run(suite)
In [ ]:
class TestFibonacci(unittest.TestCase):
def test_fibonacci(self):
self.assertEqual(0, fibonacci(0), "fibonacci(0) should equal 0")
run_tests()
In [ ]:
def fibonacci(n):
return 0
run_tests()
In [ ]:
class TestFibonacci(unittest.TestCase):
def test_fibonacci(self):
self.assertEqual(0, fibonacci(0), "fibonacci(0) should equal 0")
self.assertEqual(1, fibonacci(1), "fibonacci(1) should equal 1")
run_tests()
In [ ]:
def fibonacci(n):
if n == 0: return 0
return 1
run_tests()
In [ ]:
class TestFibonacci(unittest.TestCase):
def test_fibonacci(self):
self.assertEqual(0, fibonacci(0), "fibonacci(0) should equal 0")
self.assertEqual(1, fibonacci(1), "fibonacci(1) should equal 1")
self.assertEqual(1, fibonacci(2), "fibonacci(2) should equal 1")
run_tests()
In [ ]:
class TestFibonacci(unittest.TestCase):
def test_fibonacci(self):
self.assertEqual(0, fibonacci(0), "fibonacci(0) should equal 0")
self.assertEqual(1, fibonacci(1), "fibonacci(1) should equal 1")
self.assertEqual(1, fibonacci(2), "fibonacci(2) should equal 1")
self.assertEqual(2, fibonacci(3), "fibonacci(3) should equal 2")
run_tests()
In [ ]:
def fibonacci(n):
if n == 0: return 0
if n <= 2: return 1
return 2
run_tests()
In [ ]:
class TestFibonacci(unittest.TestCase):
def test_fibonacci(self):
self.assertEqual(0, fibonacci(0), "fibonacci(0) should equal 0")
self.assertEqual(1, fibonacci(1), "fibonacci(1) should equal 1")
self.assertEqual(1, fibonacci(2), "fibonacci(2) should equal 1")
self.assertEqual(2, fibonacci(3), "fibonacci(3) should equal 2")
self.assertEqual(3, fibonacci(4), "fibonacci(4) should equal 3")
run_tests()
In [ ]:
def fibonacci(n):
if n == 0: return 0
if n <= 2: return 1
if n == 3: return 2
return 3
run_tests()
In [ ]:
def fibonacci(n):
if n == 0: return 0
if n <= 2: return 1
if n == 3: return 2
return 2 + 1
run_tests()
In [ ]:
def fibonacci(n):
if n == 0: return 0
if n <= 2: return 1
return fibonacci(n - 1) + fibonacci(n - 2)
run_tests()
In [ ]:
def fibonacci(n):
if n == 0: return 0
if n == 1: return 1
return fibonacci(n - 1) + fibonacci(n - 2)
run_tests()