Skip to content

Commit

Permalink
Rename the directory Introduction_To_Python...
Browse files Browse the repository at this point in the history
  • Loading branch information
Aadv1k committed Jan 27, 2024
1 parent e46a431 commit 7791d36
Show file tree
Hide file tree
Showing 48 changed files with 57 additions and 0 deletions.
Binary file not shown.
Binary file not shown.
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()
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()

0 comments on commit 7791d36

Please sign in to comment.