Added unittests
This commit is contained in:
parent
5f2dd62868
commit
6ff0e26c71
46
tests/Program_test.py
Normal file
46
tests/Program_test.py
Normal file
@ -0,0 +1,46 @@
|
||||
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)
|
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
23
tests/tester.py
Normal file
23
tests/tester.py
Normal file
@ -0,0 +1,23 @@
|
||||
import unittest
|
||||
|
||||
from tests.Program_test import ProgramTest
|
||||
|
||||
|
||||
class Tester:
|
||||
|
||||
def __init__(self):
|
||||
self._suite = unittest.TestSuite()
|
||||
|
||||
def create(self):
|
||||
self._suite.addTest(ProgramTest('test_sqrt'))
|
||||
self._suite.addTest(ProgramTest('test_date'))
|
||||
|
||||
def start(self):
|
||||
runner = unittest.TextTestRunner()
|
||||
runner.run(self._suite)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
tester = Tester()
|
||||
tester.create()
|
||||
tester.start()
|
Loading…
Reference in New Issue
Block a user