From e24b8ea8fe74c26683b9584cee87f733b8395683 Mon Sep 17 00:00:00 2001 From: sbaldu Date: Tue, 26 Sep 2023 23:06:21 +0200 Subject: [PATCH] Add test of set data for isolated node --- test/GraphTest.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/test/GraphTest.cpp b/test/GraphTest.cpp index 3ef8e5e2b..890d6c72e 100644 --- a/test/GraphTest.cpp +++ b/test/GraphTest.cpp @@ -821,3 +821,56 @@ TEST(TestGetNode, Test_1) { auto node_notfound = graph.getNode("5"); ASSERT_FALSE(node_notfound.has_value()); } + +TEST(GraphTest, set_data_isolated) { + // Create the graph + CXXGraph::Node node1("1", 1); + CXXGraph::Node node2("2", 2); + CXXGraph::Node node3("3", 3); + std::pair *, const CXXGraph::Node *> pairNode( + &node1, &node2); + CXXGraph::DirectedEdge edge1(1, pairNode); + CXXGraph::DirectedEdge edge2(2, node2, node3); + CXXGraph::UndirectedEdge edge3(3, node1, node3); + CXXGraph::T_EdgeSet edgeSet; + edgeSet.insert(make_shared>(edge1)); + edgeSet.insert(make_shared>(edge2)); + edgeSet.insert(make_shared>(edge3)); + CXXGraph::Graph graph(edgeSet); + + // Create isolated nodes and add them to the graph + CXXGraph::Node node4("4", 4); + CXXGraph::Node node5("5", 5); + CXXGraph::Node node6("6", 6); + graph.addNode(make_shared>(node4)); + graph.addNode(make_shared>(node5)); + graph.addNode(make_shared>(node6)); + + std::map initial_values; + // Construct map with the initial values of the nodes data + for (const auto &nodeIt : graph.getNodeSet()) { + initial_values[nodeIt->getUserId()] = nodeIt->getData(); + } + // Change the data contained in the nodes singularly + std::map new_values; + for (const auto &nodeIt : graph.getNodeSet()) { + int r = std::rand(); + graph.setNodeData(nodeIt->getUserId(), r); + new_values[nodeIt->getUserId()] = r; + } + // Check the final values of the node data + for (const auto &nodeIt : graph.getNodeSet()) { + ASSERT_EQ(nodeIt->getData(), new_values[nodeIt->getUserId()]); + } + + // Now set the data of all the nodes at once + std::map data_values; + for (const auto &nodeIt : graph.getNodeSet()) { + int r = std::rand(); + data_values[nodeIt->getUserId()] = r; + } + graph.setNodeData(data_values); + for (const auto &nodeIt : graph.getNodeSet()) { + ASSERT_EQ(nodeIt->getData(), data_values[nodeIt->getUserId()]); + } +}