6#include <gtest/gtest.h>
40 EXPECT_EQ(p.
get_x(), 0.0);
41 EXPECT_EQ(p.
get_y(), 0.0);
56 EXPECT_DOUBLE_EQ(retrieved.
get_x().
get_d(), 10.5);
57 EXPECT_DOUBLE_EQ(retrieved.
get_y().
get_d(), 20.3);
67 EXPECT_DOUBLE_EQ(retrieved.
get_x().
get_d(), 5.0);
68 EXPECT_DOUBLE_EQ(retrieved.
get_y().
get_d(), 15.0);
79 EXPECT_DOUBLE_EQ(retrieved.
get_x().
get_d(), 7.5);
80 EXPECT_DOUBLE_EQ(retrieved.
get_y().
get_d(), 8.5);
96 EXPECT_DOUBLE_EQ(arc.
get_info(), 3.14);
115 ASSERT_NE(node,
nullptr);
116 EXPECT_EQ(node->get_info(), 42);
126 ASSERT_NE(node,
nullptr);
127 Point retrieved = node->get_position();
128 EXPECT_DOUBLE_EQ(retrieved.
get_x().
get_d(), 10.0);
129 EXPECT_DOUBLE_EQ(retrieved.
get_y().
get_d(), 20.0);
139 ASSERT_NE(node,
nullptr);
140 EXPECT_EQ(node->get_info(), 100);
141 Point retrieved = node->get_position();
142 EXPECT_DOUBLE_EQ(retrieved.
get_x().
get_d(), 5.5);
143 EXPECT_DOUBLE_EQ(retrieved.
get_y().
get_d(), 7.5);
155 ASSERT_NE(n1,
nullptr);
156 ASSERT_NE(n2,
nullptr);
157 ASSERT_NE(n3,
nullptr);
173 ASSERT_NE(arc,
nullptr);
187 ASSERT_NE(arc,
nullptr);
188 EXPECT_DOUBLE_EQ(arc->get_info(), 99.9);
219 EXPECT_DOUBLE_EQ(dist.
get_d(), 5.0);
231 EXPECT_DOUBLE_EQ(dist.
get_d(), 0.0);
243 EXPECT_DOUBLE_EQ(dist.
get_d(), 10.0);
255 EXPECT_DOUBLE_EQ(dist.
get_d(), 8.0);
265 Point p1(10.0, 20.0);
266 Point p2(30.0, 40.0);
274 EXPECT_EQ(found1, n1);
275 EXPECT_EQ(found2, n2);
283 Point search_point(99.0, 99.0);
286 EXPECT_EQ(found,
nullptr);
295 EXPECT_EQ(found,
nullptr);
375 ASSERT_NE(arc,
nullptr);
395 bool each_arc_leaves_its_node(
const EDigraph & dg,
const size_t degree)
397 for (
auto it = dg.
get_node_it(); it.has_curr(); it.next_ne())
399 auto p = it.get_curr();
412 std::vector<std::string> positions(
const G & g)
414 std::vector<std::string> ret;
415 for (
auto it = g.
get_node_it(); it.has_curr(); it.next_ne())
416 ret.push_back(it.get_curr()->get_position().to_string());
429 const std::vector<std::string> where = positions(g1);
430 ASSERT_EQ(where.size(), 2u);
432 const EGraph & source = g1;
434 EXPECT_EQ(positions(g2), where);
441 EXPECT_EQ(positions(g3), where);
442 for (
auto it = g3.
get_arc_it(); it.has_curr(); it.next_ne())
465 EXPECT_TRUE(each_arc_leaves_its_node(dg2, 1));
466 EXPECT_EQ(positions(dg2), positions(dg1));
474 EXPECT_TRUE(each_arc_leaves_its_node(dg3, 1));
475 EXPECT_EQ(positions(dg3), positions(dg1));
485 const size_t n = 1000;
487 for (
size_t i = 0; i < n; ++i)
489 double x =
static_cast<double>(i);
490 double y =
static_cast<double>(i * 2);
500 const size_t n = 100;
502 std::vector<ENode*>
nodes;
503 for (
size_t i = 0; i < n; ++i)
509 for (
size_t i = 0; i < n; ++i)
511 for (
size_t j = i + 1; j < n; ++j)
517 size_t expected_arcs = n * (n - 1) / 2;
531 ASSERT_NE(n1,
nullptr);
532 ASSERT_NE(n2,
nullptr);
537 EXPECT_GT(dist.
get_d(), 0.0);
549 EXPECT_DOUBLE_EQ(dist.
get_d(), std::sqrt(2.0));
Geom_Number get_distance(Arc *arc)
Node * insert_node(Node *node) noexcept override
Insertion of a node already allocated.
Node * search_node(const Point &)
void next_ne() noexcept(shows_ne)
Advances the iterator to the next filtered element, as next() does.
Graph implemented with double-linked adjacency lists.
Arc * get_first_arc(Node *node) const
Return any arc adjacent to a node.
Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
Represents a point with rectangular coordinates in a 2D plane.
const Geom_Number & get_x() const noexcept
Gets the x-coordinate value.
const Geom_Number & get_y() const noexcept
Gets the y-coordinate value.
ArcInfo & get_info() noexcept
Return a modifiable reference to the arc data.
NodeInfo & get_info() noexcept
Return a modifiable reference to the data contained in the node.
constexpr size_t get_num_nodes() const noexcept
Return the total of nodes of graph.
auto get_arc_it() const noexcept
Obtains an iterator to the arc of graph.
Node * get_src_node(Arc *arc) const noexcept
Return the source node of arc (only for directed graphs)
bool is_digraph() const noexcept
Return true if the graph this is directed.
constexpr size_t get_num_arcs() const noexcept
Return the number of arcs of the graph.
auto get_node_it() const noexcept
Obtains an iterator to the nodes of graph.
Node * get_tgt_node(Arc *arc) const noexcept
Return the target node of arc (only for directed graphs)
TEST_F(EuclidianGraphTest, NodeDefaultConstructor)
DynArray< Graph::Node * > nodes
Main namespace for Aleph-w library functions.
int num(Node *p)
The number of a node of a built graph.
2D point and geometric utilities.
Filtered iterator of adjacent arcs of a node.
Euclidean graph with 2D coordinates.