mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 21:11:08 +00:00
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:
parent
cc0405d05c
commit
f4ff73b1bd
|
@ -32,19 +32,7 @@ def and_gate(input_1: int, input_2: int) -> int:
|
|||
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__":
|
||||
test_and_gate()
|
||||
print(and_gate(1, 0))
|
||||
print(and_gate(0, 0))
|
||||
print(and_gate(0, 1))
|
||||
print(and_gate(1, 1))
|
||||
import doctest
|
||||
|
||||
doctest.testmod()
|
||||
|
|
|
@ -34,7 +34,6 @@ def imply_gate(input_1: int, input_2: int) -> int:
|
|||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(imply_gate(0, 0))
|
||||
print(imply_gate(0, 1))
|
||||
print(imply_gate(1, 0))
|
||||
print(imply_gate(1, 1))
|
||||
import doctest
|
||||
|
||||
doctest.testmod()
|
||||
|
|
|
@ -30,18 +30,7 @@ def nand_gate(input_1: int, input_2: int) -> int:
|
|||
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__":
|
||||
print(nand_gate(0, 0))
|
||||
print(nand_gate(0, 1))
|
||||
print(nand_gate(1, 0))
|
||||
print(nand_gate(1, 1))
|
||||
import doctest
|
||||
|
||||
doctest.testmod()
|
||||
|
|
|
@ -34,7 +34,6 @@ def nimply_gate(input_1: int, input_2: int) -> int:
|
|||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(nimply_gate(0, 0))
|
||||
print(nimply_gate(0, 1))
|
||||
print(nimply_gate(1, 0))
|
||||
print(nimply_gate(1, 1))
|
||||
import doctest
|
||||
|
||||
doctest.testmod()
|
||||
|
|
|
@ -24,14 +24,7 @@ def not_gate(input_1: int) -> int:
|
|||
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__":
|
||||
print(not_gate(0))
|
||||
print(not_gate(1))
|
||||
import doctest
|
||||
|
||||
doctest.testmod()
|
||||
|
|
|
@ -29,18 +29,7 @@ def or_gate(input_1: int, input_2: int) -> int:
|
|||
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__":
|
||||
print(or_gate(0, 1))
|
||||
print(or_gate(1, 0))
|
||||
print(or_gate(0, 0))
|
||||
print(or_gate(1, 1))
|
||||
import doctest
|
||||
|
||||
doctest.testmod()
|
||||
|
|
|
@ -31,18 +31,7 @@ def xnor_gate(input_1: int, input_2: int) -> int:
|
|||
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__":
|
||||
print(xnor_gate(0, 0))
|
||||
print(xnor_gate(0, 1))
|
||||
print(xnor_gate(1, 0))
|
||||
print(xnor_gate(1, 1))
|
||||
import doctest
|
||||
|
||||
doctest.testmod()
|
||||
|
|
|
@ -31,16 +31,7 @@ def xor_gate(input_1: int, input_2: int) -> int:
|
|||
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__":
|
||||
print(xor_gate(0, 0))
|
||||
print(xor_gate(0, 1))
|
||||
import doctest
|
||||
|
||||
doctest.testmod()
|
||||
|
|
Loading…
Reference in New Issue
Block a user