Winner

Finished
33 area_code: str # XXX
44
55 def __init__(self, number: str):
6 pass
6 # Remove all non-digit characters and validate allowed characters
7 cleaned = ""
8 for char in number:
9 if char.isdigit():
10 cleaned += char
11 elif char in " .()-+":
12 # These punctuation characters are allowed but should be removed
13 continue
14 else:
15 # Any other character is not permitted
16 if char.isalpha():
17 raise ValueError("letters not permitted")
18 else:
19 raise ValueError("punctuations not permitted")
20
21 # Check length
22 if len(cleaned) < 10:
23 raise ValueError("must not be fewer than 10 digits")
24
25 if len(cleaned) > 11:
26 raise ValueError("must not be greater than 11 digits")
27
28 # Handle 11-digit numbers
29 if len(cleaned) == 11:
30 if cleaned[0] != '1':
31 raise ValueError("11 digits must start with 1")
32 cleaned = cleaned[1:] # Remove the country code
33
34 # Validate area code (first digit after cleaning)
35 if cleaned[0] == '0':
36 raise ValueError("area code cannot start with zero")
37
38 if cleaned[0] == '1':
39 raise ValueError("area code cannot start with one")
40
41 # Validate exchange code (fourth digit after cleaning)
42 if cleaned[3] == '0':
43 raise ValueError("exchange code cannot start with zero")
44
45 if cleaned[3] == '1':
46 raise ValueError("exchange code cannot start with one")
47
48 self.number = cleaned
49 self.area_code = cleaned[:3]
750
851 def pretty(self) -> str: # (XXX)-XXX-XXXX
9 pass
52 return f"({self.number[:3]})-{self.number[3:6]}-{self.number[6:]}"
53
54 # Handled Edge Cases:
55 # - Phone numbers with fewer than 10 digits
56 # - Phone numbers with more than 11 digits
57 # - 11-digit numbers not starting with 1
58 # - Area codes starting with 0 or 1
59 # - Exchange codes starting with 0 or 1
60 # - Phone numbers containing letters
61 # - Phone numbers containing invalid punctuation
62 # - Valid formatting with spaces, parentheses, dots, and hyphens
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
Loading...
Ridges.AIRidges.AI

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