Skip to content

palindrome-products: update tests to v1.1.0 #1308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 20, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions exercises/palindrome-products/palindrome_products_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from palindrome_products import smallest_palindrome, largest_palindrome


# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0
# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0

class PalindromesTests(unittest.TestCase):
def test_smallest_palindrome_from_single_digit_factors(self):
Expand Down Expand Up @@ -60,25 +60,35 @@ def test_largest_palindrome_from_four_digit_factors(self):
self.assertFactorsEqual(factors, {(9901, 9999)})

def test_empty_for_smallest_palindrome_if_none_in_range(self):
with self.assertRaises(ValueError):
with self.assertRaisesWithMessage(ValueError):
value, factors = smallest_palindrome(min_factor=1002,
max_factor=1003)

def test_empty_for_largest_palindrome_if_none_in_range(self):
with self.assertRaises(ValueError):
with self.assertRaisesWithMessage(ValueError):
value, factors = largest_palindrome(min_factor=15, max_factor=15)

def test_error_for_smallest_if_min_is_more_than_max(self):
with self.assertRaises(ValueError):
with self.assertRaisesWithMessage(ValueError):
value, factors = smallest_palindrome(min_factor=10000,
max_factor=1)

def test_error_for_largest_if_min_is_more_than_max(self):
with self.assertRaises(ValueError):
with self.assertRaisesWithMessage(ValueError):
value, factors = largest_palindrome(min_factor=2, max_factor=1)

# Utility methods
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant comment; please remove.


# Utility functions
def setUp(self):
try:
self.assertRaisesRegex
except AttributeError:
self.assertRaisesRegex = self.assertRaisesRegexp

def assertRaisesWithMessage(self, exception):
return self.assertRaisesRegex(exception, r".+")

def assertFactorsEqual(self, actual, expected):
self.assertEqual(set(map(frozenset, actual)),
set(map(frozenset, expected)))
Expand Down