import re import unittest ## def is_valid_phone_number(phone_number : str): ## return bool(re.search(r"^(\d{3}-){2}\d{4}$", phone_number)) import unittest class TestPhoneNumberRegex(unittest.TestCase): def test_if_valid(self): test_cases = [ ("123-456-7890", True), # Valid format ("111-222-3333", True), # Another valid format ("abc-def-ghij", False), # Letters instead of digits ("1234567890", False), # Missing dashes ("123-45-67890", False), # Wrong grouping ("12-3456-7890", False), # Wrong grouping again ("", False), # Empty string ] print("\nPHONE NUMBER VALIDATION TEST RESULTS") for phone, expected in test_cases: try: actual = is_valid_phone_number(phone) # pyright: ignore[reportUndefinedVariable] status = "✓ PASS" if actual == expected else "✗ FAIL" print(f"{status} | Input: '{phone}' -> Got: {actual} | Expected: {expected}") self.assertEqual(actual, expected) except Exception as e: print(f"✗ ERROR | Input: '{phone}' -> Exception: {e}") raise if __name__ == "__main__": unittest.main(verbosity=2)