42#include <gtest/gtest.h>
63 struct GraphWithoutMemory :
public ::testing::Test
68 GTEST_SKIP() <<
"ThreadSanitizer replaces the global operator new";
83 void expect_arcs(
const G & g,
const std::vector<typename G::Arc *> &
arcs)
89 auto a = it.get_curr_ne();
90 EXPECT_NE(std::find(
arcs.begin(),
arcs.end(), a),
arcs.end());
93 EXPECT_EQ(in_graph,
arcs.size());
97 auto p = it.get_curr_ne();
98 size_t adjacent = 0,
sum = 0;
101 auto a = j.get_curr_ne();
102 EXPECT_NE(std::find(
arcs.begin(),
arcs.end(), a),
arcs.end());
103 sum += size_t(a->get_info());
107 EXPECT_GE(sum, adjacent);
118TYPED_TEST(GraphWithoutMemory, InsertArcLeavesTheGraphAsItWas)
121 for (
bool loop : {
false,
true})
122 for (
size_t k = 1; ; ++
k)
124 SCOPED_TRACE(testing::Message() <<
"allocation " <<
k
125 << (loop ?
", a loop" :
""));
132 typename G::Arc * arc =
nullptr;
140 catch (
const std::bad_alloc &)
149 expect_arcs(g,
arcs);
152 expect_arcs(g,
arcs);
156 expect_arcs(g,
arcs);
164TYPED_TEST(GraphWithoutMemory, RemoveNodeLeavesTheGraphAsItWasOrRemovesIt)
167 for (
size_t k = 1; ; ++
k)
169 SCOPED_TRACE(testing::Message() <<
"allocation " <<
k);
186 catch (
const std::bad_alloc &)
195 expect_arcs(g,
arcs);
200 expect_arcs(g, {
arcs[3]});
210 void expect_sources_and_sinks(
const Net & net)
214 auto p = it.get_curr_ne();
220 struct NetWithoutMemory :
public ::testing::Test
222 void SetUp()
override
225 GTEST_SKIP() <<
"ThreadSanitizer replaces the global operator new";
233TEST_F(NetWithoutMemory, ArcsGoOnlyIfTheSetsOfSourcesAndSinksTakeTheirEnds)
235 for (
int how = 0; how < 3; ++how)
236 for (
size_t k = 1; ; ++
k)
238 SCOPED_TRACE(testing::Message() <<
"way " << how <<
", allocation " <<
k);
258 catch (
const std::bad_alloc &)
263 expect_sources_and_sinks(net);
264 if (how == 1
and not thrown)
278TEST_F(NetWithoutMemory, ClearGraphThrowsAndLeavesTheNetworkRight)
280 for (
size_t k = 1; ; ++
k)
282 SCOPED_TRACE(testing::Message() <<
"allocation " <<
k);
297 catch (
const std::bad_alloc &)
302 expect_sources_and_sinks(net);
317TYPED_TEST(GraphWithoutMemory, CopyAssignmentLeavesTheGraphAsItWas)
327 for (
size_t k = 1; ; ++
k)
329 SCOPED_TRACE(testing::Message() <<
"allocation " <<
k);
343 catch (
const std::bad_alloc &)
354 expect_arcs(g,
arcs);
362 sum += it.get_curr_ne()->get_info();
371TYPED_TEST(GraphWithoutMemory, InsertNodeLeavesTheGraphAsItWas)
374 for (
size_t k = 1; ; ++
k)
376 SCOPED_TRACE(testing::Message() <<
"allocation " <<
k);
386 catch (
const std::bad_alloc &)
398 EXPECT_EQ(
nodes, 2u);
401 EXPECT_EQ(
nodes, 1u);
409 struct CopiesWithoutMemory :
public ::testing::Test
411 void SetUp()
override
414 GTEST_SKIP() <<
"ThreadSanitizer replaces the global operator new";
426 std::vector<typename G::Node *> bow(
G & g)
428 std::vector<typename G::Node *> v;
429 for (
int i = 0; i < 6; ++i)
432 const int arcs[][2] = {{0, 1}, {1, 2}, {2, 0}, {2, 3}, {3, 4}, {4, 2}, {4, 5}};
434 for (
const auto & a :
arcs)
435 g.insert_arc(v[a[0]], v[a[1]],
k++);
441 template <
class Copy>
442 void fail_each_allocation(Copy
copy)
444 for (
size_t k = 1; ; ++
k)
446 SCOPED_TRACE(testing::Message() <<
"allocation " <<
k);
454 catch (
const std::bad_alloc &)
479 ASSERT_EQ(cuts.size(), 2u);
485 fail_each_allocation([&] {
auto copies =
map_cut_graph(g, cuts); });
490 cc.paint_subgraphs();
491 fail_each_allocation([&]
496 fail_each_allocation([&]
500 cc.map_cut_graph(cut_graph, cross);
503 fail_each_allocation([&] { (void) g.
insert_node(7); });
A global operator new that a test can make fail.
#define ALEPH_ALLOCATION_FAILURE_UNDER_TSAN
Computation of cut nodes (articulation points) of a graph.
Generic directed graph (digraph) wrapper template.
bool has_curr() const noexcept
Return true if the iterator has current item.
Dynamic doubly linked list with O(1) size and bidirectional access.
Arc for graphs implemented with simple adjacency lists.
Iterator on the arcs of a graph.
Graph implemented with double-linked adjacency lists.
virtual Node * insert_node(Node *node) noexcept
Insertion of a node already allocated.
virtual void remove_node(Node *node)
Remove a node from the graph and free its memory.
_Graph_Arc Arc
The node class type.
Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
Graph class implemented with singly-linked adjacency lists.
constexpr size_t get_num_nodes() const noexcept
Return the total of nodes of graph.
bool is_digraph() const noexcept
Return true if the graph this is directed.
void *& get_cookie() noexcept
Return a modifiable reference to graph's cookie.
constexpr size_t get_num_arcs() const noexcept
Return the number of arcs of the graph.
TEST_F(NetWithoutMemory, ArcsGoOnlyIfTheSetsOfSourcesAndSinksTakeTheirEnds)
TYPED_TEST_SUITE(GraphWithoutMemory, Graph_Kinds)
TYPED_TEST(GraphWithoutMemory, InsertArcLeavesTheGraphAsItWas)
DynArray< Graph::Node * > nodes
DynArray< Graph::Arc * > arcs
#define NODE_COUNTER(p)
Get the counter of a node.
GT find_breadth_first_spanning_tree(GT &g, typename GT::Node *gp)
Build a breadth-first spanning tree (mapped to the original graph).
long paint_subgraphs(const GT &g, const DynList< typename GT::Node * > &cut_node_list)
Paint connected blocks around articulation points.
DynList< typename GT::Node * > compute_cut_nodes(const GT &g, typename GT::Node *start)
Compute articulation points (cut vertices) of an undirected graph.
void clear_graph(GT &g)
Clean a graph: all its nodes and arcs are removed and freed.
std::tuple< GT, DynList< typename GT::Arc * > > map_cut_graph(const GT &g, const DynList< typename GT::Node * > &cut_node_list)
Extract the cut graph and cross-arc list.
GT map_subgraph(const GT &g, const long color)
Extract a mapped subgraph containing a given color.
Main namespace for Aleph-w library functions.
Itor2 copy(Itor1 sourceBeg, const Itor1 &sourceEnd, Itor2 destBeg)
Copy elements from one range to another.
and
Check uniqueness with explicit hash + equality functors.
static long & color(typename GT::Node *p)
T sum(const Container &container, const T &init=T{})
Compute sum of all elements.
::testing::Types< Aleph::List_Graph< Aleph::Graph_Node< int >, Aleph::Graph_Arc< int > >, Aleph::List_SGraph< Aleph::Graph_Snode< int >, Aleph::Graph_Sarc< int > >, Aleph::Array_Graph< Aleph::Graph_Anode< int >, Aleph::Graph_Aarc< int > > > Undirected_Kinds
The kinds of graph that are not directed, with int infos.
Arc of graph implemented with double-linked adjacency lists.
Iterator on all arcs of a graph.
Arc of a flow network implemented with adjacency lists.
Flow network implemented with adjacency lists.
Node * insert_node(const Node_Type &node_info)
Insert a new node by copying node_info.
Arc * connect_arc(Arc *arc)
Connect a previously disconnected arc.
void remove_arc(Arc *arc) override
Remove arc arc from the network.
virtual void disconnect_arc(Arc *arc)
Disconnect arc arc from the graph without deleting it.
size_t get_out_degree(Node *p) const noexcept
Return the out-degree of p (number of outgoing arcs).
bool is_source(Node *node) const noexcept
Return true if node is a source.
Arc * insert_arc(Node *src_node, Node *tgt_node, const Flow_Type &cap, const Flow_Type &flow, const typename Arc::Arc_Type &arc_info=Arc_Type())
Insert a capacitated arc with an initial flow.
void remove_node(Node *p) override
Remove node p and all its arcs from the network.
bool is_sink(Node *node) const noexcept
Return true if node is a sink.
size_t get_in_degree(Node *p) const noexcept
Return the in-degree of p (number of incoming arcs).
Array-based graph implementation.
Articulation points (cut nodes), bridges, and biconnected components.
Generic graph and digraph implementations.
Utility algorithms and operations for graphs.
Network flow graph structures.
Simple graph implementation with adjacency lists.