Skip to content

Instantly share code, notes, and snippets.

@blazs
Last active May 8, 2018 11:52
Show Gist options
  • Save blazs/0cc67e168509bc751ab21227368497b5 to your computer and use it in GitHub Desktop.
Save blazs/0cc67e168509bc751ab21227368497b5 to your computer and use it in GitHub Desktop.
Using hypothesis, a property-based testing Python library, to test topological ordering algorithm by randomly sampling the space of directed graphs
@given(
st.lists(st.tuples(st.integers(min_value=0, max_value=10), st.integers(min_value=0, max_value=10)), min_size=1,
max_size=90))
def test_resolve_dependencies(self, edges):
dag = DirectedGraph.from_edges(edges)
if DirectedGraph.is_cyclic(dag):
with self.assertRaises(CyclicDependencyError):
_ = EOWorkflow._resolve_dependencies(dag)
else:
ver2pos = {u: i for i, u in enumerate(EOWorkflow._resolve_dependencies(dag))}
self.assertTrue(functools.reduce(
lambda P, Q: P and Q,
[ver2pos[u] < ver2pos[v] for u, v in edges]
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment