diff --git a/test/algorithm_test.cc b/test/algorithm_test.cc index 30d67dd..c374972 100644 --- a/test/algorithm_test.cc +++ b/test/algorithm_test.cc @@ -1,10 +1,7 @@ #include -#include "graph/digraph.h" -#include "graph/scc.h" #include "algorithm/tarjan.h" -#include "algorithm/bfs.h" -#include "algorithm/decremental_scc.h" +#include "algorithm/breadth_first_search.h" using namespace graph; @@ -30,7 +27,7 @@ TEST_SUITE("Algorithm") { REQUIRE_EQ(G.vertices.size(), 9); algo::Tarjan tarjan(G); - auto res = tarjan.findSCC(); + auto res = tarjan.execute(); std::vector> exp = { {6, 8, 9}, @@ -63,7 +60,7 @@ TEST_SUITE("Algorithm") { REQUIRE_EQ(G.vertices.size(), 7); algo::Tarjan tarjan(G); - auto res = tarjan.findSCC(); + auto res = tarjan.execute(); std::vector> exp = { {2, 5, 7}, @@ -92,8 +89,8 @@ TEST_SUITE("Algorithm") { G.insert(6, 3); G.insert(7, 2); - algo::BFS bfs(G); - auto tree = bfs.run(1); + algo::BreadthFirstSearch bfs(G); + auto tree = bfs.execute(1); /*std::map> exp = { {1, {2, 4}}, @@ -115,36 +112,31 @@ TEST_SUITE("Algorithm") { CHECK_EQ(tree, exp); } - TEST_CASE("Roditty Zwick A1 T1 ") { - // 1 --> 2 --> 5 --> 7 --> 2 - // 1 --> 4 --> 3 --> 1 - // 4 --> 6 --> 3 + + + TEST_CASE("BFS") { + // 1 --> 2 --> 3 --> 1 +// 3 --> 4 --> 5 --> 3 +// 2 --> 6 --> 7 --> 8 --> 6 +// 6 --> 9 --> 10 --> 11 --> 12 --> 13 --> 9 +// 12 --> 10 Digraph G; G.insert(1, 2); - G.insert(1, 4); - G.insert(2, 5); + G.insert(2, 3); G.insert(3, 1); - G.insert(4, 3); - G.insert(4, 6); - G.insert(5, 7); - G.insert(6, 3); - G.insert(7, 2); - - algo::DecrementalSCC rz(G); - rz.init(); - - std::vector> exp = { - {2, 5, 7}, - {1, 3, 4, 6} - }; - - CHECK_EQ(rz.query(1, 2), false); - CHECK_EQ(rz.query(1, 3), true); - CHECK_EQ(rz.query(1, 7), false); - CHECK_EQ(rz.query(2, 3), false); - CHECK_EQ(rz.query(2, 5), true); - CHECK_EQ(rz.query(5, 7), true); - - //CHECK_EQ(rz.query(1, 2), true); + G.insert(3, 4); + G.insert(4, 5); + G.insert(5, 3); + G.insert(2, 6); + G.insert(6, 7); + G.insert(7, 8); + G.insert(8, 6); + G.insert(6, 9); + G.insert(9, 10); + G.insert(10, 11); + G.insert(11, 12); + G.insert(12, 13); + G.insert(13, 9); + G.insert(12, 10); } } \ No newline at end of file diff --git a/test/graph_test.cc b/test/graph_test.cc index c6a380e..5593ca9 100644 --- a/test/graph_test.cc +++ b/test/graph_test.cc @@ -1,7 +1,6 @@ #include #include "graph/scc.h" -#include "graph/digraph.h" #include "algorithm/tarjan.h" #include @@ -44,7 +43,6 @@ TEST_SUITE("Graph") { }; CHECK_EQ(RG.adjMatrix, exp); - } TEST_CASE("SCC T1") { @@ -67,7 +65,7 @@ TEST_SUITE("Graph") { REQUIRE_EQ(G.vertices.size(), 9); algo::Tarjan tarjan(G); - auto sccs = tarjan.findSCC(); + auto sccs = tarjan.execute(); } TEST_CASE("SCC T2") { @@ -88,6 +86,37 @@ TEST_SUITE("Graph") { REQUIRE_EQ(G.vertices.size(), 7); algo::Tarjan tarjan(G); - auto sccs = tarjan.findSCC(); + auto sccs = tarjan.execute(); + } + + TEST_CASE("SCC T3") { + // 1 --> 2 --> 3 --> 1 + // 3 --> 4 --> 5 --> 3 + // 2 --> 6 --> 7 --> 8 --> 6 + // 6 --> 9 --> 10 --> 11 --> 12 --> 13 --> 9 + // 12 --> 10 + Digraph G; + G.insert(1, 2); + G.insert(2, 3); + G.insert(3, 1); + G.insert(3, 4); + G.insert(4, 5); + G.insert(5, 3); + G.insert(2, 6); + G.insert(6, 7); + G.insert(7, 8); + G.insert(8, 6); + G.insert(6, 9); + G.insert(9, 10); + G.insert(10, 11); + G.insert(11, 12); + G.insert(12, 13); + G.insert(13, 9); + G.insert(12, 10); + + REQUIRE_EQ(G.vertices.size(), 13); + + algo::Tarjan tarjan(G); + auto sccs = tarjan.execute(); } } \ No newline at end of file diff --git a/test/roditty_zwick_test.cc b/test/roditty_zwick_test.cc new file mode 100644 index 0000000..040557b --- /dev/null +++ b/test/roditty_zwick_test.cc @@ -0,0 +1,43 @@ +#include + +#include "algorithm/decremental_scc.h" +#include "algorithm/decremental_tc.h" + +using namespace graph; + +TEST_SUITE("Roditty and Zwick") { + + TEST_CASE("Roditty Zwick A1 T1 ") { + // 1 --> 2 --> 5 --> 7 --> 2 + // 1 --> 4 --> 3 --> 1 + // 4 --> 6 --> 3 + Digraph G; + G.insert(1, 2); + G.insert(1, 4); + G.insert(2, 5); + G.insert(3, 1); + G.insert(4, 3); + G.insert(4, 6); + G.insert(5, 7); + G.insert(6, 3); + G.insert(7, 2); + + algo::DecrementalSCC rz(G); + rz.init(); + + std::vector> exp = { + {2, 5, 7}, + {1, 3, 4, 6} + }; + + CHECK_EQ(rz.query(1, 2), false); + CHECK_EQ(rz.query(1, 3), true); + CHECK_EQ(rz.query(1, 7), false); + CHECK_EQ(rz.query(2, 3), false); + CHECK_EQ(rz.query(2, 5), true); + CHECK_EQ(rz.query(5, 7), true); + + //CHECK_EQ(rz.query(1, 2), true); + } + +} \ No newline at end of file diff --git a/test/tree_test.cc b/test/tree_test.cc index 30057d8..fb27811 100644 --- a/test/tree_test.cc +++ b/test/tree_test.cc @@ -1,12 +1,7 @@ #include -#include "graph/scc.h" -#include "graph/digraph.h" -#include "algorithm/tarjan.h" #include "tree/breadth_first_tree.h" -#include - using namespace graph; using namespace tree; @@ -27,7 +22,7 @@ TEST_SUITE("Tree") { G.insert(6, 3); G.insert(7, 2); - BreadthFirstTree tree(G); + BreadthFirstTree tree(G, 1); std::map> exp = { {1, {2, 4}},