Adding DAG visitor and some unit tests around its function

This commit is contained in:
Ian Roddis
2021-06-07 11:54:50 -03:00
parent e36b3a2012
commit 2030368c22
6 changed files with 181 additions and 46 deletions

View File

@@ -1,9 +1,30 @@
#include <iostream>
#include "daggy/DAG.hpp"
#include "daggy/DAGVisitor.hpp"
#include "catch.hpp"
TEST_CASE("DAG Construction Tests", "[dag]") {
daggy::DAG<int> dag;
REQUIRE(dag.size() == 0);
REQUIRE(dag.empty());
REQUIRE_NOTHROW(dag.addVertex(0));
for (int i = 1; i < 10; ++i) {
dag.addVertex(i);
dag.addEdge(i-1, i);
}
REQUIRE(dag.getRoots().size() == 1);
REQUIRE(dag.size() == 10);
REQUIRE(! dag.empty());
// Cannot add an edge that would result in a cycle
REQUIRE_THROWS(dag.addEdge(9, 5));
}
TEST_CASE("DAG Basic Tests", "[dag]") {
daggy::DAG<int> dag;
@@ -13,10 +34,10 @@ TEST_CASE("DAG Basic Tests", "[dag]") {
dag.addEdge(i-1, i);
}
REQUIRE(dag.shortestPath(0,9).size() == 10);
SECTION("Pathing") {
REQUIRE(dag.shortestPath(0,9).size() == 10);
dag.addEdge(5, 9);
REQUIRE(dag.shortestPath(0,9).size() == 7);
REQUIRE_THROWS(dag.addEdge(9, 5));
dag.addEdge(5, 9);
REQUIRE(dag.shortestPath(0,9).size() == 7);
}
}