Skip to content

Commit 82fc24c

Browse files
RaymondDashWupre-commit-ci[bot]cclauss
authored
Test cases for check_bipartite_graph_bfs (TheAlgorithms#10688)
* [ADD] tests for check_bipartite_graph_bfs * linter fix? * linter fix * [ADD] more test cases check_bipartite_graph_bfs * doctest fixes. Forgot to add 'Traceback...' * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * missed a Traceback * Update check_bipartite_graph_bfs.py --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Christian Clauss <[email protected]>
1 parent 4154428 commit 82fc24c

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

graphs/check_bipartite_graph_bfs.py

+45
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,48 @@
1010

1111

1212
def check_bipartite(graph):
13+
"""
14+
>>> check_bipartite({})
15+
True
16+
>>> check_bipartite({0: [1, 3], 1: [0, 2], 2: [1, 3], 3: [0, 2]})
17+
True
18+
>>> check_bipartite({0: [1, 2, 3], 1: [0, 2], 2: [0, 1, 3], 3: [0, 2]})
19+
False
20+
>>> check_bipartite({0: [4], 1: [], 2: [4], 3: [4], 4: [0, 2, 3]})
21+
True
22+
>>> check_bipartite({0: [1, 3], 1: [0, 2], 2: [1, 3], 3: [0, 2], 4: [0]})
23+
False
24+
>>> check_bipartite({7: [1, 3], 1: [0, 2], 2: [1, 3], 3: [0, 2], 4: [0]})
25+
Traceback (most recent call last):
26+
...
27+
KeyError: 0
28+
>>> check_bipartite({0: [1, 3], 1: [0, 2], 2: [1, 3], 3: [0, 2], 9: [0]})
29+
Traceback (most recent call last):
30+
...
31+
KeyError: 4
32+
>>> check_bipartite({0: [-1, 3], 1: [0, -2]})
33+
Traceback (most recent call last):
34+
...
35+
IndexError: list index out of range
36+
>>> check_bipartite({-1: [0, 2], 0: [-1, 1], 1: [0, 2], 2: [-1, 1]})
37+
True
38+
>>> check_bipartite({0.9: [1, 3], 1: [0, 2], 2: [1, 3], 3: [0, 2]})
39+
Traceback (most recent call last):
40+
...
41+
KeyError: 0
42+
>>> check_bipartite({0: [1.0, 3.0], 1.0: [0, 2.0], 2.0: [1.0, 3.0], 3.0: [0, 2.0]})
43+
Traceback (most recent call last):
44+
...
45+
TypeError: list indices must be integers or slices, not float
46+
>>> check_bipartite({"a": [1, 3], "b": [0, 2], "c": [1, 3], "d": [0, 2]})
47+
Traceback (most recent call last):
48+
...
49+
KeyError: 0
50+
>>> check_bipartite({0: ["b", "d"], 1: ["a", "c"], 2: ["b", "d"], 3: ["a", "c"]})
51+
Traceback (most recent call last):
52+
...
53+
TypeError: list indices must be integers or slices, not str
54+
"""
1355
queue = Queue()
1456
visited = [False] * len(graph)
1557
color = [-1] * len(graph)
@@ -45,3 +87,6 @@ def bfs():
4587
if __name__ == "__main__":
4688
# Adjacency List of graph
4789
print(check_bipartite({0: [1, 3], 1: [0, 2], 2: [1, 3], 3: [0, 2]}))
90+
import doctest
91+
92+
doctest.testmod()

0 commit comments

Comments
 (0)