diff --git a/alib2data/test-src/graph/GraphElementsTest.cpp b/alib2data/test-src/graph/GraphElementsTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..721d60c7b82c1c585e6ca5848f3b55f0ec7ef20e --- /dev/null +++ b/alib2data/test-src/graph/GraphElementsTest.cpp @@ -0,0 +1,147 @@ +#include "GraphElementsTest.h" + +#include "sax/SaxParseInterface.h" +#include "sax/SaxComposeInterface.h" + +#include "factory/XmlDataFactory.hpp" +#include "factory/StringDataFactory.hpp" + +CPPUNIT_TEST_SUITE_REGISTRATION(GraphElementsTest); + +void GraphElementsTest::testCopyConstruct() +{ + // Common + graph::Node n1("n1"); + graph::Node n2("n2"); + graph::Node n3("n3"); + + // DirectedEdge + graph::DirectedEdge de1(n1, n2); + graph::DirectedEdge de2(n1, n3); + + graph::DirectedEdge de1_2(de1); + CPPUNIT_ASSERT(de1_2 == de1); + + graph::DirectedEdge de2_2(de2); + CPPUNIT_ASSERT(de2_2 == de2); + + graph::DirectedEdge de1_3(std::move(de1)); + CPPUNIT_ASSERT(de1_3 == de1_2); + + graph::DirectedEdge de2_3(std::move(de2)); + CPPUNIT_ASSERT(de2_3 == de2_2); + + // UndirectedEdge + graph::UndirectedEdge ue1(n1, n2); + graph::UndirectedEdge ue2(n1, n3); + + graph::UndirectedEdge ue1_2(ue1); + CPPUNIT_ASSERT(ue1_2 == ue1); + + graph::UndirectedEdge ue2_2(ue2); + CPPUNIT_ASSERT(ue2_2 == ue2); + + graph::UndirectedEdge ue1_3(std::move(ue1)); + CPPUNIT_ASSERT(ue1_3 == ue1_2); + + graph::UndirectedEdge ue2_3(std::move(ue2)); + CPPUNIT_ASSERT(ue2_3 == ue2_2); + + // Node + graph::Node n1_2(n1); + CPPUNIT_ASSERT(n1_2 == n1); + + graph::Node n2_2(n2); + CPPUNIT_ASSERT(n2_2 == n2); + + graph::Node n3_2(n3); + CPPUNIT_ASSERT(n3_2 == n3); + + graph::Node n1_3(std::move(n1)); + CPPUNIT_ASSERT(n1_3 == n1_2); + + graph::Node n2_3(std::move(n2)); + CPPUNIT_ASSERT(n2_3 == n2_2); + + graph::Node n3_3(std::move(n3)); + CPPUNIT_ASSERT(n3_3 == n3_2); +} + +void GraphElementsTest::testEqual() +{ + // Node + graph::Node n1("n1"); + graph::Node n1_("n1"); + graph::Node n2("n2"); + graph::Node n2_("n2"); + graph::Node n3("n3"); + graph::Node n3_("n3"); + + CPPUNIT_ASSERT(n1 == n1); + CPPUNIT_ASSERT(n1 == n1_); + CPPUNIT_ASSERT(n2 == n2); + CPPUNIT_ASSERT(n2 == n2_); + CPPUNIT_ASSERT(n3 == n3); + CPPUNIT_ASSERT(n3 == n3_); + + CPPUNIT_ASSERT(n1 != n2); + CPPUNIT_ASSERT(n1 != n3); + CPPUNIT_ASSERT(n2 != n1); + CPPUNIT_ASSERT(n3 != n1); + + CPPUNIT_ASSERT_EQUAL(0, std::compare<graph::Node>()(n1, n1_)); + CPPUNIT_ASSERT_EQUAL(0, std::compare<graph::Node>()(n1, n1)); + CPPUNIT_ASSERT(std::compare<graph::Node>()(n1, n2) != 0); + CPPUNIT_ASSERT(std::compare<graph::Node>()(n1, n3) != 0); + CPPUNIT_ASSERT(std::compare<graph::Node>()(n1, n3_) != 0); + + // DirectedEdge + graph::DirectedEdge de1(n1, n2); + graph::DirectedEdge de1_(n1, n2); + graph::DirectedEdge de2(n1, n3); + graph::DirectedEdge de2_(n1, n3); + graph::DirectedEdge de3(n1, n3, "a"); + graph::DirectedEdge de3_(n1, n3, "a"); + + CPPUNIT_ASSERT(de1 == de1); + CPPUNIT_ASSERT(de1 == de1_); + CPPUNIT_ASSERT(de2 == de2); + CPPUNIT_ASSERT(de2 == de2_); + CPPUNIT_ASSERT(de3 == de3); + CPPUNIT_ASSERT(de3 == de3_); + + CPPUNIT_ASSERT(de1 != de2); + CPPUNIT_ASSERT(de1 != de3); + CPPUNIT_ASSERT(de2 != de1); + CPPUNIT_ASSERT(de3 != de1); + + CPPUNIT_ASSERT_EQUAL(0, std::compare<graph::DirectedEdge>()(de1, de1_)); + CPPUNIT_ASSERT_EQUAL(0, std::compare<graph::DirectedEdge>()(de1, de1)); + CPPUNIT_ASSERT(std::compare<graph::DirectedEdge>()(de1, de2) != 0); + CPPUNIT_ASSERT(std::compare<graph::DirectedEdge>()(de1, de3) != 0); + CPPUNIT_ASSERT(std::compare<graph::DirectedEdge>()(de1, de3_) != 0); + + // UndirectedEdge + graph::UndirectedEdge ue1(n1, n2); + graph::UndirectedEdge ue1_(n1, n2); + graph::UndirectedEdge ue1_s(n2, n1); + graph::UndirectedEdge ue2(n1, n3); + graph::UndirectedEdge ue2_(n1, n3); + graph::UndirectedEdge ue3(n1, n3, "a"); + graph::UndirectedEdge ue3_(n1, n3, "a"); + + CPPUNIT_ASSERT(ue1 == ue1); + CPPUNIT_ASSERT(ue1 == ue1_); + CPPUNIT_ASSERT(ue1 == ue1_s); + CPPUNIT_ASSERT(ue1_ == ue1_s); + CPPUNIT_ASSERT(ue2 == ue2); + CPPUNIT_ASSERT(ue2 == ue2_); + CPPUNIT_ASSERT(ue3 == ue3); + CPPUNIT_ASSERT(ue3 == ue3_); + + CPPUNIT_ASSERT(ue1 != ue2); + CPPUNIT_ASSERT(ue1 != ue3); + CPPUNIT_ASSERT(ue2 != ue1); + CPPUNIT_ASSERT(ue3 != ue1); +} + diff --git a/alib2data/test-src/graph/GraphElementsTest.h b/alib2data/test-src/graph/GraphElementsTest.h new file mode 100644 index 0000000000000000000000000000000000000000..279c89c2b8421c8a56befe16054f79e3e3806adb --- /dev/null +++ b/alib2data/test-src/graph/GraphElementsTest.h @@ -0,0 +1,21 @@ +#ifndef GRAPH_ELEMENTS_TEST_H_ +#define GRAPH_ELEMENTS_TEST_H_ + +#include <cppunit/extensions/HelperMacros.h> + +#include "graph/directed/DirectedGraph.h" +#include "graph/undirected/UndirectedGraph.h" + +class GraphElementsTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(GraphElementsTest); + CPPUNIT_TEST(testCopyConstruct); + CPPUNIT_TEST(testEqual); + CPPUNIT_TEST_SUITE_END(); + +public: + void testCopyConstruct(); + void testEqual(); +}; + +#endif // GRAPH_ELEMENTS_TEST_H_