From 7897f2130bd106e6ea5f460ae5236e4641536c91 Mon Sep 17 00:00:00 2001 From: Stephan Porada Date: Tue, 23 Mar 2021 14:46:08 +0100 Subject: [PATCH] Add unittests --- palindrome.py | 0 test_palindrome.py | 49 ++++++++++++++++++++++++++++++++++++++++++ transform/Transform.py | 2 +- 3 files changed, 50 insertions(+), 1 deletion(-) mode change 100644 => 100755 palindrome.py create mode 100755 test_palindrome.py diff --git a/palindrome.py b/palindrome.py old mode 100644 new mode 100755 diff --git a/test_palindrome.py b/test_palindrome.py new file mode 100755 index 0000000..d81c4f0 --- /dev/null +++ b/test_palindrome.py @@ -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() diff --git a/transform/Transform.py b/transform/Transform.py index a226fc2..bf283df 100644 --- a/transform/Transform.py +++ b/transform/Transform.py @@ -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