Sha256: a184c9977306a8a2778569cd03ec4ab9272675910983dc7198eb902a5b733a01

Contents?: true

Size: 1.65 KB

Versions: 178

Compression:

Stored size: 1.65 KB

Contents

"""
Notes regarding the implementation of smallest_palindrome and
largest_palindrome:

Both functions must take two keyword arguments:
    max_factor -- int
    min_factor -- int, default 0

Their return value must be a tuple (value, factors) where value is the
palindrome itself, and factors is an iterable containing both factors of the
palindrome in arbitrary order.
"""

import unittest

from palindrome_products import smallest_palindrome, largest_palindrome


class PalindromesTests(unittest.TestCase):
    def test_largest_palindrome_from_single_digit_factors(self):
        value, factors = largest_palindrome(max_factor=9)
        self.assertEqual(value, 9)
        self.assertIn(set(factors), [{1, 9}, {3, 3}])

    def test_largest_palindrome_from_double_digit_factors(self):
        value, factors = largest_palindrome(max_factor=99, min_factor=10)
        self.assertEqual(value, 9009)
        self.assertEqual(set(factors), {91, 99})

    def test_smallest_palindrome_from_double_digit_factors(self):
        value, factors = smallest_palindrome(max_factor=99, min_factor=10)
        self.assertEqual(value, 121)
        self.assertEqual(set(factors), {11})

    def test_largest_palindrome_from_triple_digit_factors(self):
        value, factors = largest_palindrome(max_factor=999, min_factor=100)
        self.assertEqual(value, 906609)
        self.assertEqual(set(factors), {913, 993})

    def test_smallest_palindrome_from_triple_digit_factors(self):
        value, factors = smallest_palindrome(max_factor=999, min_factor=100)
        self.assertEqual(value, 10201)
        self.assertEqual(set(factors), {101, 101})


if __name__ == '__main__':
    unittest.main()

Version data entries

178 entries across 178 versions & 1 rubygems

Version Path
trackler-2.2.1.87 tracks/python/exercises/palindrome-products/palindrome_products_test.py
trackler-2.2.1.86 tracks/python/exercises/palindrome-products/palindrome_products_test.py
trackler-2.2.1.85 tracks/python/exercises/palindrome-products/palindrome_products_test.py
trackler-2.2.1.84 tracks/python/exercises/palindrome-products/palindrome_products_test.py
trackler-2.2.1.83 tracks/python/exercises/palindrome-products/palindrome_products_test.py
trackler-2.2.1.82 tracks/python/exercises/palindrome-products/palindrome_products_test.py
trackler-2.2.1.81 tracks/python/exercises/palindrome-products/palindrome_products_test.py
trackler-2.2.1.80 tracks/python/exercises/palindrome-products/palindrome_products_test.py
trackler-2.2.1.79 tracks/python/exercises/palindrome-products/palindrome_products_test.py
trackler-2.2.1.78 tracks/python/exercises/palindrome-products/palindrome_products_test.py
trackler-2.2.1.77 tracks/python/exercises/palindrome-products/palindrome_products_test.py
trackler-2.2.1.76 tracks/python/exercises/palindrome-products/palindrome_products_test.py
trackler-2.2.1.75 tracks/python/exercises/palindrome-products/palindrome_products_test.py
trackler-2.2.1.74 tracks/python/exercises/palindrome-products/palindrome_products_test.py
trackler-2.2.1.73 tracks/python/exercises/palindrome-products/palindrome_products_test.py
trackler-2.2.1.72 tracks/python/exercises/palindrome-products/palindrome_products_test.py
trackler-2.2.1.71 tracks/python/exercises/palindrome-products/palindrome_products_test.py
trackler-2.2.1.70 tracks/python/exercises/palindrome-products/palindrome_products_test.py
trackler-2.2.1.69 tracks/python/exercises/palindrome-products/palindrome_products_test.py
trackler-2.2.1.68 tracks/python/exercises/palindrome-products/palindrome_products_test.py