From e0fa295a6478e9410506760f6ef8a90ecae92645 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20Kr=C3=A4mer?= <2122684@stud.hs-mannheim.de> Date: Mon, 9 Jan 2023 14:53:57 +0100 Subject: [PATCH] =?UTF-8?q?Dateien=20hochladen=20nach=20=E2=80=9ESL2?= =?UTF-8?q?=E2=80=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SL2/s2_a4_a.py | 11 +++++++++++ SL2/s2_a4_b.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 SL2/s2_a4_a.py create mode 100644 SL2/s2_a4_b.py diff --git a/SL2/s2_a4_a.py b/SL2/s2_a4_a.py new file mode 100644 index 0000000..c23588a --- /dev/null +++ b/SL2/s2_a4_a.py @@ -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') + + diff --git a/SL2/s2_a4_b.py b/SL2/s2_a4_b.py new file mode 100644 index 0000000..dbc1810 --- /dev/null +++ b/SL2/s2_a4_b.py @@ -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() \ No newline at end of file