Skip to content
Snippets Groups Projects
Commit d17dbfb3 authored by Olivier BICHLER's avatar Olivier BICHLER
Browse files

Extended tests to cyclic graphs

parent 4ff979a6
No related branches found
No related tags found
1 merge request!53GraphView inputs/outputs ordering
Pipeline #35200 failed
......@@ -23,9 +23,11 @@
namespace Aidge {
/**
* Random DAG generator
* Random (directed) graph generator
*/
struct RandomDAG {
struct RandomGraph {
/// @brief If true, the generated graph is a DAG (no cycle)
bool acyclic = false;
/// @brief Connection density (between 0 and 1)
float density = 0.5;
/// @brief Max number of inputs per node (regardless if they are connected or not)
......
......@@ -12,7 +12,7 @@
#include "aidge/graph/Testing.hpp"
#include "aidge/operator/GenericOperator.hpp"
std::pair<Aidge::NodePtr, std::set<Aidge::NodePtr>> Aidge::RandomDAG::gen(std::mt19937::result_type seed, size_t nbNodes) const {
std::pair<Aidge::NodePtr, std::set<Aidge::NodePtr>> Aidge::RandomGraph::gen(std::mt19937::result_type seed, size_t nbNodes) const {
std::mt19937 gen(seed);
std::binomial_distribution<> dIn(maxIn - 1, avgIn/maxIn);
std::binomial_distribution<> dOut(maxOut - 1, avgOut/maxOut);
......@@ -39,7 +39,7 @@ std::pair<Aidge::NodePtr, std::set<Aidge::NodePtr>> Aidge::RandomDAG::gen(std::m
}
for (size_t i = 0; i < nbNodes; ++i) {
for (size_t j = i + 1; j < nbNodes; ++j) {
for (size_t j = (acyclic) ? i + 1 : 0; j < nbNodes; ++j) {
for (size_t outId = 0; outId < nodes[i]->nbOutputs(); ++outId) {
for (size_t inId = 0; inId < nodes[j]->nbInputs(); ++inId) {
if (dLink(gen)) {
......
......@@ -40,7 +40,7 @@ public:
}
};
TEST_CASE("genRandomDAG") {
TEST_CASE("genRandomGraph") {
const size_t nbTests = 100;
size_t nbUnicity = 0;
......@@ -48,14 +48,14 @@ TEST_CASE("genRandomDAG") {
std::random_device rd;
const std::mt19937::result_type seed(rd());
RandomDAG randDAG;
RandomGraph randGraph;
const auto g1 = std::make_shared<GraphView_Test>("g1");
const bool unicity1 = g1->add(randDAG.gen(seed, 10));
const bool unicity1 = g1->add(randGraph.gen(seed, 10));
const auto g2 = std::make_shared<GraphView>("g2");
const bool unicity2 = g2->add(randDAG.gen(seed, 10));
const bool unicity2 = g2->add(randGraph.gen(seed, 10));
g1->save("./genRandomDAG1");
g2->save("./genRandomDAG2");
g1->save("./genRandomGraph1");
g2->save("./genRandomGraph2");
REQUIRE(unicity1 == unicity2);
......@@ -96,9 +96,9 @@ TEST_CASE("clone") {
std::random_device rd;
const std::mt19937::result_type seed(rd());
RandomDAG randDAG;
RandomGraph randGraph;
const auto g1 = std::make_shared<GraphView>("g1");
g1->add(randDAG.gen(seed, 10));
g1->add(randGraph.gen(seed, 10));
const auto g2 = g1->clone();
......@@ -126,16 +126,16 @@ TEST_CASE("clone_with_delete") {
std::mt19937::result_type seed(42);
for (int test = 0; test < nbTests; ++test) {
RandomDAG randDAG;
randDAG.types = {"Fictive", "DelFictive"};
randDAG.typesWeights = {0.9, 0.1};
RandomGraph randGraph;
randGraph.types = {"Fictive", "DelFictive"};
randGraph.typesWeights = {0.9, 0.1};
const auto g1 = std::make_shared<GraphView>("g1");
const bool unicity1 = g1->add(randDAG.gen(seed, 10));
const bool unicity1 = g1->add(randGraph.gen(seed, 10));
if (unicity1) {
randDAG.omitType = "DelFictive";
randGraph.omitType = "DelFictive";
const auto g2 = std::make_shared<GraphView>("g2");
const bool unicity2 = g2->add(randDAG.gen(seed, 10));
const bool unicity2 = g2->add(randGraph.gen(seed, 10));
g1->save("./clone_with_delete1");
g2->save("./clone_with_delete2");
......@@ -167,11 +167,11 @@ TEST_CASE("remove") {
std::random_device rd;
const std::mt19937::result_type seed(rd());
RandomDAG randDAG;
randDAG.types = {"Fictive", "DelFictive"};
randDAG.typesWeights = {0.8, 0.2};
RandomGraph randGraph;
randGraph.types = {"Fictive", "DelFictive"};
randGraph.typesWeights = {0.8, 0.2};
const auto g1 = std::make_shared<GraphView>("g1");
const bool unicity1 = g1->add(randDAG.gen(seed, 10));
const bool unicity1 = g1->add(randGraph.gen(seed, 10));
if (unicity1) {
g1->save("./remove1_before");
......@@ -185,9 +185,9 @@ TEST_CASE("remove") {
}
}
randDAG.omitType = "DelFictive";
randGraph.omitType = "DelFictive";
const auto g2 = std::make_shared<GraphView>("g2");
g2->add(randDAG.gen(seed, 10));
g2->add(randGraph.gen(seed, 10));
g1->save("./remove1");
g2->save("./remove2");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment