-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename the directory
Introduction_To_Python...
- Loading branch information
Showing
48 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
Binary file added
BIN
+753 Bytes
...tion_To_Programming_with_Python/ProblemSet_07/numb3rs/__pycache__/numb3rs.cpython-310.pyc
Binary file not shown.
Binary file added
BIN
+4.71 KB
...g_with_Python/ProblemSet_07/numb3rs/__pycache__/test_numb3rs.cpython-310-pytest-7.4.4.pyc
Binary file not shown.
13 changes: 13 additions & 0 deletions
13
Introduction_To_Programming_with_Python/ProblemSet_07/numb3rs/numb3rs.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import re | ||
import sys | ||
|
||
def main(): | ||
print(validate(input("IPv4 Address: "))) | ||
|
||
|
||
def validate(ip): | ||
s = [i.isdigit() and int(i) <= 255 for i in ip.strip().split(".")] | ||
return all(s) and len(s) == 4 | ||
|
||
if __name__ == "__main__": | ||
main() |
44 changes: 44 additions & 0 deletions
44
Introduction_To_Programming_with_Python/ProblemSet_07/numb3rs/test_numb3rs.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import pytest | ||
from numb3rs import validate | ||
|
||
def test_valid_ipv4(): | ||
assert validate("127.0.0.1") == True | ||
assert validate("255.255.255.255") == True | ||
assert validate("192.168.1.1") == True | ||
|
||
def test_invalid_ipv4(): | ||
assert validate("512.512.512.512") == False | ||
assert validate("1.2.3.1000") == False | ||
assert validate("cat") == False | ||
assert validate("256.0.0.1") == False | ||
assert validate("192.168.1.1.1") == False | ||
|
||
def test_edge_cases(): | ||
# Minimum valid IPv4 address | ||
assert validate("0.0.0.0") == True | ||
|
||
# Maximum valid IPv4 address | ||
assert validate("255.255.255.255") == True | ||
|
||
# Valid IPv4 addresses with leading zeros | ||
assert validate("001.002.003.004") == True | ||
assert validate("010.020.030.040") == True | ||
|
||
# Valid IPv4 addresses with spaces | ||
assert validate(" 127.0.0.1 ") == True | ||
assert validate(" 192.168.1.1 ") == True | ||
|
||
def test_mixed_formats(): | ||
# Valid IPv4 addresses in mixed formats | ||
assert validate("192.168.1.001") == True | ||
assert validate(" 010.020.030.040 ") == True | ||
|
||
def test_invalid_formats(): | ||
# Invalid IPv4 formats | ||
assert validate("256.0.0.1") == False | ||
assert validate("1.2.3.1000") == False | ||
assert validate("cat") == False | ||
assert validate("192.168.1.1.1") == False | ||
|
||
if __name__ == "__main__": | ||
pytest.main() |
File renamed without changes.