-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCycleTest.cc
More file actions
41 lines (35 loc) · 1013 Bytes
/
CycleTest.cc
File metadata and controls
41 lines (35 loc) · 1013 Bytes
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
#include <algorithm>
#include "Cycle.hh"
#include "Graph.hh"
auto main() -> int {
print("Edge is_trivially_copyable {}\n", std::is_trivially_copyable_v<Edge>);
print("Graph is_trivially_copyable {}\n",
std::is_trivially_copyable_v<Graph>);
constexpr int v{8}, e{12};
// Cycle
Graph G(v);
generateGraph(G, e);
printGraph(G);
Cycle C(G);
printCycle(C);
std::cout << '\n';
if (C.hasCycle()) {
for (size_t i = 0; i < C.cycle.size() - 1; i++) {
assert(std::find(G.adj[C.cycle[i]].begin(), G.adj[C.cycle[i]].end(),
C.cycle[i + 1]) != G.adj[C.cycle[i]].end());
}
}
// DirectedCycle
Digraph DG(v);
generateGraph(DG, e);
printGraph(DG);
DirectedCycle DC(DG);
printCycle(DC);
std::cout << '\n';
if (DC.hasCycle()) {
for (size_t i = 0; i < DC.cycle.size() - 1; i++) {
assert(std::find(DG.adj[DC.cycle[i]].begin(), DG.adj[DC.cycle[i]].end(),
DC.cycle[i + 1]) != DG.adj[DC.cycle[i]].end());
}
}
}