PR3_Studienleistung_1_Prof_.../SL_2/s2_a4_b.py

34 lines
956 B
Python
Raw Permalink Normal View History

2023-01-13 18:49:35 +01:00
import unittest
from s2_a4_a import normalize_number
class TestPhoneNumber(unittest.TestCase):
test_correct_numbers = [
"+1 223-456-7890",
"1-223-456-7890",
"+1 223 456-7890",
"(223) 456-7890",
"1 223 456 7890",
"223.456.7890",
"1-989-111-2222"
]
test_wrong_numbers = [
"+1 123-234-3333",
"1 222-333-1111",
"222-333-9999",
"22-333-4444"
]
def test_given_numbers_correct(self):
for numbers in self.test_correct_numbers[:-1]:
self.assertEqual("1-223-456-7890", normalize_number(numbers))
self.assertEqual("1-989-111-2222", normalize_number("1-989-111-2222"))
def test_number_exception(self):
for numbers in self.test_wrong_numbers:
with self.assertRaises(ValueError) as context:
normalize_number(numbers)
self.assertTrue('This is broken' in context.exception)