Dateien hochladen nach „SL2“

Main
Dennis Krämer 2023-01-09 14:53:57 +01:00
parent 0e3a09ba8d
commit e0fa295a64
2 changed files with 43 additions and 0 deletions

11
SL2/s2_a4_a.py 100644
View File

@ -0,0 +1,11 @@
import re
def normalize(number):
phone_regex = re.compile(r'\+?1?.?.?([2-9]\d{2}).?.?(\d{3}).?([2-9][0-8]\d{2}$)')
tmp = phone_regex.match(number)
if(tmp):
return '1' + '-' + tmp.group(1) + '-' + tmp.group(2) + '-' + tmp.group(3)
else: raise ValueError('Ungültige Telefonnummer')

32
SL2/s2_a4_b.py 100644
View File

@ -0,0 +1,32 @@
import unittest
import s2_a4_a
test_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"]
class TestPhoneNumber(unittest.TestCase):
def test_phoneCorrect1(self):
self.assertEqual(s2_a4_a.normalize(test_numbers[0]), "1-223-456-7890")
def test_phoneCorrect2(self):
self.assertEqual(s2_a4_a.normalize(test_numbers[1]), "1-223-456-7890")
def test_phoneCorrect3(self):
self.assertEqual(s2_a4_a.normalize(test_numbers[2]), "1-223-456-7890")
def test_phoneCorrect4(self):
self.assertEqual(s2_a4_a.normalize(test_numbers[3]), "1-223-456-7890")
def test_phoneCorrect5(self):
self.assertEqual(s2_a4_a.normalize(test_numbers[4]), "1-223-456-7890")
def test_phoneCorrect6(self):
self.assertEqual(s2_a4_a.normalize(test_numbers[5]), "1-223-456-7890")
def test_phoneCorrect7(self):
self.assertEqual(s2_a4_a.normalize(test_numbers[6]), "1-989-111-2222")
def test_failure(self):
self.assertRaises(ValueError,s2_a4_a.normalize, "adasd")
if __name__ == '__main__':
unittest.main()