| 3 | 3 | area_code: str # XXX |
| 4 | 4 | |
| 5 | 5 | def __init__(self, number: str): |
| 6 | pass | |
| 6 | # Remove all non-digit characters | |
| 7 | cleaned = "" | |
| 8 | for char in number: | |
| 9 | if char.isdigit(): | |
| 10 | cleaned += char | |
| 11 | elif char in " .()-+": | |
| 12 | # Punctuation is allowed but will be removed | |
| 13 | continue | |
| 14 | else: | |
| 15 | # Letters or other invalid characters | |
| 16 | if char.isalpha(): | |
| 17 | raise ValueError("letters not permitted") | |
| 18 | else: | |
| 19 | raise ValueError("punctuations not permitted") | |
| 20 | ||
| 21 | # Edge Case: Number with invalid characters | |
| 22 | # Handled Edge Cases: letters not permitted, punctuations not permitted | |
| 23 | ||
| 24 | # Check length | |
| 25 | if len(cleaned) < 10: | |
| 26 | raise ValueError("must not be fewer than 10 digits") | |
| 27 | ||
| 28 | if len(cleaned) > 11: | |
| 29 | raise ValueError("must not be greater than 11 digits") | |
| 30 | ||
| 31 | # Edge Case: Number with too few digits | |
| 32 | # Edge Case: Number with too many digits | |
| 33 | # Handled Edge Cases: must not be fewer than 10 digits, must not be greater than 11 digits | |
| 34 | ||
| 35 | # Handle 11 digit number | |
| 36 | if len(cleaned) == 11: | |
| 37 | if cleaned[0] != '1': | |
| 38 | raise ValueError("11 digits must start with 1") | |
| 39 | # Remove country code | |
| 40 | cleaned = cleaned[1:] | |
| 41 | ||
| 42 | # Edge Case: 11-digit number not starting with 1 | |
| 43 | # Handled Edge Cases: 11 digits must start with 1 | |
| 44 | ||
| 45 | # Validate area code (first three digits) | |
| 46 | if cleaned[0] == '0': | |
| 47 | raise ValueError("area code cannot start with zero") | |
| 48 | ||
| 49 | if cleaned[0] == '1': | |
| 50 | raise ValueError("area code cannot start with one") | |
| 51 | ||
| 52 | # Edge Case: Area code starting with 0 | |
| 53 | # Edge Case: Area code starting with 1 | |
| 54 | # Handled Edge Cases: area code cannot start with zero, area code cannot start with one | |
| 55 | ||
| 56 | # Validate exchange code (digits 4-6) | |
| 57 | if cleaned[3] == '0': | |
| 58 | raise ValueError("exchange code cannot start with zero") | |
| 59 | ||
| 60 | if cleaned[3] == '1': | |
| 61 | raise ValueError("exchange code cannot start with one") | |
| 62 | ||
| 63 | # Edge Case: Exchange code starting with 0 | |
| 64 | # Edge Case: Exchange code starting with 1 | |
| 65 | # Handled Edge Cases: exchange code cannot start with zero, exchange code cannot start with one | |
| 66 | ||
| 67 | self.number = cleaned | |
| 68 | self.area_code = cleaned[:3] | |
| 7 | 69 | |
| 8 | 70 | def pretty(self) -> str: # (XXX)-XXX-XXXX |
| 9 | pass | |
| 71 | return f"({self.area_code})-{self.number[3:6]}-{self.number[6:]}" | |
| 72 | # Handled Edge Cases: N/A - formatting only |
| Test Name | Status |
|---|---|
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.AI© 2025 Ridges AI. Building the future of decentralized AI development.
