diff --git a/.gitignore b/.gitignore index ea784d4..c87012e 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,4 @@ # Building build +*.swp diff --git a/src/algorithm.hpp b/src/algorithm.hpp index 964e0fc..e3dd442 100644 --- a/src/algorithm.hpp +++ b/src/algorithm.hpp @@ -27,22 +27,6 @@ struct Graph { void PrintGraph(void); }; -/* OLD IMPLEMENTATION -struct Node { - int destination; - int weight; - Node(int destination, int weight); -}; - -struct Graph { - int nodeCount; - std::vector> nodes; - Graph(void); - void AddEdge(int source, int destination, int weight); - void PrintGraph(void); -}; - */ - Graph ReadInGraph(std::string fileLocation); void PrintSolution(std::vector solution); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4786b92..dc49f2f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,9 +1,9 @@ -find_package(unity REQUIRED) +find_package(Catch2 REQUIRED) include_directories("${CMAKE_CURRENT_SOURCE_DIR}") add_executable(testing - ./testing.cpp - ../src/main.cpp + ./test-main.cpp + ./test-algorithm.cpp ../src/algorithm.cpp ) set_target_properties(testing PROPERTIES LINKER_LANGUAGE CXX) -target_link_libraries(testing unity) +target_link_libraries(testing Catch2::Catch2) diff --git a/test/test-algorithm.cpp b/test/test-algorithm.cpp new file mode 100644 index 0000000..238d11c --- /dev/null +++ b/test/test-algorithm.cpp @@ -0,0 +1,23 @@ +#include +#include "algorithm.hpp" + +TEST_CASE("Adding Graph") { + Graph testGraph = ReadInGraph("test/input/graphPosLittle"); + REQUIRE( testGraph.nodeCount > 0 ); + SECTION( "Vertices" ) { + REQUIRE( testGraph.vertices.at(1).nodeNumber == 1 ); + REQUIRE( testGraph.vertices.at(2).nodeNumber == 2 ); + REQUIRE( testGraph.vertices.at(3).nodeNumber == 3 ); + REQUIRE( testGraph.vertices.at(4).nodeNumber == 4 ); + REQUIRE( testGraph.vertices.at(5).nodeNumber == 5 ); + REQUIRE( testGraph.vertices.at(6).nodeNumber == 6 ); + REQUIRE( testGraph.vertices.at(7).nodeNumber == 7 ); + REQUIRE( testGraph.vertices.at(8).nodeNumber == 8 ); + REQUIRE( testGraph.vertices.at(9).nodeNumber == 9 ); + REQUIRE( testGraph.vertices.at(10).nodeNumber == 10 ); + } + SECTION( "Edges" ) { + REQUIRE( testGraph.vertices.at(1).edges.at(1).destination->nodeNumber == 7 ); + REQUIRE( testGraph.vertices.at(1).edges.at(2).destination->nodeNumber == 2 ); + } +} diff --git a/test/test-main.cpp b/test/test-main.cpp new file mode 100644 index 0000000..4ed06df --- /dev/null +++ b/test/test-main.cpp @@ -0,0 +1,2 @@ +#define CATCH_CONFIG_MAIN +#include diff --git a/test/testing.cpp b/test/testing.cpp deleted file mode 100644 index f0e94c0..0000000 --- a/test/testing.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include -#include -#include "algorithm.hpp" - -// Function is defined here for testing - -void setUp(void) -{ - ; -} - -void tearDown(void) -{ - ; -} - -int main(void) -{ - UNITY_BEGIN(); - return UNITY_END(); -} -