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.7 tracks/python/exercises/palindrome-products/palindrome_products_test.py
trackler-2.2.1.6 tracks/python/exercises/palindrome-products/palindrome_products_test.py
trackler-2.2.1.5 tracks/python/exercises/palindrome-products/palindrome_products_test.py
trackler-2.2.1.4 tracks/python/exercises/palindrome-products/palindrome_products_test.py
trackler-2.2.1.3 tracks/python/exercises/palindrome-products/palindrome_products_test.py
trackler-2.2.1.2 tracks/python/exercises/palindrome-products/palindrome_products_test.py
trackler-2.2.1.1 tracks/python/exercises/palindrome-products/palindrome_products_test.py
trackler-2.2.1.0 tracks/python/exercises/palindrome-products/palindrome_products_test.py
trackler-2.2.0.6 tracks/python/exercises/palindrome-products/palindrome_products_test.py
trackler-2.2.0.5 tracks/python/exercises/palindrome-products/palindrome_products_test.py
trackler-2.2.0.4 tracks/python/exercises/palindrome-products/palindrome_products_test.py
trackler-2.2.0.3 tracks/python/exercises/palindrome-products/palindrome_products_test.py
trackler-2.2.0.2 tracks/python/exercises/palindrome-products/palindrome_products_test.py
trackler-2.2.0.1 tracks/python/exercises/palindrome-products/palindrome_products_test.py
trackler-2.2.0.0 tracks/python/exercises/palindrome-products/palindrome_products_test.py
trackler-2.1.0.55 tracks/python/exercises/palindrome-products/palindrome_products_test.py
trackler-2.1.0.54 tracks/python/exercises/palindrome-products/palindrome_products_test.py
trackler-2.1.0.53 tracks/python/exercises/palindrome-products/palindrome_products_test.py
trackler-2.1.0.52 tracks/python/exercises/palindrome-products/palindrome_products_test.py
trackler-2.1.0.51 tracks/python/exercises/palindrome-products/palindrome_products_test.py