Add unit test for SCC::normalize

This commit is contained in:
stefiosif
2022-09-21 19:32:57 +03:00
parent 5f9b225609
commit 813c63a4ea

View File

@@ -1,6 +1,5 @@
#include <doctest/doctest.h>
#include "graph/scc.h"
#include "algorithm/tarjan.h"
#include <vector>
@@ -91,4 +90,46 @@ TEST_SUITE("Graph") {
CHECK_EQ(G.V(), 13);
CHECK_EQ(G.E(), 18);
}
TEST_CASE("SCC::normalize") {
// 1 --> 2 --> 4 --> 6 --> 8 --> 9 --> 5
// 4 --> 5 --> 7 --> 8
// 5 --> 6
// 7 --> 9
// 2 --> 3 --> 1
// 3 --> 5
// 3 --> 9
Digraph<std::uint16_t> G;
G.insert(1, 2);
G.insert(2, 4);
G.insert(2, 3);
G.insert(3, 1);
G.insert(3, 5);
G.insert(3, 9);
G.insert(4, 5);
G.insert(4, 6);
G.insert(5, 6);
G.insert(5, 7);
G.insert(6, 8);
G.insert(7, 8);
G.insert(7, 9);
G.insert(8, 9);
G.insert(9, 5);
REQUIRE_EQ(G.adjMatrix.size(), 9);
auto SCCs = algo::Tarjan<std::uint16_t>(G.adjMatrix).execute();
std::vector<std::vector<std::uint16_t>> expected = {
{5, 6, 7, 8, 9},
{4},
{1, 2, 3}
};
for (auto i = 0; i < SCCs.size(); i++) {
auto kv = SCCs[i].vertices();
CHECK_EQ(std::is_permutation(kv.begin(), kv.end(),
expected[i].begin()), true);
}
}
}