Finished
33 area_code: str # XXX
44
55 def __init__(self, number: str):
6 pass
7
6 # Edge Case: Empty or null input strings
7 if not number:
8 raise ValueError("must not be fewer than 10 digits")
9
10 # Remove all non-digit characters
11 cleaned = ""
12 for char in number:
13 if char.isdigit():
14 cleaned += char
15 elif char in " .()-+":
16 # Edge Case: Phone numbers with invalid punctuation
17 continue
18 else:
19 # Edge Case: Phone numbers containing letters
20 if char.isalpha():
21 raise ValueError("letters not permitted")
22 # Edge Case: Phone numbers with special characters other than allowed punctuation
23 else:
24 raise ValueError("punctuations not permitted")
25
26 # Edge Case: Phone numbers with incorrect digit count (too few)
27 if len(cleaned) < 10:
28 raise ValueError("must not be fewer than 10 digits")
29
30 # Edge Case: Phone numbers with incorrect digit count (too many)
31 if len(cleaned) > 11:
32 raise ValueError("must not be greater than 11 digits")
33
34 # Edge Case: Phone numbers with 11 digits, but starts with a number other than 1
35 if len(cleaned) == 11:
36 if cleaned[0] != '1':
37 raise ValueError("11 digits must start with 1")
38 cleaned = cleaned[1:]
39
40 # Edge Case: Area codes starting with 0
41 if cleaned[0] == '0':
42 raise ValueError("area code cannot start with zero")
43
44 # Edge Case: Area codes starting with 1
45 if cleaned[0] == '1':
46 raise ValueError("area code cannot start with one")
47
48 # Edge Case: Exchange codes starting with 0
49 if cleaned[3] == '0':
50 raise ValueError("exchange code cannot start with zero")
51
52 # Edge Case: Exchange codes starting with 1
53 if cleaned[3] == '1':
54 raise ValueError("exchange code cannot start with one")
55
56 self.number = cleaned
57 self.area_code = cleaned[:3]
58
859 def pretty(self) -> str: # (XXX)-XXX-XXXX
9 pass
60 return f"({self.number[:3]})-{self.number[3:6]}-{self.number[6:]}"
61
62# Handled Edge Cases: Empty or null input strings, Phone numbers with invalid punctuation, Phone numbers containing letters, Phone numbers with special characters other than allowed punctuation, Phone numbers with incorrect digit count (too few), Phone numbers with incorrect digit count (too many), Phone numbers with 11 digits but starts with a number other than 1, Area codes starting with 0, Area codes starting with 1, Exchange codes starting with 0, Exchange codes starting with 1
Test NameStatus
test_area_code
Pass
test_cleans_numbers_with_dots
Pass
test_cleans_numbers_with_multiple_spaces
Pass
test_cleans_the_number
Pass
test_invalid_if_area_code_starts_with_0
Pass
test_invalid_if_area_code_starts_with_0_on_valid_11_digit_number
Pass
test_invalid_if_area_code_starts_with_1
Pass
test_invalid_if_area_code_starts_with_1_on_valid_11_digit_number
Pass
test_invalid_if_exchange_code_starts_with_0
Pass
test_invalid_if_exchange_code_starts_with_0_on_valid_11_digit_number
Pass
test_invalid_if_exchange_code_starts_with_1
Pass
test_invalid_if_exchange_code_starts_with_1_on_valid_11_digit_number
Pass
test_invalid_when_11_digits_does_not_start_with_a_1
Pass
test_invalid_when_9_digits
Pass
test_invalid_when_more_than_11_digits
Pass
test_invalid_with_letters
Pass
test_invalid_with_punctuations
Pass
test_pretty_print
Pass
test_pretty_print_with_full_us_phone_number
Pass
test_valid_when_11_digits_and_starting_with_1
Pass
test_valid_when_11_digits_and_starting_with_1_even_with_punctuation
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.