Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create property-based tests for shortest paths algorithms #12

Closed
pnevyk opened this issue Feb 6, 2022 · 2 comments · Fixed by #88
Closed

Create property-based tests for shortest paths algorithms #12

pnevyk opened this issue Feb 6, 2022 · 2 comments · Fixed by #88
Labels
good first issue Good for newcomers

Comments

@pnevyk
Copy link
Owner

pnevyk commented Feb 6, 2022

Create proptest tests for ShortestPaths using our graph generation strategies strategies. Test both algorithms (Dijkstra, Bellman-Ford). Use DebugGraph as the graph being generated because it provides very useful information in case of a failed assert.

What properties to test? One possibility is to implement a function for removing isolated vertices from a graph so that the tested graphs are connected. Then, For connected graphs after finishing an algorithm, it should be possible to reconstruct path and get distance from every vertex in the graph to the starting vertex. Also, the distances (not the paths, generally) should be equal as returned by Dijkstra and Bellman-Ford.

@pnevyk pnevyk added the good first issue Good for newcomers label Feb 6, 2022
@pnevyk
Copy link
Owner Author

pnevyk commented Mar 12, 2023

Update after #46:

  • The proptests should look similarly to those for toposort

    gryf/src/algo/toposort.rs

    Lines 269 to 297 in 4518875

    proptest! {
    #[test]
    #[cfg_attr(not(proptest), ignore = "compile with --cfg proptest")]
    fn toposort_dfs_acyclic(graph in graph_directed(any::<()>(), any::<()>()).acyclic()) {
    let toposort = TopoSort::on(&graph).with(Algo::Dfs).run();
    assert_valid(toposort, &graph);
    }
    #[test]
    #[cfg_attr(not(proptest), ignore = "compile with --cfg proptest")]
    fn toposort_dfs_any(graph in graph_directed(any::<()>(), any::<()>())) {
    let toposort = TopoSort::on(&graph).with(Algo::Dfs).run();
    assert_valid(toposort, &graph);
    }
    #[test]
    #[cfg_attr(not(proptest), ignore = "compile with --cfg proptest")]
    fn toposort_kahn_acyclic(graph in graph_directed(any::<()>(), any::<()>()).acyclic()) {
    let toposort = TopoSort::on(&graph).with(Algo::Kahn).run();
    assert_valid(toposort, &graph);
    }
    #[test]
    #[cfg_attr(not(proptest), ignore = "compile with --cfg proptest")]
    fn toposort_kahn_any(graph in graph_directed(any::<()>(), any::<()>())) {
    let toposort = TopoSort::on(&graph).with(Algo::Kahn).run();
    assert_valid(toposort, &graph);
    }
    }
    .
  • It is possible to request for generated graphs to be connected, but this feature is not implemented yet

    gryf/src/infra/proptest.rs

    Lines 322 to 327 in 4518875

    if self.params.connected {
    panic!("connected graphs are not supported yet");
    // TODO: Identify all connected components and connect these
    // components with new edges.
    }
    (might be a part of this ticket).

@pnevyk
Copy link
Owner Author

pnevyk commented May 22, 2023

In #64 I added proptests that at least check that the algorithms do not panic. But the properties mentioned in the original post in this issue should still be added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant