From 813c63a4eaf811b49aab9e588fceea9bf21706ad Mon Sep 17 00:00:00 2001 From: stefiosif Date: Wed, 21 Sep 2022 19:32:57 +0300 Subject: [PATCH] Add unit test for SCC::normalize --- test/graph_test.cc | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/test/graph_test.cc b/test/graph_test.cc index 5c8be0d..01fc995 100644 --- a/test/graph_test.cc +++ b/test/graph_test.cc @@ -1,6 +1,5 @@ #include -#include "graph/scc.h" #include "algorithm/tarjan.h" #include @@ -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 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(G.adjMatrix).execute(); + + std::vector> 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); + } + } } \ No newline at end of file