Skip to content

Commit f4ff73b

Browse files
Converted tests into doctests (TheAlgorithms#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>
1 parent cc0405d commit f4ff73b

8 files changed

+24
-87
lines changed

boolean_algebra/and_gate.py

+3-15
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,7 @@ def and_gate(input_1: int, input_2: int) -> int:
3232
return int((input_1, input_2).count(0) == 0)
3333

3434

35-
def test_and_gate() -> None:
36-
"""
37-
Tests the and_gate function
38-
"""
39-
assert and_gate(0, 0) == 0
40-
assert and_gate(0, 1) == 0
41-
assert and_gate(1, 0) == 0
42-
assert and_gate(1, 1) == 1
43-
44-
4535
if __name__ == "__main__":
46-
test_and_gate()
47-
print(and_gate(1, 0))
48-
print(and_gate(0, 0))
49-
print(and_gate(0, 1))
50-
print(and_gate(1, 1))
36+
import doctest
37+
38+
doctest.testmod()

boolean_algebra/imply_gate.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ def imply_gate(input_1: int, input_2: int) -> int:
3434

3535

3636
if __name__ == "__main__":
37-
print(imply_gate(0, 0))
38-
print(imply_gate(0, 1))
39-
print(imply_gate(1, 0))
40-
print(imply_gate(1, 1))
37+
import doctest
38+
39+
doctest.testmod()

boolean_algebra/nand_gate.py

+3-14
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,7 @@ def nand_gate(input_1: int, input_2: int) -> int:
3030
return int((input_1, input_2).count(0) != 0)
3131

3232

33-
def test_nand_gate() -> None:
34-
"""
35-
Tests the nand_gate function
36-
"""
37-
assert nand_gate(0, 0) == 1
38-
assert nand_gate(0, 1) == 1
39-
assert nand_gate(1, 0) == 1
40-
assert nand_gate(1, 1) == 0
41-
42-
4333
if __name__ == "__main__":
44-
print(nand_gate(0, 0))
45-
print(nand_gate(0, 1))
46-
print(nand_gate(1, 0))
47-
print(nand_gate(1, 1))
34+
import doctest
35+
36+
doctest.testmod()

boolean_algebra/nimply_gate.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ def nimply_gate(input_1: int, input_2: int) -> int:
3434

3535

3636
if __name__ == "__main__":
37-
print(nimply_gate(0, 0))
38-
print(nimply_gate(0, 1))
39-
print(nimply_gate(1, 0))
40-
print(nimply_gate(1, 1))
37+
import doctest
38+
39+
doctest.testmod()

boolean_algebra/not_gate.py

+3-10
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,7 @@ def not_gate(input_1: int) -> int:
2424
return 1 if input_1 == 0 else 0
2525

2626

27-
def test_not_gate() -> None:
28-
"""
29-
Tests the not_gate function
30-
"""
31-
assert not_gate(0) == 1
32-
assert not_gate(1) == 0
33-
34-
3527
if __name__ == "__main__":
36-
print(not_gate(0))
37-
print(not_gate(1))
28+
import doctest
29+
30+
doctest.testmod()

boolean_algebra/or_gate.py

+3-14
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,7 @@ def or_gate(input_1: int, input_2: int) -> int:
2929
return int((input_1, input_2).count(1) != 0)
3030

3131

32-
def test_or_gate() -> None:
33-
"""
34-
Tests the or_gate function
35-
"""
36-
assert or_gate(0, 0) == 0
37-
assert or_gate(0, 1) == 1
38-
assert or_gate(1, 0) == 1
39-
assert or_gate(1, 1) == 1
40-
41-
4232
if __name__ == "__main__":
43-
print(or_gate(0, 1))
44-
print(or_gate(1, 0))
45-
print(or_gate(0, 0))
46-
print(or_gate(1, 1))
33+
import doctest
34+
35+
doctest.testmod()

boolean_algebra/xnor_gate.py

+3-14
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,7 @@ def xnor_gate(input_1: int, input_2: int) -> int:
3131
return 1 if input_1 == input_2 else 0
3232

3333

34-
def test_xnor_gate() -> None:
35-
"""
36-
Tests the xnor_gate function
37-
"""
38-
assert xnor_gate(0, 0) == 1
39-
assert xnor_gate(0, 1) == 0
40-
assert xnor_gate(1, 0) == 0
41-
assert xnor_gate(1, 1) == 1
42-
43-
4434
if __name__ == "__main__":
45-
print(xnor_gate(0, 0))
46-
print(xnor_gate(0, 1))
47-
print(xnor_gate(1, 0))
48-
print(xnor_gate(1, 1))
35+
import doctest
36+
37+
doctest.testmod()

boolean_algebra/xor_gate.py

+3-12
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,7 @@ def xor_gate(input_1: int, input_2: int) -> int:
3131
return (input_1, input_2).count(0) % 2
3232

3333

34-
def test_xor_gate() -> None:
35-
"""
36-
Tests the xor_gate function
37-
"""
38-
assert xor_gate(0, 0) == 0
39-
assert xor_gate(0, 1) == 1
40-
assert xor_gate(1, 0) == 1
41-
assert xor_gate(1, 1) == 0
42-
43-
4434
if __name__ == "__main__":
45-
print(xor_gate(0, 0))
46-
print(xor_gate(0, 1))
35+
import doctest
36+
37+
doctest.testmod()

0 commit comments

Comments
 (0)