Add new graph example

This commit is contained in:
stefiosif
2022-07-12 14:44:43 +03:00
parent 601f80c8d4
commit 0f857a6c9e
4 changed files with 105 additions and 46 deletions

View File

@@ -1,7 +1,6 @@
#include <doctest/doctest.h>
#include "graph/scc.h"
#include "graph/digraph.h"
#include "algorithm/tarjan.h"
#include <vector>
@@ -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<std::uint16_t> 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<std::uint16_t> 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<std::uint16_t> 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<std::uint16_t> tarjan(G);
auto sccs = tarjan.execute();
}
}