Compare commits
No commits in common. "0bb33a13c2014fafcd28bcb3580d4e89e95ac7f6" and "a45482ca5ef26aadad62286f4f9d76cac45043fb" have entirely different histories.
0bb33a13c2
...
a45482ca5e
0
palindrome.py
Executable file → Normal file
0
palindrome.py
Executable file → Normal file
@ -1,49 +0,0 @@
|
|||||||
#!/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()
|
|
@ -20,7 +20,7 @@ class Transform(object):
|
|||||||
return self.input_integer
|
return self.input_integer
|
||||||
else:
|
else:
|
||||||
print('Integer {} is not a palindrome'.format(self.input_integer))
|
print('Integer {} is not a palindrome'.format(self.input_integer))
|
||||||
print('Calculating the palindrome for input {}'.format(self.input_integer)) # noqa
|
print('Calculating the palindrome for input {}'.format(self.input_integer))
|
||||||
palindrome = self.__calculate_palindrome()
|
palindrome = self.__calculate_palindrome()
|
||||||
return palindrome
|
return palindrome
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user