import unittest from datetime import datetime from new.program import Program class ProgramTest(unittest.TestCase): def setUp(self) -> None: self._program = Program() @staticmethod def _to_date(value: str): return datetime.strptime(value, '%d.%m.%Y') def test_sqrt(self): """ Function to test the sqrt function of program, which uses the sqrt function of math package :return: """ print(f'[ {__name__}.test_sqrt ]') result = self._program.sqrt(9.0) self.assertEqual(result, 3.0) result = self._program.sqrt(144.0) self.assertEqual(result, 12.0) def test_date(self): """ Function to test the date function of program, which calculates the difference between two dates :return: """ print(f'[ {__name__}.test_date ]') result = self._program.date(self._to_date('01.01.2020'), self._to_date('31.12.2020')) self.assertEqual(result, 365) result = self._program.date(self._to_date('31.12.2020'), self._to_date('01.01.2020')) self.assertEqual(result, 365) result = self._program.date(self._to_date('01.12.2020'), self._to_date('31.12.2020')) self.assertEqual(result, 30) result = self._program.date(self._to_date('01.01.2000'), self._to_date('31.12.2020')) self.assertEqual(result, 7670)