Skip to content

Commit

Permalink
Edited Jinja template and regenerated tests for phone-number.
Browse files Browse the repository at this point in the history
  • Loading branch information
BethanyG committed May 10, 2021
1 parent 805fcb5 commit 8a2d5be
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
2 changes: 1 addition & 1 deletion exercises/practice/phone-number/.meta/template.j2
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{{ macros.header([class]) }}

class {{ class }}Test(unittest.TestCase):
{% for case in cases[0]["cases"] -%}
{% for case in cases -%}
def test_{{ case["description"] | to_snake }}(self):
{% if "error" in case["expected"] -%}
with self.assertRaisesWithMessage(ValueError):
Expand Down
71 changes: 71 additions & 0 deletions exercises/practice/phone-number/phone_number_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,77 @@


class PhoneNumberTest(unittest.TestCase):
def test_cleans_the_number(self):
number = PhoneNumber("(223) 456-7890").number
self.assertEqual(number, "2234567890")

def test_cleans_numbers_with_dots(self):
number = PhoneNumber("223.456.7890").number
self.assertEqual(number, "2234567890")

def test_cleans_numbers_with_multiple_spaces(self):
number = PhoneNumber("223 456 7890 ").number
self.assertEqual(number, "2234567890")

def test_invalid_when_9_digits(self):
with self.assertRaisesWithMessage(ValueError):
PhoneNumber("123456789")

def test_invalid_when_11_digits_does_not_start_with_a_1(self):
with self.assertRaisesWithMessage(ValueError):
PhoneNumber("22234567890")

def test_valid_when_11_digits_and_starting_with_1(self):
number = PhoneNumber("12234567890").number
self.assertEqual(number, "2234567890")

def test_valid_when_11_digits_and_starting_with_1_even_with_punctuation(self):
number = PhoneNumber("+1 (223) 456-7890").number
self.assertEqual(number, "2234567890")

def test_invalid_when_more_than_11_digits(self):
with self.assertRaisesWithMessage(ValueError):
PhoneNumber("321234567890")

def test_invalid_with_letters(self):
with self.assertRaisesWithMessage(ValueError):
PhoneNumber("123-abc-7890")

def test_invalid_with_punctuations(self):
with self.assertRaisesWithMessage(ValueError):
PhoneNumber("123-@:!-7890")

def test_invalid_if_area_code_starts_with_0(self):
with self.assertRaisesWithMessage(ValueError):
PhoneNumber("(023) 456-7890")

def test_invalid_if_area_code_starts_with_1(self):
with self.assertRaisesWithMessage(ValueError):
PhoneNumber("(123) 456-7890")

def test_invalid_if_exchange_code_starts_with_0(self):
with self.assertRaisesWithMessage(ValueError):
PhoneNumber("(223) 056-7890")

def test_invalid_if_exchange_code_starts_with_1(self):
with self.assertRaisesWithMessage(ValueError):
PhoneNumber("(223) 156-7890")

def test_invalid_if_area_code_starts_with_0_on_valid_11_digit_number(self):
with self.assertRaisesWithMessage(ValueError):
PhoneNumber("1 (023) 456-7890")

def test_invalid_if_area_code_starts_with_1_on_valid_11_digit_number(self):
with self.assertRaisesWithMessage(ValueError):
PhoneNumber("1 (123) 456-7890")

def test_invalid_if_exchange_code_starts_with_0_on_valid_11_digit_number(self):
with self.assertRaisesWithMessage(ValueError):
PhoneNumber("1 (223) 056-7890")

def test_invalid_if_exchange_code_starts_with_1_on_valid_11_digit_number(self):
with self.assertRaisesWithMessage(ValueError):
PhoneNumber("1 (223) 156-7890")

# Additional tests for this track
def test_area_code(self):
Expand Down

0 comments on commit 8a2d5be

Please sign in to comment.