Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,11 @@ def format(self, style: str = "dash") -> str:

@classmethod
def from_area_code(cls, area_code: str) -> "PhoneNumber":
prefix = str(random.randint(200, 1000))
line_number = str(random.randint(0, 10000)).zfill(4)
return PhoneNumber(area_code=area_code, prefix=prefix, line_number=line_number)
prefix = random.randint(200, 999)
while prefix % 100 == 11:
prefix = random.randint(200, 999)
line_number = str(random.randint(0, 9999)).zfill(4)
return PhoneNumber(area_code=area_code, prefix=str(prefix), line_number=line_number)

@classmethod
def from_zip_prefix(cls, zip_prefix: str) -> "PhoneNumber":
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

from __future__ import annotations

from unittest.mock import patch

import pytest
Expand Down Expand Up @@ -63,6 +65,23 @@ def test_from_area_code():
assert phone.line_number == "1234"


@pytest.mark.parametrize(
("upper_bound", "expected"),
[(False, "202-200-0000"), (True, "202-999-9999")],
)
def test_from_area_code_boundaries(upper_bound: bool, expected: str) -> None:
with patch("random.randint", side_effect=lambda low, high: high if upper_bound else low):
phone = PhoneNumber.from_area_code("202")
assert str(phone) == expected


@pytest.mark.parametrize("reserved_prefix", range(211, 912, 100))
def test_from_area_code_skips_n11_exchanges(reserved_prefix: int) -> None:
with patch("random.randint", side_effect=[reserved_prefix, 500, 42]):
phone = PhoneNumber.from_area_code("202")
assert str(phone) == "202-500-0042"


def test_str_and_repr_representations(stub_sample_phone_number):
assert str(stub_sample_phone_number) == "555-123-4567"
assert repr(stub_sample_phone_number) == "PhoneNumber(555-123-4567)"
Expand Down
Loading