Skip to content

Commit

Permalink
apply fix-style
Browse files Browse the repository at this point in the history
  • Loading branch information
luk036 committed Mar 16, 2023
1 parent 93d5f1c commit 0efca8a
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 95 deletions.
10 changes: 3 additions & 7 deletions include/xnetwork/classes/digraphs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,9 @@ class DiGraphS
> G = xnetwork::DiGraphS(r, r); // or DiGraph, MultiGraph,
MultiDiGraph, etc
*/
explicit DiGraphS(const nodeview_t &Nodes)
: _Base{Nodes} {}
explicit DiGraphS(const nodeview_t &Nodes) : _Base{Nodes} {}

explicit DiGraphS(uint32_t num_nodes)
: _Base{num_nodes} {}
explicit DiGraphS(uint32_t num_nodes) : _Base{num_nodes} {}

/** DiGraphS adjacency object holding the neighbors of each node.
Expand Down Expand Up @@ -410,9 +408,7 @@ class DiGraphS
*/
auto successors(const Node &n) -> auto & { return this->_adj[n]; }

auto successors(const Node &n) const -> const auto & {
return this->_adj[n];
}
auto successors(const Node &n) const -> const auto & { return this->_adj[n]; }

/** An OutEdgeView of the DiGraph as G.edges().
Expand Down
86 changes: 43 additions & 43 deletions test/source/test_transrangers_xnDiGraphS2.cpp
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
// -*- coding: utf-8 -*-
#include <doctest/doctest.h> // for TestCase, ResultBuilder
#include <doctest/doctest.h> // for TestCase, ResultBuilder

#include <array> // for array
#include <array> // for array
#include <transrangers_ext.hpp>
#include <xnetwork/classes/digraphs.hpp> // for DiGraphS
#include <xnetwork/generators/testcases.hpp> // for create_test_case1, crea...
#include <xnetwork/classes/digraphs.hpp> // for DiGraphS
#include <xnetwork/generators/testcases.hpp> // for create_test_case1, crea...

/**
* @brief
*
* @tparam Graph
* @param G
*/
template <typename Graph> static void do_case(const Graph& G) {
using namespace transrangers;

auto count = 0U;
auto rng = all(G);
rng([&count](const auto& /* node */) {
++count;
return true;
});

CHECK(G.number_of_nodes() == count);

// auto count2 = 0U;
// for ([[maybe_unused]] auto _ : G.edges())
// {
// ++count2;
// }
// CHECK(G.number_of_edges() == count2);

// auto deg = 0U;
// for ([[maybe_unused]] auto _ : G[1U]) {
// ++deg;
// }
// CHECK(G.degree(1U) == deg);

auto deg = 0U;
auto rng2 = all(G[1U]);
rng2([&deg](const auto& /* x */) {
++deg;
return true;
});
CHECK_EQ(G.degree(1U), deg);
template <typename Graph> static void do_case(const Graph &G) {
using namespace transrangers;

auto count = 0U;
auto rng = all(G);
rng([&count](const auto & /* node */) {
++count;
return true;
});

CHECK(G.number_of_nodes() == count);

// auto count2 = 0U;
// for ([[maybe_unused]] auto _ : G.edges())
// {
// ++count2;
// }
// CHECK(G.number_of_edges() == count2);

// auto deg = 0U;
// for ([[maybe_unused]] auto _ : G[1U]) {
// ++deg;
// }
// CHECK(G.degree(1U) == deg);

auto deg = 0U;
auto rng2 = all(G[1U]);
rng2([&deg](const auto & /* x */) {
++deg;
return true;
});
CHECK_EQ(G.degree(1U), deg);
}

TEST_CASE("Test Cycle Ratio") {
const auto indices = std::array<int, 5>{0, 1, 2, 3, 4};
auto G = create_test_case1(indices);
do_case(G);
const auto indices = std::array<int, 5>{0, 1, 2, 3, 4};
auto G = create_test_case1(indices);
do_case(G);
}

TEST_CASE("Test Cycle Ratio of Timing Graph") {
// make sure no parallel edges!!!
// make sure no parallel edges!!!

const auto indices = std::array<int, 6>{0, 1, 2, 3, 4, 5};
auto G = create_test_case2(indices);
do_case(G);
const auto indices = std::array<int, 6>{0, 1, 2, 3, 4, 5};
auto G = create_test_case2(indices);
do_case(G);
}
88 changes: 44 additions & 44 deletions test/source/test_transrangers_xnGraph.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// -*- coding: utf-8 -*-
#include <doctest/doctest.h> // for ResultBuilder, TestCase, CHECK
#include <doctest/doctest.h> // for ResultBuilder, TestCase, CHECK

#include <cstdint> // for uint8_t
#include <py2cpp/dict.hpp> // for dict<>::Base
#include <py2cpp/set.hpp> // for set
#include <cstdint> // for uint8_t
#include <py2cpp/dict.hpp> // for dict<>::Base
#include <py2cpp/set.hpp> // for set
#include <transrangers_ext.hpp>
#include <tuple> // for tuple_element<>::type
#include <unordered_map> // for operator!=
#include <vector> // for vector
#include <xnetwork/classes/graph.hpp> // for Graph, SimpleGraph
#include <tuple> // for tuple_element<>::type
#include <unordered_map> // for operator!=
#include <vector> // for vector
#include <xnetwork/classes/graph.hpp> // for Graph, SimpleGraph

#if __cplusplus > 201703L
# include <cppcoro/generator.hpp> // for operator!=, generator
#include <cppcoro/generator.hpp> // for operator!=, generator
#endif

/**
Expand All @@ -20,24 +20,24 @@
* @tparam Graph
* @param G
*/
template <typename Graph> static void do_case(const Graph& G) {
using namespace transrangers;
template <typename Graph> static void do_case(const Graph &G) {
using namespace transrangers;

auto count = 0U;
auto rng = all(G);
rng([&count](const auto& /* x */) {
++count;
return true;
});
CHECK(G.number_of_nodes() == count);
auto count = 0U;
auto rng = all(G);
rng([&count](const auto & /* x */) {
++count;
return true;
});
CHECK(G.number_of_nodes() == count);

auto deg = 0U;
auto rng2 = all(G[1U]);
rng2([&deg](const auto& /* x */) {
++deg;
return true;
});
CHECK(G.degree(1U) == deg);
auto deg = 0U;
auto rng2 = all(G[1U]);
rng2([&deg](const auto & /* x */) {
++deg;
return true;
});
CHECK(G.degree(1U) == deg);
}

/**
Expand All @@ -46,16 +46,16 @@ template <typename Graph> static void do_case(const Graph& G) {
* @return Netlist
*/
TEST_CASE("Test xnetwork::Graph") {
constexpr auto num_nodes = 6;
enum nodes { a1, a2, a3, n1, n2, n3 };
// const auto R = py::range<std::uint8_t>(0, num_nodes);
auto G = xnetwork::SimpleGraph{num_nodes};
G.add_edge(a1, n1);
G.add_edge(a1, n1);
G.add_edge(a1, n2);
G.add_edge(a2, n2);
constexpr auto num_nodes = 6;
enum nodes { a1, a2, a3, n1, n2, n3 };
// const auto R = py::range<std::uint8_t>(0, num_nodes);
auto G = xnetwork::SimpleGraph{num_nodes};
G.add_edge(a1, n1);
G.add_edge(a1, n1);
G.add_edge(a1, n2);
G.add_edge(a2, n2);

do_case(G);
do_case(G);
}

/**
Expand All @@ -64,17 +64,17 @@ TEST_CASE("Test xnetwork::Graph") {
* @return Netlist
*/
TEST_CASE("Test xnetwork::Graph (not simple graph)") {
// constexpr auto num_nodes = 6;
enum nodes_name { a1, a2, a3, n1, n2, n3 };
// constexpr auto num_nodes = 6;
enum nodes_name { a1, a2, a3, n1, n2, n3 };

std::vector<uint8_t> nodes{a2, a3, n1, n3, n2};
std::vector<uint8_t> nodes{a2, a3, n1, n3, n2};

// const auto R = py::range<std::uint8_t>(0, num_nodes);
auto G = xnetwork::Graph<std::vector<uint8_t>>{nodes};
G.add_edge(a2, n1);
G.add_edge(a3, n2);
G.add_edge(a3, n3);
G.add_edge(a2, n2);
// const auto R = py::range<std::uint8_t>(0, num_nodes);
auto G = xnetwork::Graph<std::vector<uint8_t>>{nodes};
G.add_edge(a2, n1);
G.add_edge(a3, n2);
G.add_edge(a3, n3);
G.add_edge(a2, n2);

do_case(G);
do_case(G);
}
2 changes: 1 addition & 1 deletion test/source/test_xnDiGraphS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ template <typename Graph> static void do_case(const Graph &G) {

auto deg = 0U;
for ([[maybe_unused]] auto _ : G["B"]) {
++deg;
++deg;
}
CHECK_EQ(G.degree("B"), deg);
}
Expand Down

0 comments on commit 0efca8a

Please sign in to comment.