48 lines
1.7 KiB
Python
48 lines
1.7 KiB
Python
import unittest
|
|
try:
|
|
from .lib_misc import is_palindrome_integer
|
|
from .lib_misc import is_palindrome_string
|
|
from .lib_misc import get_digits_reversed
|
|
from .lib_misc import get_item_counts
|
|
from .lib_misc import product
|
|
except ModuleNotFoundError:
|
|
from lib_misc import is_palindrome_integer
|
|
from lib_misc import is_palindrome_string
|
|
from lib_misc import get_digits_reversed
|
|
from lib_misc import get_item_counts
|
|
from lib_misc import product
|
|
|
|
|
|
class TestPrimeMethods(unittest.TestCase):
|
|
|
|
def test_is_palindrome_integer(self):
|
|
self.assertEqual(is_palindrome_integer(2), True)
|
|
self.assertEqual(is_palindrome_integer(888), True)
|
|
self.assertEqual(is_palindrome_integer(9009), True)
|
|
self.assertEqual(is_palindrome_integer(23), False)
|
|
self.assertEqual(is_palindrome_integer(9008), False)
|
|
|
|
def test_is_palindrome_string(self):
|
|
self.assertEqual(is_palindrome_string(2), True)
|
|
self.assertEqual(is_palindrome_string(888), True)
|
|
self.assertEqual(is_palindrome_string(9009), True)
|
|
self.assertEqual(is_palindrome_string(23), False)
|
|
self.assertEqual(is_palindrome_string(9008), False)
|
|
|
|
def test_get_digits_reversed(self):
|
|
self.assertEqual(get_digits_reversed(3), [3])
|
|
self.assertEqual(get_digits_reversed(1234), [4, 3, 2, 1])
|
|
self.assertEqual(get_digits_reversed(1000), [0, 0, 0, 1])
|
|
|
|
def test_get_item_counts(self):
|
|
self.assertEqual(get_item_counts([]), {})
|
|
self.assertEqual(get_item_counts([1, 1, 3]), {1: 2, 3: 1})
|
|
|
|
def test_product(self):
|
|
self.assertEqual(product([2, 4, 8]), 64)
|
|
self.assertEqual(product([]), 1)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|