diff --git a/CMakeLists.txt b/CMakeLists.txt index 6519c40..2061569 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,8 +2,10 @@ cmake_minimum_required(VERSION 3.14) project(graphs) find_package(Boost REQUIRED) +find_package(GTest REQUIRED) include(CTest) +include(GoogleTest) add_library(graphs INTERFACE) target_include_directories(graphs INTERFACE include) diff --git a/conan.lock b/conan.lock index 16d03a2..73ebb1a 100644 --- a/conan.lock +++ b/conan.lock @@ -3,10 +3,12 @@ "requires": [ "zlib/1.3.1#b8bc2603263cf7eccbd6e17e66b0ed76%1733936244.862", "libbacktrace/cci.20210118#a7691bfccd8caaf66309df196790a5a1%1722218217.276", + "gtest/1.17.0#5224b3b3ff3b4ce1133cbdd27d53ee7d%1755784855.585", "bzip2/1.0.8#d00dac990f08d991998d624be81a9526%1724661266.998", "boost/1.86.0#0675eb54da69d8eed264eb22203a7117%1761059017.02" ], "build_requires": [ + "cmake/4.2.0#ae0a44f44a1ef9ab68fd4b3e9a1f8671%1764093466.37", "b2/5.2.1#91bc73931a0acb655947a81569ed8b80%1718416612.241" ], "python_requires": [], diff --git a/conanfile.txt b/conanfile.txt index 4693463..3a8224f 100644 --- a/conanfile.txt +++ b/conanfile.txt @@ -1,5 +1,6 @@ [requires] boost/1.86.0 +gtest/1.17.0 [generators] CMakeDeps diff --git a/include/graphs/graph.hh b/include/graphs/graph.hh index 709cc36..3f430c3 100644 --- a/include/graphs/graph.hh +++ b/include/graphs/graph.hh @@ -2,8 +2,7 @@ #include #include -#include -#include +#include #include #include @@ -12,42 +11,144 @@ namespace graph { template class Graph final { public: + using AdjMap = std::unordered_map>; + + Graph() noexcept = default; + + Graph( + std::initializer_list>> adj_list) { + for (const auto& [v, a] : adj_list) { + insert(v, std::vector(a)); + } + } + bool insert(const T& v, const std::vector& adj) { - vertices_.insert(v); + auto it = adj_list_.find(v); + if (it != adj_list_.end()) { + return false; + } + for (const auto& a : adj) { - vertices_.insert(a); + auto it = adj_list_.find(a); + ++in_deg_[a]; + out_deg_.emplace(a, 0); } - return adj_list_.insert({v, adj}).second; + in_deg_.emplace(v, 0); + out_deg_[v] = adj.size(); + adj_list_.emplace(v, adj); + return true; } - void dump() const { + std::vector topologicalSort() const { + std::vector order; + std::queue q; + + for (auto& [u, cnt] : in_deg_) { + if (cnt == 0) { + q.push(u); + } + } + + order.reserve(in_deg_.size()); + auto id = in_deg_; + + while (!q.empty()) { + T u = q.front(); + q.pop(); + + order.push_back(u); + + auto it = adj_list_.find(u); + + if (it != adj_list_.end()) { + for (auto& v : it->second) { + if (--id[v] == 0) { + q.push(v); + } + } + } + } + + if (order.size() != in_deg_.size()) { + throw std::runtime_error("Graph has cycle"); + } + return order; + } + + void dump(std::ostream& os) const { using namespace boost; using OutGraph = adjacency_list, property>; + OutGraph g; + auto start = add_vertex(g); + auto end = add_vertex(g); + put(vertex_name, g, start, "Start"); + put(vertex_name, g, end, "End"); + std::unordered_map vd; - vd.reserve(adj_list_.size()); - for (const auto& v : vertices_) { + vd.reserve(in_deg_.size()); + for (const auto& [v, _] : in_deg_) { auto d = add_vertex(g); put(vertex_name, g, d, std::to_string(v)); - vd.insert({v, d}); + vd.emplace(v, d); + } + + for (const auto& [v, cnt] : in_deg_) { + if (cnt == 0) { + add_edge(start, vd[v], g); + } } - for (auto& [v, adj] : adj_list_) { + for (const auto& [v, cnt] : out_deg_) { + if (cnt == 0) { + add_edge(vd[v], end, g); + } + } + + for (const auto& [v, adj] : adj_list_) { for (const auto& a : adj) { add_edge(vd[v], vd[a], g); } } - write_graphviz(std::cout, g, make_label_writer(get(vertex_name, g))); + write_graphviz(os, g, make_label_writer(get(vertex_name, g))); } private: - std::unordered_map> adj_list_; - std::unordered_set vertices_; + AdjMap adj_list_; + + using DegreeMap = std::unordered_map; + DegreeMap in_deg_; + DegreeMap out_deg_; }; + +template +inline Graph readGraph(std::istream& is) { + graph::Graph g; + + std::string line; + while (std::getline(is, line)) { + if (line.empty()) { + break; + } + + std::istringstream ss(line); + T u; + ss >> u; + + std::vector adj; + T v; + while (ss >> v) { + adj.push_back(v); + } + g.insert(u, adj); + } + + return g; +} } // namespace graph diff --git a/src/main.cc b/src/main.cc index bb0efdf..a6d0a52 100644 --- a/src/main.cc +++ b/src/main.cc @@ -35,28 +35,8 @@ int main(int argc, char** argv) try { return 0; } - graph::Graph g; - - std::string line; - while (std::getline(std::cin, line)) { - if (line.empty()) { - break; - } - - std::istringstream ss(line); - std::size_t u; - ss >> u; - - std::vector adj; - std::size_t v; - while (ss >> v) { - adj.push_back(v); - } - - g.insert(u, adj); - } - - g.dump(); + auto g = graph::readGraph(std::cin); + g.dump(std::cout); return 0; } catch (std::exception& e) { std::cerr << e.what() << std::endl; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index dc09882..f7b9078 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,2 +1,7 @@ add_test(NAME GraphvizOutputTest COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/run_tests.py --executable $) + +add_executable(unit_test unit_tests.cc) +target_link_libraries(unit_test gtest::gtest graphs) + +gtest_discover_tests(unit_test) diff --git a/tests/in/2.in b/tests/in/2.in new file mode 100644 index 0000000..bb886ce --- /dev/null +++ b/tests/in/2.in @@ -0,0 +1,24 @@ +1 2 6 +2 3 7 +3 4 8 +4 5 9 +5 10 +6 7 11 +7 8 12 +8 9 13 +9 10 14 +10 15 +11 12 16 +12 13 17 +13 14 18 +14 15 19 +15 20 +16 17 21 +17 18 22 +18 19 23 +19 20 24 +20 25 +21 22 +22 23 +23 24 +24 25 diff --git a/tests/in/3.in b/tests/in/3.in new file mode 100644 index 0000000..f8a828b --- /dev/null +++ b/tests/in/3.in @@ -0,0 +1,7 @@ +1 2 3 +2 4 5 +3 6 7 +4 8 9 +5 10 11 +6 12 13 +7 14 15 diff --git a/tests/in/4.in b/tests/in/4.in new file mode 100644 index 0000000..af1036e --- /dev/null +++ b/tests/in/4.in @@ -0,0 +1,19 @@ +1 2 11 +2 3 12 +3 4 13 +4 5 14 +5 6 15 +6 7 16 +7 8 17 +8 9 18 +9 10 19 +10 20 +11 12 +12 13 +13 14 +14 15 +15 16 +16 17 +17 18 +18 19 +19 20 diff --git a/tests/in/5.in b/tests/in/5.in new file mode 100644 index 0000000..6de28de --- /dev/null +++ b/tests/in/5.in @@ -0,0 +1,137 @@ +1 2 3 4 +2 5 6 7 +3 8 9 10 +4 11 12 13 +5 14 15 16 +6 15 16 17 +7 17 18 19 +8 19 20 21 +9 20 21 22 +10 22 23 24 +11 24 25 26 +12 25 26 27 +13 27 28 +14 29 30 31 +15 30 31 32 +16 32 33 34 +17 33 34 35 +18 35 36 37 +19 36 37 38 +20 37 38 39 +21 38 39 40 +22 39 40 41 +23 40 41 42 +24 41 42 43 +25 42 43 44 +26 43 44 45 +27 44 45 46 +28 46 47 48 +29 47 48 49 +30 48 49 50 +31 49 50 51 +32 50 51 52 +33 51 52 53 +34 52 53 54 +35 53 54 55 +36 54 55 56 +37 55 56 57 +38 56 57 58 +39 57 58 59 +40 58 59 60 +41 59 60 61 +42 60 61 62 +43 61 62 63 +44 62 63 64 +45 63 64 65 +46 64 65 66 +47 65 66 67 +48 66 67 68 +49 67 68 69 +50 68 69 70 +51 69 70 71 +52 70 71 72 +53 71 72 73 +54 72 73 74 +55 73 74 75 +56 74 75 76 +57 75 76 77 +58 76 77 78 +59 77 78 79 +60 78 79 80 +61 79 80 81 +62 80 81 82 +63 81 82 83 +64 82 83 84 +65 83 84 85 +66 84 85 86 +67 85 86 87 +68 86 87 88 +69 87 88 89 +70 88 89 90 +71 89 90 91 +72 90 91 92 +73 91 92 93 +74 92 93 94 +75 93 94 95 +76 94 95 96 +77 95 96 97 +78 96 97 98 +79 97 98 99 +80 98 99 100 +81 99 100 101 +82 100 101 102 +83 101 102 103 +84 102 103 104 +85 103 104 105 +86 104 105 106 +87 105 106 107 +88 106 107 108 +89 107 108 109 +90 108 109 110 +91 109 110 111 +92 110 111 112 +93 111 112 113 +94 112 113 114 +95 113 114 115 +96 114 115 116 +97 115 116 117 +98 116 117 118 +99 117 118 119 +100 118 119 120 +101 119 120 121 +102 120 121 122 +103 121 122 123 +104 122 123 124 +105 123 124 125 +106 124 125 126 +107 125 126 127 +108 126 127 128 +109 127 128 129 +110 128 129 130 +111 129 130 131 +112 130 131 132 +113 131 132 133 +114 132 133 134 +115 133 134 135 +116 134 135 136 +117 135 136 137 +118 136 137 +119 136 137 +120 136 137 +121 136 137 +122 136 137 +123 136 137 +124 136 137 +125 136 137 +126 136 137 +127 136 137 +128 136 137 +129 136 137 +130 136 137 +131 136 137 +132 136 137 +133 137 +134 +135 +136 +137 diff --git a/tests/in/6.in b/tests/in/6.in new file mode 100644 index 0000000..4fe892c --- /dev/null +++ b/tests/in/6.in @@ -0,0 +1,241 @@ +1 4 5 6 +2 6 7 8 +3 8 9 +4 10 11 12 +5 12 13 14 +6 14 15 16 +7 16 17 18 +8 18 19 20 +9 20 21 +10 22 23 +11 24 25 26 +12 25 26 27 +13 27 28 +14 29 30 31 +15 30 31 32 +16 32 33 34 +17 33 34 35 +18 35 36 37 +19 36 37 38 +20 37 38 39 +21 38 39 40 +22 39 40 41 +23 40 41 42 +24 41 42 43 +25 42 43 44 +26 43 44 45 +27 44 45 46 +28 46 47 48 +29 47 48 49 +30 48 49 50 +31 49 50 51 +32 50 51 52 +33 51 52 53 +34 52 53 54 +35 53 54 55 +36 54 55 56 +37 55 56 57 +38 56 57 58 +39 57 58 59 +40 58 59 60 +41 59 60 61 +42 60 61 62 +43 61 62 63 +44 62 63 64 +45 63 64 65 +46 64 65 66 +47 65 66 67 +48 66 67 68 +49 67 68 69 +50 68 69 70 +51 69 70 71 +52 70 71 72 +53 71 72 73 +54 72 73 74 +55 73 74 75 +56 74 75 76 +57 75 76 77 +58 76 77 78 +59 77 78 79 +60 78 79 80 +61 79 80 81 +62 80 81 82 +63 81 82 83 +64 82 83 84 +65 83 84 85 +66 84 85 86 +67 85 86 87 +68 86 87 88 +69 87 88 89 +70 88 89 90 +71 89 90 91 +72 90 91 92 +73 91 92 93 +74 92 93 94 +75 93 94 95 +76 94 95 96 +77 95 96 97 +78 96 97 98 +79 97 98 99 +80 98 99 100 +81 99 100 101 +82 100 101 102 +83 101 102 103 +84 102 103 104 +85 103 104 105 +86 104 105 106 +87 105 106 107 +88 106 107 108 +89 107 108 109 +90 108 109 110 +91 109 110 111 +92 110 111 112 +93 111 112 113 +94 112 113 114 +95 113 114 115 +96 114 115 116 +97 115 116 117 +98 116 117 118 +99 117 118 119 +100 118 119 120 +101 119 120 121 +102 120 121 122 +103 121 122 123 +104 122 123 124 +105 123 124 125 +106 124 125 126 +107 125 126 127 +108 126 127 128 +109 127 128 129 +110 128 129 130 +111 129 130 131 +112 130 131 132 +113 131 132 133 +114 132 133 134 +115 133 134 135 +116 134 135 136 +117 135 136 137 +118 136 137 +119 136 137 +120 136 137 +121 136 137 +122 136 137 +123 136 137 +124 136 137 +125 136 137 +126 136 137 +127 136 137 +128 136 137 +129 136 137 +130 136 137 +131 136 137 +132 136 137 +133 137 +134 +135 +136 +137 +138 139 140 +139 141 142 +140 142 143 +141 143 144 +142 144 145 +143 145 146 +144 146 147 +145 147 148 +146 148 149 +147 149 150 +148 150 151 +149 151 152 +150 152 153 +151 153 154 +152 154 155 +153 155 156 +154 156 157 +155 157 158 +156 158 159 +157 159 160 +158 160 161 +159 161 162 +160 162 163 +161 163 164 +162 164 165 +163 165 166 +164 166 167 +165 167 168 +166 168 169 +167 169 170 +168 170 171 +169 171 172 +170 172 173 +171 173 174 +172 174 175 +173 175 176 +174 176 177 +175 177 178 +176 178 179 +177 179 180 +178 180 181 +179 181 182 +180 182 183 +181 183 184 +182 184 185 +183 185 186 +184 186 187 +185 187 188 +186 188 189 +187 189 190 +188 190 191 +189 191 192 +190 192 193 +191 193 194 +192 194 195 +193 195 196 +194 196 197 +195 197 198 +196 198 199 +197 199 200 +198 200 201 +199 201 202 +200 202 203 +201 203 204 +202 204 205 +203 205 206 +204 206 207 +205 207 208 +206 208 209 +207 209 210 +208 210 211 +209 211 212 +210 212 213 +211 213 214 +212 214 215 +213 215 216 +214 216 217 +215 217 218 +216 218 219 +217 219 220 +218 220 221 +219 221 222 +220 222 223 +221 223 224 +222 224 225 +223 225 226 +224 226 227 +225 227 228 +226 228 229 +227 229 230 +228 230 231 +229 231 232 +230 232 233 +231 233 234 +232 234 235 +233 235 236 +234 +235 +236 +237 +238 +239 +240 +241 diff --git a/tests/in/7.in b/tests/in/7.in new file mode 100644 index 0000000..2b3ea1f --- /dev/null +++ b/tests/in/7.in @@ -0,0 +1,3 @@ +1 2 +2 3 +3 4 diff --git a/tests/in/8.in b/tests/in/8.in new file mode 100644 index 0000000..7d783d0 --- /dev/null +++ b/tests/in/8.in @@ -0,0 +1,30 @@ +1 5 6 +2 6 7 +3 7 8 +4 8 9 +5 10 +6 10 11 +7 11 12 +8 12 13 +9 13 14 +10 15 +11 15 16 +12 16 17 +13 17 18 +14 18 19 +15 20 +16 20 21 +17 21 22 +18 22 23 +19 23 24 +20 25 +21 25 26 +22 26 27 +23 27 28 +24 28 29 +25 30 +26 30 +27 30 +28 30 +29 30 +30 diff --git a/tests/out/1.dot b/tests/out/1.dot index 38580c9..de9caed 100644 --- a/tests/out/1.dot +++ b/tests/out/1.dot @@ -1,12 +1,17 @@ digraph G { -0[label=9]; -1[label=2]; -2[label=7]; -3[label=5]; -4[label=3]; -2->0 ; -3->0 ; -4->3 ; -4->2 ; +0[label=Start]; +1[label=End]; +2[label=9]; +3[label=3]; +4[label=2]; +5[label=7]; +6[label=5]; +0->3 ; +2->1 ; +3->6 ; +3->5 ; +3->4 ; 4->1 ; +5->2 ; +6->2 ; } diff --git a/tests/out/2.dot b/tests/out/2.dot new file mode 100644 index 0000000..0c15d86 --- /dev/null +++ b/tests/out/2.dot @@ -0,0 +1,71 @@ +digraph G { +0[label=Start]; +1[label=End]; +2[label=25]; +3[label=24]; +4[label=23]; +5[label=22]; +6[label=21]; +7[label=20]; +8[label=19]; +9[label=18]; +10[label=17]; +11[label=16]; +12[label=15]; +13[label=14]; +14[label=2]; +15[label=6]; +16[label=1]; +17[label=3]; +18[label=7]; +19[label=4]; +20[label=8]; +21[label=5]; +22[label=9]; +23[label=10]; +24[label=11]; +25[label=12]; +26[label=13]; +0->16 ; +2->1 ; +3->2 ; +4->3 ; +5->4 ; +6->5 ; +7->2 ; +8->7 ; +8->3 ; +9->8 ; +9->4 ; +10->9 ; +10->5 ; +11->10 ; +11->6 ; +12->7 ; +13->12 ; +13->8 ; +14->17 ; +14->18 ; +15->18 ; +15->24 ; +16->14 ; +16->15 ; +17->19 ; +17->20 ; +18->20 ; +18->25 ; +19->21 ; +19->22 ; +20->22 ; +20->26 ; +21->23 ; +22->23 ; +22->13 ; +23->12 ; +24->25 ; +24->11 ; +25->26 ; +25->10 ; +26->13 ; +26->9 ; +} diff --git a/tests/out/3.dot b/tests/out/3.dot new file mode 100644 index 0000000..c3e7df7 --- /dev/null +++ b/tests/out/3.dot @@ -0,0 +1,42 @@ +digraph G { +0[label=Start]; +1[label=End]; +2[label=15]; +3[label=14]; +4[label=2]; +5[label=3]; +6[label=1]; +7[label=4]; +8[label=5]; +9[label=6]; +10[label=7]; +11[label=8]; +12[label=9]; +13[label=10]; +14[label=11]; +15[label=12]; +16[label=13]; +0->6 ; +2->1 ; +3->1 ; +4->7 ; +4->8 ; +5->9 ; +5->10 ; +6->4 ; +6->5 ; +7->11 ; +7->12 ; +8->13 ; +8->14 ; +9->15 ; +9->16 ; +10->3 ; +10->2 ; +11->1 ; +12->1 ; +13->1 ; +14->1 ; +15->1 ; +16->1 ; +} diff --git a/tests/out/4.dot b/tests/out/4.dot new file mode 100644 index 0000000..b8bab33 --- /dev/null +++ b/tests/out/4.dot @@ -0,0 +1,54 @@ +digraph G { +0[label=Start]; +1[label=End]; +2[label=20]; +3[label=19]; +4[label=10]; +5[label=18]; +6[label=9]; +7[label=17]; +8[label=8]; +9[label=2]; +10[label=15]; +11[label=11]; +12[label=1]; +13[label=14]; +14[label=3]; +15[label=16]; +16[label=12]; +17[label=4]; +18[label=13]; +19[label=5]; +20[label=6]; +21[label=7]; +0->12 ; +2->1 ; +3->2 ; +4->2 ; +5->3 ; +6->4 ; +6->3 ; +7->5 ; +8->6 ; +8->5 ; +9->14 ; +9->16 ; +10->15 ; +11->16 ; +12->9 ; +12->11 ; +13->10 ; +14->17 ; +14->18 ; +15->7 ; +16->18 ; +17->19 ; +17->13 ; +18->13 ; +19->20 ; +19->10 ; +20->21 ; +20->15 ; +21->8 ; +21->7 ; +} diff --git a/tests/out/5.dot b/tests/out/5.dot new file mode 100644 index 0000000..1850c7d --- /dev/null +++ b/tests/out/5.dot @@ -0,0 +1,527 @@ +digraph G { +0[label=Start]; +1[label=End]; +2[label=137]; +3[label=136]; +4[label=135]; +5[label=134]; +6[label=133]; +7[label=132]; +8[label=131]; +9[label=130]; +10[label=129]; +11[label=128]; +12[label=59]; +13[label=58]; +14[label=57]; +15[label=56]; +16[label=55]; +17[label=54]; +18[label=53]; +19[label=52]; +20[label=51]; +21[label=50]; +22[label=49]; +23[label=48]; +24[label=47]; +25[label=46]; +26[label=45]; +27[label=44]; +28[label=43]; +29[label=42]; +30[label=41]; +31[label=40]; +32[label=39]; +33[label=38]; +34[label=37]; +35[label=36]; +36[label=35]; +37[label=34]; +38[label=33]; +39[label=32]; +40[label=31]; +41[label=30]; +42[label=13]; +43[label=12]; +44[label=11]; +45[label=10]; +46[label=9]; +47[label=8]; +48[label=7]; +49[label=6]; +50[label=5]; +51[label=1]; +52[label=4]; +53[label=3]; +54[label=2]; +55[label=14]; +56[label=15]; +57[label=16]; +58[label=17]; +59[label=18]; +60[label=19]; +61[label=20]; +62[label=21]; +63[label=22]; +64[label=23]; +65[label=24]; +66[label=25]; +67[label=26]; +68[label=27]; +69[label=28]; +70[label=29]; +71[label=60]; +72[label=61]; +73[label=62]; +74[label=63]; +75[label=64]; +76[label=65]; +77[label=66]; +78[label=67]; +79[label=68]; +80[label=69]; +81[label=70]; +82[label=71]; +83[label=72]; +84[label=73]; +85[label=74]; +86[label=75]; +87[label=76]; +88[label=77]; +89[label=78]; +90[label=79]; +91[label=80]; +92[label=81]; +93[label=82]; +94[label=83]; +95[label=84]; +96[label=85]; +97[label=86]; +98[label=87]; +99[label=88]; +100[label=89]; +101[label=90]; +102[label=91]; +103[label=92]; +104[label=93]; +105[label=94]; +106[label=95]; +107[label=96]; +108[label=97]; +109[label=98]; +110[label=99]; +111[label=100]; +112[label=101]; +113[label=102]; +114[label=103]; +115[label=104]; +116[label=105]; +117[label=106]; +118[label=107]; +119[label=108]; +120[label=109]; +121[label=110]; +122[label=111]; +123[label=112]; +124[label=113]; +125[label=114]; +126[label=115]; +127[label=116]; +128[label=117]; +129[label=118]; +130[label=119]; +131[label=120]; +132[label=121]; +133[label=122]; +134[label=123]; +135[label=124]; +136[label=125]; +137[label=126]; +138[label=127]; +0->51 ; +2->1 ; +3->1 ; +4->1 ; +5->1 ; +6->2 ; +7->3 ; +7->2 ; +8->3 ; +8->2 ; +9->3 ; +9->2 ; +10->3 ; +10->2 ; +11->3 ; +11->2 ; +12->88 ; +12->89 ; +12->90 ; +13->87 ; +13->88 ; +13->89 ; +14->86 ; +14->87 ; +14->88 ; +15->85 ; +15->86 ; +15->87 ; +16->84 ; +16->85 ; +16->86 ; +17->83 ; +17->84 ; +17->85 ; +18->82 ; +18->83 ; +18->84 ; +19->81 ; +19->82 ; +19->83 ; +20->80 ; +20->81 ; +20->82 ; +21->79 ; +21->80 ; +21->81 ; +22->78 ; +22->79 ; +22->80 ; +23->77 ; +23->78 ; +23->79 ; +24->76 ; +24->77 ; +24->78 ; +25->75 ; +25->76 ; +25->77 ; +26->74 ; +26->75 ; +26->76 ; +27->73 ; +27->74 ; +27->75 ; +28->72 ; +28->73 ; +28->74 ; +29->71 ; +29->72 ; +29->73 ; +30->12 ; +30->71 ; +30->72 ; +31->13 ; +31->12 ; +31->71 ; +32->14 ; +32->13 ; +32->12 ; +33->15 ; +33->14 ; +33->13 ; +34->16 ; +34->15 ; +34->14 ; +35->17 ; +35->16 ; +35->15 ; +36->18 ; +36->17 ; +36->16 ; +37->19 ; +37->18 ; +37->17 ; +38->20 ; +38->19 ; +38->18 ; +39->21 ; +39->20 ; +39->19 ; +40->22 ; +40->21 ; +40->20 ; +41->23 ; +41->22 ; +41->21 ; +42->68 ; +42->69 ; +43->66 ; +43->67 ; +43->68 ; +44->65 ; +44->66 ; +44->67 ; +45->63 ; +45->64 ; +45->65 ; +46->61 ; +46->62 ; +46->63 ; +47->60 ; +47->61 ; +47->62 ; +48->58 ; +48->59 ; +48->60 ; +49->56 ; +49->57 ; +49->58 ; +50->55 ; +50->56 ; +50->57 ; +51->54 ; +51->53 ; +51->52 ; +52->44 ; +52->43 ; +52->42 ; +53->47 ; +53->46 ; +53->45 ; +54->50 ; +54->49 ; +54->48 ; +55->70 ; +55->41 ; +55->40 ; +56->41 ; +56->40 ; +56->39 ; +57->39 ; +57->38 ; +57->37 ; +58->38 ; +58->37 ; +58->36 ; +59->36 ; +59->35 ; +59->34 ; +60->35 ; +60->34 ; +60->33 ; +61->34 ; +61->33 ; +61->32 ; +62->33 ; +62->32 ; +62->31 ; +63->32 ; +63->31 ; +63->30 ; +64->31 ; +64->30 ; +64->29 ; +65->30 ; +65->29 ; +65->28 ; +66->29 ; +66->28 ; +66->27 ; +67->28 ; +67->27 ; +67->26 ; +68->27 ; +68->26 ; +68->25 ; +69->25 ; +69->24 ; +69->23 ; +70->24 ; +70->23 ; +70->22 ; +71->89 ; +71->90 ; +71->91 ; +72->90 ; +72->91 ; +72->92 ; +73->91 ; +73->92 ; +73->93 ; +74->92 ; +74->93 ; +74->94 ; +75->93 ; +75->94 ; +75->95 ; +76->94 ; +76->95 ; +76->96 ; +77->95 ; +77->96 ; +77->97 ; +78->96 ; +78->97 ; +78->98 ; +79->97 ; +79->98 ; +79->99 ; +80->98 ; +80->99 ; +80->100 ; +81->99 ; +81->100 ; +81->101 ; +82->100 ; +82->101 ; +82->102 ; +83->101 ; +83->102 ; +83->103 ; +84->102 ; +84->103 ; +84->104 ; +85->103 ; +85->104 ; +85->105 ; +86->104 ; +86->105 ; +86->106 ; +87->105 ; +87->106 ; +87->107 ; +88->106 ; +88->107 ; +88->108 ; +89->107 ; +89->108 ; +89->109 ; +90->108 ; +90->109 ; +90->110 ; +91->109 ; +91->110 ; +91->111 ; +92->110 ; +92->111 ; +92->112 ; +93->111 ; +93->112 ; +93->113 ; +94->112 ; +94->113 ; +94->114 ; +95->113 ; +95->114 ; +95->115 ; +96->114 ; +96->115 ; +96->116 ; +97->115 ; +97->116 ; +97->117 ; +98->116 ; +98->117 ; +98->118 ; +99->117 ; +99->118 ; +99->119 ; +100->118 ; +100->119 ; +100->120 ; +101->119 ; +101->120 ; +101->121 ; +102->120 ; +102->121 ; +102->122 ; +103->121 ; +103->122 ; +103->123 ; +104->122 ; +104->123 ; +104->124 ; +105->123 ; +105->124 ; +105->125 ; +106->124 ; +106->125 ; +106->126 ; +107->125 ; +107->126 ; +107->127 ; +108->126 ; +108->127 ; +108->128 ; +109->127 ; +109->128 ; +109->129 ; +110->128 ; +110->129 ; +110->130 ; +111->129 ; +111->130 ; +111->131 ; +112->130 ; +112->131 ; +112->132 ; +113->131 ; +113->132 ; +113->133 ; +114->132 ; +114->133 ; +114->134 ; +115->133 ; +115->134 ; +115->135 ; +116->134 ; +116->135 ; +116->136 ; +117->135 ; +117->136 ; +117->137 ; +118->136 ; +118->137 ; +118->138 ; +119->137 ; +119->138 ; +119->11 ; +120->138 ; +120->11 ; +120->10 ; +121->11 ; +121->10 ; +121->9 ; +122->10 ; +122->9 ; +122->8 ; +123->9 ; +123->8 ; +123->7 ; +124->8 ; +124->7 ; +124->6 ; +125->7 ; +125->6 ; +125->5 ; +126->6 ; +126->5 ; +126->4 ; +127->5 ; +127->4 ; +127->3 ; +128->4 ; +128->3 ; +128->2 ; +129->3 ; +129->2 ; +130->3 ; +130->2 ; +131->3 ; +131->2 ; +132->3 ; +132->2 ; +133->3 ; +133->2 ; +134->3 ; +134->2 ; +135->3 ; +135->2 ; +136->3 ; +136->2 ; +137->3 ; +137->2 ; +138->3 ; +138->2 ; +} diff --git a/tests/out/6.dot b/tests/out/6.dot new file mode 100644 index 0000000..28324a6 --- /dev/null +++ b/tests/out/6.dot @@ -0,0 +1,836 @@ +digraph G { +0[label=Start]; +1[label=End]; +2[label=241]; +3[label=240]; +4[label=239]; +5[label=238]; +6[label=237]; +7[label=236]; +8[label=235]; +9[label=234]; +10[label=233]; +11[label=232]; +12[label=231]; +13[label=230]; +14[label=229]; +15[label=228]; +16[label=227]; +17[label=226]; +18[label=225]; +19[label=224]; +20[label=223]; +21[label=222]; +22[label=221]; +23[label=220]; +24[label=219]; +25[label=218]; +26[label=217]; +27[label=216]; +28[label=215]; +29[label=214]; +30[label=213]; +31[label=212]; +32[label=211]; +33[label=210]; +34[label=209]; +35[label=208]; +36[label=207]; +37[label=206]; +38[label=205]; +39[label=204]; +40[label=203]; +41[label=202]; +42[label=201]; +43[label=200]; +44[label=199]; +45[label=198]; +46[label=197]; +47[label=196]; +48[label=195]; +49[label=194]; +50[label=193]; +51[label=192]; +52[label=191]; +53[label=190]; +54[label=189]; +55[label=188]; +56[label=187]; +57[label=186]; +58[label=185]; +59[label=184]; +60[label=183]; +61[label=182]; +62[label=181]; +63[label=180]; +64[label=179]; +65[label=178]; +66[label=177]; +67[label=176]; +68[label=175]; +69[label=174]; +70[label=173]; +71[label=172]; +72[label=171]; +73[label=170]; +74[label=169]; +75[label=168]; +76[label=167]; +77[label=166]; +78[label=165]; +79[label=164]; +80[label=163]; +81[label=162]; +82[label=161]; +83[label=160]; +84[label=159]; +85[label=158]; +86[label=157]; +87[label=156]; +88[label=155]; +89[label=154]; +90[label=153]; +91[label=152]; +92[label=151]; +93[label=150]; +94[label=149]; +95[label=148]; +96[label=147]; +97[label=146]; +98[label=145]; +99[label=144]; +100[label=143]; +101[label=142]; +102[label=141]; +103[label=138]; +104[label=140]; +105[label=139]; +106[label=137]; +107[label=136]; +108[label=135]; +109[label=134]; +110[label=133]; +111[label=132]; +112[label=131]; +113[label=130]; +114[label=129]; +115[label=128]; +116[label=59]; +117[label=58]; +118[label=57]; +119[label=56]; +120[label=55]; +121[label=54]; +122[label=53]; +123[label=52]; +124[label=51]; +125[label=50]; +126[label=49]; +127[label=48]; +128[label=47]; +129[label=46]; +130[label=45]; +131[label=44]; +132[label=43]; +133[label=42]; +134[label=41]; +135[label=40]; +136[label=39]; +137[label=38]; +138[label=37]; +139[label=36]; +140[label=35]; +141[label=34]; +142[label=33]; +143[label=32]; +144[label=31]; +145[label=30]; +146[label=13]; +147[label=12]; +148[label=11]; +149[label=10]; +150[label=3]; +151[label=9]; +152[label=2]; +153[label=8]; +154[label=7]; +155[label=1]; +156[label=6]; +157[label=5]; +158[label=4]; +159[label=14]; +160[label=15]; +161[label=16]; +162[label=17]; +163[label=18]; +164[label=19]; +165[label=20]; +166[label=21]; +167[label=22]; +168[label=23]; +169[label=24]; +170[label=25]; +171[label=26]; +172[label=27]; +173[label=28]; +174[label=29]; +175[label=60]; +176[label=61]; +177[label=62]; +178[label=63]; +179[label=64]; +180[label=65]; +181[label=66]; +182[label=67]; +183[label=68]; +184[label=69]; +185[label=70]; +186[label=71]; +187[label=72]; +188[label=73]; +189[label=74]; +190[label=75]; +191[label=76]; +192[label=77]; +193[label=78]; +194[label=79]; +195[label=80]; +196[label=81]; +197[label=82]; +198[label=83]; +199[label=84]; +200[label=85]; +201[label=86]; +202[label=87]; +203[label=88]; +204[label=89]; +205[label=90]; +206[label=91]; +207[label=92]; +208[label=93]; +209[label=94]; +210[label=95]; +211[label=96]; +212[label=97]; +213[label=98]; +214[label=99]; +215[label=100]; +216[label=101]; +217[label=102]; +218[label=103]; +219[label=104]; +220[label=105]; +221[label=106]; +222[label=107]; +223[label=108]; +224[label=109]; +225[label=110]; +226[label=111]; +227[label=112]; +228[label=113]; +229[label=114]; +230[label=115]; +231[label=116]; +232[label=117]; +233[label=118]; +234[label=119]; +235[label=120]; +236[label=121]; +237[label=122]; +238[label=123]; +239[label=124]; +240[label=125]; +241[label=126]; +242[label=127]; +0->2 ; +0->3 ; +0->4 ; +0->5 ; +0->6 ; +0->103 ; +0->150 ; +0->152 ; +0->155 ; +2->1 ; +3->1 ; +4->1 ; +5->1 ; +6->1 ; +7->1 ; +8->1 ; +9->1 ; +10->8 ; +10->7 ; +11->9 ; +11->8 ; +12->10 ; +12->9 ; +13->11 ; +13->10 ; +14->12 ; +14->11 ; +15->13 ; +15->12 ; +16->14 ; +16->13 ; +17->15 ; +17->14 ; +18->16 ; +18->15 ; +19->17 ; +19->16 ; +20->18 ; +20->17 ; +21->19 ; +21->18 ; +22->20 ; +22->19 ; +23->21 ; +23->20 ; +24->22 ; +24->21 ; +25->23 ; +25->22 ; +26->24 ; +26->23 ; +27->25 ; +27->24 ; +28->26 ; +28->25 ; +29->27 ; +29->26 ; +30->28 ; +30->27 ; +31->29 ; +31->28 ; +32->30 ; +32->29 ; +33->31 ; +33->30 ; +34->32 ; +34->31 ; +35->33 ; +35->32 ; +36->34 ; +36->33 ; +37->35 ; +37->34 ; +38->36 ; +38->35 ; +39->37 ; +39->36 ; +40->38 ; +40->37 ; +41->39 ; +41->38 ; +42->40 ; +42->39 ; +43->41 ; +43->40 ; +44->42 ; +44->41 ; +45->43 ; +45->42 ; +46->44 ; +46->43 ; +47->45 ; +47->44 ; +48->46 ; +48->45 ; +49->47 ; +49->46 ; +50->48 ; +50->47 ; +51->49 ; +51->48 ; +52->50 ; +52->49 ; +53->51 ; +53->50 ; +54->52 ; +54->51 ; +55->53 ; +55->52 ; +56->54 ; +56->53 ; +57->55 ; +57->54 ; +58->56 ; +58->55 ; +59->57 ; +59->56 ; +60->58 ; +60->57 ; +61->59 ; +61->58 ; +62->60 ; +62->59 ; +63->61 ; +63->60 ; +64->62 ; +64->61 ; +65->63 ; +65->62 ; +66->64 ; +66->63 ; +67->65 ; +67->64 ; +68->66 ; +68->65 ; +69->67 ; +69->66 ; +70->68 ; +70->67 ; +71->69 ; +71->68 ; +72->70 ; +72->69 ; +73->71 ; +73->70 ; +74->72 ; +74->71 ; +75->73 ; +75->72 ; +76->74 ; +76->73 ; +77->75 ; +77->74 ; +78->76 ; +78->75 ; +79->77 ; +79->76 ; +80->78 ; +80->77 ; +81->79 ; +81->78 ; +82->80 ; +82->79 ; +83->81 ; +83->80 ; +84->82 ; +84->81 ; +85->83 ; +85->82 ; +86->84 ; +86->83 ; +87->85 ; +87->84 ; +88->86 ; +88->85 ; +89->87 ; +89->86 ; +90->88 ; +90->87 ; +91->89 ; +91->88 ; +92->90 ; +92->89 ; +93->91 ; +93->90 ; +94->92 ; +94->91 ; +95->93 ; +95->92 ; +96->94 ; +96->93 ; +97->95 ; +97->94 ; +98->96 ; +98->95 ; +99->97 ; +99->96 ; +100->98 ; +100->97 ; +101->99 ; +101->98 ; +102->100 ; +102->99 ; +103->105 ; +103->104 ; +104->101 ; +104->100 ; +105->102 ; +105->101 ; +106->1 ; +107->1 ; +108->1 ; +109->1 ; +110->106 ; +111->107 ; +111->106 ; +112->107 ; +112->106 ; +113->107 ; +113->106 ; +114->107 ; +114->106 ; +115->107 ; +115->106 ; +116->192 ; +116->193 ; +116->194 ; +117->191 ; +117->192 ; +117->193 ; +118->190 ; +118->191 ; +118->192 ; +119->189 ; +119->190 ; +119->191 ; +120->188 ; +120->189 ; +120->190 ; +121->187 ; +121->188 ; +121->189 ; +122->186 ; +122->187 ; +122->188 ; +123->185 ; +123->186 ; +123->187 ; +124->184 ; +124->185 ; +124->186 ; +125->183 ; +125->184 ; +125->185 ; +126->182 ; +126->183 ; +126->184 ; +127->181 ; +127->182 ; +127->183 ; +128->180 ; +128->181 ; +128->182 ; +129->179 ; +129->180 ; +129->181 ; +130->178 ; +130->179 ; +130->180 ; +131->177 ; +131->178 ; +131->179 ; +132->176 ; +132->177 ; +132->178 ; +133->175 ; +133->176 ; +133->177 ; +134->116 ; +134->175 ; +134->176 ; +135->117 ; +135->116 ; +135->175 ; +136->118 ; +136->117 ; +136->116 ; +137->119 ; +137->118 ; +137->117 ; +138->120 ; +138->119 ; +138->118 ; +139->121 ; +139->120 ; +139->119 ; +140->122 ; +140->121 ; +140->120 ; +141->123 ; +141->122 ; +141->121 ; +142->124 ; +142->123 ; +142->122 ; +143->125 ; +143->124 ; +143->123 ; +144->126 ; +144->125 ; +144->124 ; +145->127 ; +145->126 ; +145->125 ; +146->172 ; +146->173 ; +147->170 ; +147->171 ; +147->172 ; +148->169 ; +148->170 ; +148->171 ; +149->167 ; +149->168 ; +150->153 ; +150->151 ; +151->165 ; +151->166 ; +152->156 ; +152->154 ; +152->153 ; +153->163 ; +153->164 ; +153->165 ; +154->161 ; +154->162 ; +154->163 ; +155->158 ; +155->157 ; +155->156 ; +156->159 ; +156->160 ; +156->161 ; +157->147 ; +157->146 ; +157->159 ; +158->149 ; +158->148 ; +158->147 ; +159->174 ; +159->145 ; +159->144 ; +160->145 ; +160->144 ; +160->143 ; +161->143 ; +161->142 ; +161->141 ; +162->142 ; +162->141 ; +162->140 ; +163->140 ; +163->139 ; +163->138 ; +164->139 ; +164->138 ; +164->137 ; +165->138 ; +165->137 ; +165->136 ; +166->137 ; +166->136 ; +166->135 ; +167->136 ; +167->135 ; +167->134 ; +168->135 ; +168->134 ; +168->133 ; +169->134 ; +169->133 ; +169->132 ; +170->133 ; +170->132 ; +170->131 ; +171->132 ; +171->131 ; +171->130 ; +172->131 ; +172->130 ; +172->129 ; +173->129 ; +173->128 ; +173->127 ; +174->128 ; +174->127 ; +174->126 ; +175->193 ; +175->194 ; +175->195 ; +176->194 ; +176->195 ; +176->196 ; +177->195 ; +177->196 ; +177->197 ; +178->196 ; +178->197 ; +178->198 ; +179->197 ; +179->198 ; +179->199 ; +180->198 ; +180->199 ; +180->200 ; +181->199 ; +181->200 ; +181->201 ; +182->200 ; +182->201 ; +182->202 ; +183->201 ; +183->202 ; +183->203 ; +184->202 ; +184->203 ; +184->204 ; +185->203 ; +185->204 ; +185->205 ; +186->204 ; +186->205 ; +186->206 ; +187->205 ; +187->206 ; +187->207 ; +188->206 ; +188->207 ; +188->208 ; +189->207 ; +189->208 ; +189->209 ; +190->208 ; +190->209 ; +190->210 ; +191->209 ; +191->210 ; +191->211 ; +192->210 ; +192->211 ; +192->212 ; +193->211 ; +193->212 ; +193->213 ; +194->212 ; +194->213 ; +194->214 ; +195->213 ; +195->214 ; +195->215 ; +196->214 ; +196->215 ; +196->216 ; +197->215 ; +197->216 ; +197->217 ; +198->216 ; +198->217 ; +198->218 ; +199->217 ; +199->218 ; +199->219 ; +200->218 ; +200->219 ; +200->220 ; +201->219 ; +201->220 ; +201->221 ; +202->220 ; +202->221 ; +202->222 ; +203->221 ; +203->222 ; +203->223 ; +204->222 ; +204->223 ; +204->224 ; +205->223 ; +205->224 ; +205->225 ; +206->224 ; +206->225 ; +206->226 ; +207->225 ; +207->226 ; +207->227 ; +208->226 ; +208->227 ; +208->228 ; +209->227 ; +209->228 ; +209->229 ; +210->228 ; +210->229 ; +210->230 ; +211->229 ; +211->230 ; +211->231 ; +212->230 ; +212->231 ; +212->232 ; +213->231 ; +213->232 ; +213->233 ; +214->232 ; +214->233 ; +214->234 ; +215->233 ; +215->234 ; +215->235 ; +216->234 ; +216->235 ; +216->236 ; +217->235 ; +217->236 ; +217->237 ; +218->236 ; +218->237 ; +218->238 ; +219->237 ; +219->238 ; +219->239 ; +220->238 ; +220->239 ; +220->240 ; +221->239 ; +221->240 ; +221->241 ; +222->240 ; +222->241 ; +222->242 ; +223->241 ; +223->242 ; +223->115 ; +224->242 ; +224->115 ; +224->114 ; +225->115 ; +225->114 ; +225->113 ; +226->114 ; +226->113 ; +226->112 ; +227->113 ; +227->112 ; +227->111 ; +228->112 ; +228->111 ; +228->110 ; +229->111 ; +229->110 ; +229->109 ; +230->110 ; +230->109 ; +230->108 ; +231->109 ; +231->108 ; +231->107 ; +232->108 ; +232->107 ; +232->106 ; +233->107 ; +233->106 ; +234->107 ; +234->106 ; +235->107 ; +235->106 ; +236->107 ; +236->106 ; +237->107 ; +237->106 ; +238->107 ; +238->106 ; +239->107 ; +239->106 ; +240->107 ; +240->106 ; +241->107 ; +241->106 ; +242->107 ; +242->106 ; +} diff --git a/tests/out/7.dot b/tests/out/7.dot new file mode 100644 index 0000000..ff9c5a8 --- /dev/null +++ b/tests/out/7.dot @@ -0,0 +1,13 @@ +digraph G { +0[label=Start]; +1[label=End]; +2[label=4]; +3[label=3]; +4[label=1]; +5[label=2]; +0->4 ; +2->1 ; +3->2 ; +4->5 ; +5->3 ; +} diff --git a/tests/out/8.dot b/tests/out/8.dot new file mode 100644 index 0000000..6511071 --- /dev/null +++ b/tests/out/8.dot @@ -0,0 +1,88 @@ +digraph G { +0[label=Start]; +1[label=End]; +2[label=30]; +3[label=13]; +4[label=12]; +5[label=11]; +6[label=10]; +7[label=4]; +8[label=9]; +9[label=3]; +10[label=8]; +11[label=2]; +12[label=7]; +13[label=1]; +14[label=6]; +15[label=5]; +16[label=14]; +17[label=15]; +18[label=16]; +19[label=17]; +20[label=18]; +21[label=19]; +22[label=20]; +23[label=21]; +24[label=22]; +25[label=23]; +26[label=24]; +27[label=25]; +28[label=26]; +29[label=27]; +30[label=28]; +31[label=29]; +0->7 ; +0->9 ; +0->11 ; +0->13 ; +2->1 ; +3->19 ; +3->20 ; +4->18 ; +4->19 ; +5->17 ; +5->18 ; +6->17 ; +7->10 ; +7->8 ; +8->3 ; +8->16 ; +9->12 ; +9->10 ; +10->4 ; +10->3 ; +11->14 ; +11->12 ; +12->5 ; +12->4 ; +13->15 ; +13->14 ; +14->6 ; +14->5 ; +15->6 ; +16->20 ; +16->21 ; +17->22 ; +18->22 ; +18->23 ; +19->23 ; +19->24 ; +20->24 ; +20->25 ; +21->25 ; +21->26 ; +22->27 ; +23->27 ; +23->28 ; +24->28 ; +24->29 ; +25->29 ; +25->30 ; +26->30 ; +26->31 ; +27->2 ; +28->2 ; +29->2 ; +30->2 ; +31->2 ; +} diff --git a/tests/run_tests.py b/tests/run_tests.py index 35e0c44..cea1921 100644 --- a/tests/run_tests.py +++ b/tests/run_tests.py @@ -4,7 +4,7 @@ import glob CURRENT_PATH = os.path.abspath(os.path.dirname(__file__)) -PATH_TO_INPUT = [CURRENT_PATH + '/in/'] +PATH_TO_INPUT = os.path.join(CURRENT_PATH, "in") def get_dot_file_path(input_path): @@ -45,7 +45,7 @@ def test(executable): raise RuntimeError("End-to-end test failed\n") -if __name__ == "main": +if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument('--executable', help='Executable to test') args = parser.parse_args() diff --git a/tests/unit_tests.cc b/tests/unit_tests.cc new file mode 100644 index 0000000..eaf7c03 --- /dev/null +++ b/tests/unit_tests.cc @@ -0,0 +1,119 @@ +#include + +#include +#include +#include + +#include "graphs/graph.hh" + +class GraphTest : public testing::Test {}; + +TEST_F(GraphTest, TopologicalSort) { + graph::Graph g0; + std::vector o0; + ASSERT_EQ(g0.topologicalSort(), o0); + + graph::Graph g1 = {{42, {}}}; + std::vector o1 = {42}; + ASSERT_EQ(g1.topologicalSort(), o1); + + graph::Graph g2 = {{1, {2}}}; + std::vector o2 = {1, 2}; + ASSERT_EQ(g2.topologicalSort(), o2); + + graph::Graph g3{{1, {2, 3, 4}}, {2, {3, 4}}, {3, {4}}}; + std::vector o3 = {1, 2, 3, 4}; + ASSERT_EQ(g3.topologicalSort(), o3); + + graph::Graph g4 = { + {1, {2}}, {2, {3}}, {3, {4}}, + {4, {5}}, {5, {6, 7}}, {6, {7}}, + {7, {8, 10}}, {8, {9}}, {9, {10}}, + {10, {11, 12}}, {11, {12, 16}}, {12, {13}}, + {13, {14}}, {14, {15, 17}}, {15, {16, 17}}, + {16, {17}}, {17, {18, 20}}, {18, {19}}, + {19, {20}}, {20, {21, 22}}, {21, {22}}, + {22, {23}}, {23, {24, 26}}, {24, {25}}, + {25, {26, 27}}, {26, {27}}, {27, {28}}, + {28, {29}}, {29, {30, 32}}, {30, {31, 32}}, + {31, {32}}, {32, {33}}, {33, {34}}, + {34, {35, 37}}, {35, {36, 37}}, {36, {37}}, + {37, {38, 40}}, {38, {39}}, {39, {40}}, + {40, {41, 42}}, {41, {42}}, {42, {43}}, + {43, {44}}, {44, {45, 47}}, {45, {46, 47}}, + {46, {47}}, {47, {48}}, {48, {49}}, + {49, {50, 52}}, {50, {51, 52}}, {51, {52}}, + {52, {53}}, {53, {54}}, {54, {55}}, + {55, {56, 57, 60}}, {56, {57, 59}}, {57, {58}}, + {58, {59}}, {59, {60}}, {60, {61, 62}}, + {61, {62}}, {62, {63}}, {63, {64, 66}}, + {64, {65}}, {65, {66, 67}}, {66, {67}}, + {67, {68, 70}}, {68, {69}}, {69, {70}}, + {70, {71, 72}}, {71, {72}}, {72, {73}}, + {73, {74}}, {74, {75, 77}}, {75, {76, 77}}, + {76, {77}}, {77, {78, 80}}, {78, {79}}, + {79, {80}}, {80, {81, 82}}, {81, {82}}, + {82, {83}}, {83, {84}}, {84, {85, 87}}, + {85, {86, 87}}, {86, {87}}, {87, {88, 90}}, + {88, {89}}, {89, {90}}, {90, {91, 92}}, + {91, {92}}, {92, {93}}, {93, {94}}, + {94, {95, 97}}, {95, {96, 97}}, {96, {97}}, + {97, {98, 100}}, {98, {99}}, {99, {100}}, + {100, {101, 102}}, {101, {102}}, {102, {103}}, + {103, {104}}, {104, {105, 107}}, {105, {106, 107}}, + {106, {107}}, {107, {108, 110}}, {108, {109}}, + {109, {110}}, {110, {111, 112}}, {111, {112}}, + {112, {113}}, {113, {114}}, {114, {115, 117}}, + {115, {116, 117}}, {116, {117}}, {117, {118, 120}}, + {118, {119}}, {119, {120}}, {120, {121, 122}}, + {121, {122}}, {122, {123}}, {123, {124}}, + {124, {125, 127}}, {125, {126, 127}}, {126, {127}}, + {127, {128, 130}}, {128, {129}}, {129, {130}}, + {130, {131, 132}}, {131, {132}}, {132, {133}}, + {133, {134}}, {134, {135, 137}}, {135, {136, 137}}, + {136, {137}}, {137, {138, 140}}, {138, {139}}, + {139, {140}}, {140, {141, 142}}, {141, {142}}, + {142, {143}}, {143, {144}}, {144, {145, 147}}, + {145, {146, 147}}, {146, {147}}, {147, {148, 150}}, + {148, {149}}, {149, {150}}, {150, {151, 152}}, + {151, {152}}, {152, {153}}, {153, {154}}, + {154, {155, 157}}, {155, {156, 157}}, {156, {157}}, + {157, {158, 160}}, {158, {159}}, {159, {160}}, + {160, {161, 162}}, {161, {162}}, {162, {163}}, + {163, {164}}, {164, {165, 167}}, {165, {166, 167}}, + {166, {167}}, {167, {168, 170}}, {168, {169}}, + {169, {170}}, {170, {171, 172}}, {171, {172}}, + {172, {173}}, {173, {174}}, {174, {175, 177}}, + {175, {176, 177}}, {176, {177}}, {177, {178, 180}}, + {178, {179}}, {179, {180}}, {180, {181, 182}}, + {181, {182}}, {182, {183}}, {183, {184}}, + {184, {185, 187}}, {185, {186, 187}}, {186, {187}}, + {187, {188, 190}}, {188, {189}}, {189, {190}}, + {190, {191, 192}}, {191, {192}}, {192, {193}}, + {193, {194}}, {194, {195}}, {195, {196, 197}}, + {196, {197, 199}}, {197, {198}}, {198, {199, 203}}, + {199, {200}}, {200, {201, 202}}, {201, {202}}, + {202, {203}}, {203, {204}}, {204, {205}}, + {205, {}}}; + std::vector o4 = { + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, + 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, + 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, + 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, + 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, + 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, + 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, + 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, + 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, + 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, + 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, + 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, + 196, 197, 198, 199, 200, 201, 202, 203, 204, 205}; + ASSERT_EQ(g4.topologicalSort(), o4); +} + +int main(int argc, char** argv) { + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +}