Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/CXXGraph/Graph/Graph_decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <cmath>
#include <cstring>
#include <cstdint>
#include <deque>
#include <fstream>
#include <functional>
Expand Down
46 changes: 46 additions & 0 deletions test/CycleCheckTest.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#include <memory>
#include <vector>
#include <string>
#include <random>

#include "CXXGraph/CXXGraph.hpp"
#include "gtest/gtest.h"
Expand All @@ -9,6 +12,7 @@ using unique = std::unique_ptr<T>;
template <typename T>
using shared = std::shared_ptr<T>;

using std::shared_ptr;
using std::make_shared;
using std::make_unique;

Expand Down Expand Up @@ -151,3 +155,45 @@ TEST(CycleCheckTest, test_8) {
bool res = graph.isCyclicDirectedGraphBFS();
ASSERT_EQ(res, true);
}

TEST(CycleCheckTest, test_2001000) {
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<int> distrib(1, 100);

std::vector<CXXGraph::Node<int>> nodes;
std::vector<CXXGraph::DirectedWeightedEdge<int>> edges;
nodes.reserve(2001000);
edges.reserve(2001000);
CXXGraph::T_EdgeSet<int> edgeSet;
int node_i = 1;
int edge_i = 1;

/*
* Creates a Tree Graph with a root node in which each level
* has one more node than the previous one, having in the end
* 2000*2001/2 = 2001000 nodes the form looks as follows:
* node1---node3---node6...
* |-node2 |-node5
* |-node4
*/
CXXGraph::Node<int> node(std::to_string(node_i), node_i);
nodes.push_back(std::move(node));
node_i++;
for (int i = 2; i < 2001; i++) {
for (int j = 0; j < i; j++) {
auto last_i_node = nodes.back();
CXXGraph::Node<int> node(std::to_string(node_i), node_i);
nodes.push_back(std::move(node));
node_i++;
CXXGraph::DirectedWeightedEdge<int> edge(std::to_string(edge_i++), last_i_node, nodes.back(), distrib(gen));
edgeSet.insert(make_shared<CXXGraph::DirectedWeightedEdge<int>>(std::move(edge)));
}
}
CXXGraph::Graph<int> graph_tree(edgeSet);
ASSERT_EQ(graph_tree.isCyclicDirectedGraphBFS(), false);
CXXGraph::DirectedWeightedEdge<int> edge(std::to_string(edge_i++), nodes.back(), nodes.front(), distrib(gen));
edgeSet.insert(make_shared<CXXGraph::DirectedWeightedEdge<int>>(std::move(edge)));
CXXGraph::Graph<int> graph_cycle(std::move(edgeSet));
ASSERT_EQ(graph_cycle.isCyclicDirectedGraphBFS(), true);
}
Loading