Skip to content

Commit c0d2ff6

Browse files
committed
Add even more test cases
1 parent d82f697 commit c0d2ff6

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Lib/test/test_functools.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,34 @@ def test_no_dependencies(self):
12621262
[(1, 3, 5)]
12631263
)
12641264

1265+
def test_the_node_multiple_times(self):
1266+
# Test same node multiple times in dependencies
1267+
self._test_graph({1: {2}, 3: {4}, 0: [2, 4, 4, 4, 4, 4]},
1268+
[(2, 4), (1, 3, 0)])
1269+
1270+
# Test adding the same dependency multiple times
1271+
ts = functools.TopologicalSorter()
1272+
ts.add(1, 2)
1273+
ts.add(1, 2)
1274+
ts.add(1, 2)
1275+
self.assertEqual([*ts.static_order()], [2, 1])
1276+
1277+
def test_graph_with_iterables(self):
1278+
dependson = (2*x + 1 for x in range(5))
1279+
ts = functools.TopologicalSorter({0: dependson})
1280+
self.assertEqual(list(ts.static_order()), [1, 3, 5, 7, 9, 0])
1281+
1282+
def test_add_dependencies_for_same_node_incrementally(self):
1283+
# Test same node multiple times
1284+
ts = functools.TopologicalSorter()
1285+
ts.add(1, 2)
1286+
ts.add(1, 3)
1287+
ts.add(1, 4)
1288+
ts.add(1, 5)
1289+
1290+
ts2 = functools.TopologicalSorter({1: {2, 3, 4, 5}})
1291+
self.assertEqual([*ts.static_order()], [*ts2.static_order()])
1292+
12651293
def test_empty(self):
12661294
self._test_graph({}, [])
12671295

0 commit comments

Comments
 (0)