Add unittests

This commit is contained in:
Stephan Porada 2021-03-23 14:46:08 +01:00
parent b37a337e06
commit 7897f2130b
3 changed files with 50 additions and 1 deletions

0
palindrome.py Normal file → Executable file
View File

49
test_palindrome.py Executable file
View File

@ -0,0 +1,49 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest
from transform.Transform import Transform
class TestPalindrome(unittest.TestCase):
"""Test the palindrome script."""
PALINDROME_MAIN_TEST_CASES = [{'input': 28, 'output': 121},
{'input': 51, 'output': 66},
{'input': 11, 'output': 11},
{'input': 607, 'output': 4444},
{'input': 196, 'output': -1}]
IS_PALIDNROME_TEST_CASES = [{'input': 11, 'output': True},
{'input': 112, 'output': False},
{'input': 2222, 'output': True},
{'input': 0, 'output': True},
{'input': 1234321, 'output': True}]
REVERSED_TAST_CASES = [{'input': 123, 'output': 321},
{'input': 4321, 'output': 1234}]
def setUp(self):
pass
def test_palindrome_main(self):
transform = Transform()
for test_case in self.PALINDROME_MAIN_TEST_CASES:
self.assertEqual(transform.palindrome(test_case['input']),
test_case['output'])
def test_is_palindrome(self):
transform = Transform()
for test_case in self.IS_PALIDNROME_TEST_CASES:
# set input_integer for class manually to run this test
transform.input_integer = test_case['input']
self.assertEqual(transform._Transform__is_palindrome(test_case['input']), # noqa
test_case['output'])
def test__reverese_int(self):
transform = Transform()
for test_case in self.REVERSED_TAST_CASES:
self.assertEqual(transform._Transform__reverese_int(test_case['input']), # noqa
test_case['output'])
if __name__ == '__main__':
unittest.main()

View File

@ -20,7 +20,7 @@ class Transform(object):
return self.input_integer
else:
print('Integer {} is not a palindrome'.format(self.input_integer))
print('Calculating the palindrome for input {}'.format(self.input_integer))
print('Calculating the palindrome for input {}'.format(self.input_integer)) # noqa
palindrome = self.__calculate_palindrome()
return palindrome