Converted tests into doctests (#10572)

* Converted tests into doctests

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Removed commented code

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Akshar Goyal 2023-10-16 03:21:43 -04:00 committed by GitHub
parent cc0405d05c
commit f4ff73b1bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 24 additions and 87 deletions

View File

@ -32,19 +32,7 @@ def and_gate(input_1: int, input_2: int) -> int:
return int((input_1, input_2).count(0) == 0) return int((input_1, input_2).count(0) == 0)
def test_and_gate() -> None:
"""
Tests the and_gate function
"""
assert and_gate(0, 0) == 0
assert and_gate(0, 1) == 0
assert and_gate(1, 0) == 0
assert and_gate(1, 1) == 1
if __name__ == "__main__": if __name__ == "__main__":
test_and_gate() import doctest
print(and_gate(1, 0))
print(and_gate(0, 0)) doctest.testmod()
print(and_gate(0, 1))
print(and_gate(1, 1))

View File

@ -34,7 +34,6 @@ def imply_gate(input_1: int, input_2: int) -> int:
if __name__ == "__main__": if __name__ == "__main__":
print(imply_gate(0, 0)) import doctest
print(imply_gate(0, 1))
print(imply_gate(1, 0)) doctest.testmod()
print(imply_gate(1, 1))

View File

@ -30,18 +30,7 @@ def nand_gate(input_1: int, input_2: int) -> int:
return int((input_1, input_2).count(0) != 0) return int((input_1, input_2).count(0) != 0)
def test_nand_gate() -> None:
"""
Tests the nand_gate function
"""
assert nand_gate(0, 0) == 1
assert nand_gate(0, 1) == 1
assert nand_gate(1, 0) == 1
assert nand_gate(1, 1) == 0
if __name__ == "__main__": if __name__ == "__main__":
print(nand_gate(0, 0)) import doctest
print(nand_gate(0, 1))
print(nand_gate(1, 0)) doctest.testmod()
print(nand_gate(1, 1))

View File

@ -34,7 +34,6 @@ def nimply_gate(input_1: int, input_2: int) -> int:
if __name__ == "__main__": if __name__ == "__main__":
print(nimply_gate(0, 0)) import doctest
print(nimply_gate(0, 1))
print(nimply_gate(1, 0)) doctest.testmod()
print(nimply_gate(1, 1))

View File

@ -24,14 +24,7 @@ def not_gate(input_1: int) -> int:
return 1 if input_1 == 0 else 0 return 1 if input_1 == 0 else 0
def test_not_gate() -> None:
"""
Tests the not_gate function
"""
assert not_gate(0) == 1
assert not_gate(1) == 0
if __name__ == "__main__": if __name__ == "__main__":
print(not_gate(0)) import doctest
print(not_gate(1))
doctest.testmod()

View File

@ -29,18 +29,7 @@ def or_gate(input_1: int, input_2: int) -> int:
return int((input_1, input_2).count(1) != 0) return int((input_1, input_2).count(1) != 0)
def test_or_gate() -> None:
"""
Tests the or_gate function
"""
assert or_gate(0, 0) == 0
assert or_gate(0, 1) == 1
assert or_gate(1, 0) == 1
assert or_gate(1, 1) == 1
if __name__ == "__main__": if __name__ == "__main__":
print(or_gate(0, 1)) import doctest
print(or_gate(1, 0))
print(or_gate(0, 0)) doctest.testmod()
print(or_gate(1, 1))

View File

@ -31,18 +31,7 @@ def xnor_gate(input_1: int, input_2: int) -> int:
return 1 if input_1 == input_2 else 0 return 1 if input_1 == input_2 else 0
def test_xnor_gate() -> None:
"""
Tests the xnor_gate function
"""
assert xnor_gate(0, 0) == 1
assert xnor_gate(0, 1) == 0
assert xnor_gate(1, 0) == 0
assert xnor_gate(1, 1) == 1
if __name__ == "__main__": if __name__ == "__main__":
print(xnor_gate(0, 0)) import doctest
print(xnor_gate(0, 1))
print(xnor_gate(1, 0)) doctest.testmod()
print(xnor_gate(1, 1))

View File

@ -31,16 +31,7 @@ def xor_gate(input_1: int, input_2: int) -> int:
return (input_1, input_2).count(0) % 2 return (input_1, input_2).count(0) % 2
def test_xor_gate() -> None:
"""
Tests the xor_gate function
"""
assert xor_gate(0, 0) == 0
assert xor_gate(0, 1) == 1
assert xor_gate(1, 0) == 1
assert xor_gate(1, 1) == 0
if __name__ == "__main__": if __name__ == "__main__":
print(xor_gate(0, 0)) import doctest
print(xor_gate(0, 1))
doctest.testmod()