#!/usr/bin/python3 # -*- coding: utf-8 -*- import unittest # %% Example 3: fib def fib(n: int) -> int: """ Calculates the n-th Fibonacci number iteratively Notice the multi-line setup: """ a, b = 0, 1 for i in range(n): a, b = b, a + b # If you want to debug these with a debugger, # Just set a breakpoint within the function you want to test. return a class FibonacciTest(unittest.TestCase): def setUp(self) -> None: """ Hook method for setting up the test fixture before exercising it. This method is called before calling the implemented test methods. """ print("\n----setup if any\n") def testCalculation(self) -> None: self.assertEqual(fib(0), 0) self.assertEqual(fib(1), 1) self.assertEqual(fib(5), 5) self.assertEqual(fib(10), 55) self.assertEqual(fib(20), 6765) def tearDown(self) -> None: """ Hook method for deconstructing the class fixture after running all tests in the class. """ print("\n----teardown if any\n") if __name__ == "__main__": unittest.main(verbosity=2)