36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
import unittest
|
|
try:
|
|
from .lib_fibonacci import fibonacci_generator
|
|
from .lib_fibonacci import fibonacci_generator_smaller
|
|
from .lib_fibonacci import fibonacci_nth
|
|
except ModuleNotFoundError:
|
|
from lib_fibonacci import fibonacci_generator
|
|
from lib_fibonacci import fibonacci_generator_smaller
|
|
from lib_fibonacci import fibonacci_nth
|
|
|
|
|
|
class TestFibonacciMethods(unittest.TestCase):
|
|
|
|
def test_fibonacci_generator(self):
|
|
g = fibonacci_generator()
|
|
fs = [next(g) for _ in range(10)]
|
|
self.assertEqual(fs, [1, 1, 2, 3, 5, 8, 13, 21, 34, 55])
|
|
self.assertNotEqual(fs, [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55])
|
|
|
|
def test_fibonacci_generator_smaller(self):
|
|
g = fibonacci_generator_smaller(20)
|
|
self.assertEqual(list(g), [1, 1, 2, 3, 5, 8, 13])
|
|
|
|
def test_fibonacci_nth(self):
|
|
self.assertEqual(fibonacci_nth(0), 0)
|
|
self.assertEqual(fibonacci_nth(1), 1)
|
|
self.assertEqual(fibonacci_nth(2), 1)
|
|
self.assertEqual(fibonacci_nth(3), 2)
|
|
self.assertEqual(fibonacci_nth(4), 3)
|
|
self.assertEqual(fibonacci_nth(5), 5)
|
|
self.assertEqual(fibonacci_nth(6), 8)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|