Skip to content

Commit 0dd287a

Browse files
authored
Enhance _is_valid_group with detailed docstring
Added docstring to _is_valid_group function with examples.
1 parent b2ee9df commit 0dd287a

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

maths/is_ipv6_address_valid.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,24 @@
5151

5252

5353
def _is_valid_group(group: str) -> bool:
54-
"""Return True iff group is 1-4 hex digits."""
54+
"""Return True iff group is 1-4 hex digits.
55+
Args:
56+
group (str): The hex group to validate.
57+
58+
Returns:
59+
bool: True if the group is 1-4 hex digits, False otherwise.
60+
61+
Examples:
62+
63+
>>> _is_valid_group("1")
64+
True
65+
>>> _is_valid_group("abcd")
66+
True
67+
>>> _is_valid_group("12345") # too long
68+
False
69+
>>> _is_valid_group("g") # non-hex character
70+
False
71+
"""
5572
return 1 <= len(group) <= 4 and all(ch in _HEX_DIGITS for ch in group)
5673

5774

@@ -102,6 +119,9 @@ def is_ipv6_address_valid(address: str) -> bool:
102119

103120

104121
if __name__ == "__main__":
122+
from doctest import testmod
123+
124+
testmod()
105125
ip = input().strip()
106126
valid_or_invalid = "valid" if is_ipv6_address_valid(ip) else "invalid"
107127
print(f"{ip} is a {valid_or_invalid} IPv6 address.")

0 commit comments

Comments
 (0)