Skip to content

Commit

Permalink
Add tests for overloads of addEdge
Browse files Browse the repository at this point in the history
  • Loading branch information
sbaldu committed Oct 2, 2023
1 parent b30e7b5 commit 0c85ec0
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/GraphTest.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

#include <CXXGraph/Edge/DirectedWeightedEdge.hpp>
#include <CXXGraph/Edge/UndirectedWeightedEdge.hpp>
#include <CXXGraph/Edge/Weighted.hpp>
#include <memory>

#include "CXXGraph/CXXGraph.hpp"
Expand Down Expand Up @@ -207,6 +210,44 @@ TEST(GraphTest, RawAddEdge_3) {
ASSERT_FALSE(graph.isUndirectedGraph());
}

TEST(GraphTest, AddEdgeWeight_raw) {
CXXGraph::Node<int> node1("1", 1);
CXXGraph::Node<int> node2("2", 1);
CXXGraph::Node<int> node3("3", 1);
CXXGraph::DirectedWeightedEdge<int> edge1(1, node1, node2, 3);
CXXGraph::UndirectedWeightedEdge<int> edge2(2, node1, node3, 5);
CXXGraph::Graph<int> graph;

graph.addEdge(&edge1);
graph.addEdge(&edge2);

// Check that the edges are weighted
ASSERT_TRUE((*graph.getEdge(1))->isWeighted());
ASSERT_TRUE((*graph.getEdge(2))->isWeighted());
// Check the value of the weights
ASSERT_EQ(std::dynamic_pointer_cast<const CXXGraph::Weighted>(*graph.getEdge(1))->getWeight(), 3);
ASSERT_EQ(std::dynamic_pointer_cast<const CXXGraph::Weighted>(*graph.getEdge(2))->getWeight(), 5);
}

TEST(GraphTest, AddEdgeWeight_shared) {
CXXGraph::Node<int> node1("1", 1);
CXXGraph::Node<int> node2("2", 1);
CXXGraph::Node<int> node3("3", 1);
CXXGraph::DirectedWeightedEdge<int> edge1(1, node1, node2, 3);
CXXGraph::UndirectedWeightedEdge<int> edge2(2, node1, node3, 5);
CXXGraph::Graph<int> graph;

graph.addEdge(make_shared<const CXXGraph::DirectedWeightedEdge<int>>(edge1));
graph.addEdge(make_shared<const CXXGraph::UndirectedWeightedEdge<int>>(edge2));

// Check that the edges are weighted
ASSERT_TRUE((*graph.getEdge(1))->isWeighted());
ASSERT_TRUE((*graph.getEdge(2))->isWeighted());
// Check the value of the weights
ASSERT_EQ(std::dynamic_pointer_cast<const CXXGraph::Weighted>(*graph.getEdge(1))->getWeight(), 3);
ASSERT_EQ(std::dynamic_pointer_cast<const CXXGraph::Weighted>(*graph.getEdge(2))->getWeight(), 5);
}

TEST(GraphTest, DirectedEdgeCycle_1) {
CXXGraph::Node<int> node1("a", 1);
CXXGraph::Node<int> node2("b", 1);
Expand Down

0 comments on commit 0c85ec0

Please sign in to comment.