From cdb30ea1cf7da067d685c8d60d91868e69a053d7 Mon Sep 17 00:00:00 2001 From: Romain BERNARD <romain.bernard@uca.fr> Date: Wed, 20 Mar 2024 18:06:32 +0100 Subject: [PATCH] start unit test implementation --- .gitmodules | 3 +++ CMakeLists.txt | 2 ++ test/CMakeLists.txt | 23 +++++++++++++++++++ test/lib/googletest | 1 + test/src/LineUnitTests.cpp | 31 ++++++++++++++++++++++++++ test/src/TransitPreprocessUnitTest.cpp | 3 +++ 6 files changed, 63 insertions(+) create mode 100644 .gitmodules create mode 100644 test/CMakeLists.txt create mode 160000 test/lib/googletest create mode 100644 test/src/LineUnitTests.cpp create mode 100644 test/src/TransitPreprocessUnitTest.cpp diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..c8f91cc --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "googletest"] + path = test/lib/googletest + url = https://github.com/google/googletest.git diff --git a/CMakeLists.txt b/CMakeLists.txt index a3bcdc5..4bea03d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,8 @@ set(CMAKE_CXX_STANDARD 23) add_definitions(-DDEBUG_TRANSIT_PRECOMPUTE) +add_subdirectory(test) + add_executable(GreedyAlgorithm src/instance/graph/Node.cpp src/instance/graph/Node.h diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..451d74d --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,23 @@ +# 'Google_test' is the subproject name +project(Google_tests) + +# 'lib' is the folder with Google Test sources +add_subdirectory(lib/googletest) +include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}) + +# 'Google_Tests_run' is the target name +# 'test1.cpp test2.cpp' are source files with tests +add_executable(Line_UT + src/LineUnitTests.cpp + ../src/instance/graph/Node.cpp + ../src/instance/graph/Node.h + ../src/instance/graph/Edge.cpp + ../src/instance/graph/Edge.h + ../src/instance/graph/Graph.cpp + ../src/instance/graph/Graph.h + ../src/instance/graph/Line.cpp + ../src/instance/graph/Line.h +) +add_executable(Transit_preprocess_UT src/TransitPreprocessUnitTest.cpp) +target_link_libraries(Line_UT gtest gtest_main) +target_link_libraries(Transit_preprocess_UT gtest gtest_main) \ No newline at end of file diff --git a/test/lib/googletest b/test/lib/googletest new file mode 160000 index 0000000..eff443c --- /dev/null +++ b/test/lib/googletest @@ -0,0 +1 @@ +Subproject commit eff443c6ef5eb6ab598bfaae27f9427fdb4f6af7 diff --git a/test/src/LineUnitTests.cpp b/test/src/LineUnitTests.cpp new file mode 100644 index 0000000..bc8b3c4 --- /dev/null +++ b/test/src/LineUnitTests.cpp @@ -0,0 +1,31 @@ +// +// Created by romain on 15/02/24. +// + +//TODO : Implement following tests +// - verify schedule continuity (forall schedule, schedule[0] < schedule[1] +// - + +#include "../lib/googletest/googletest/include/gtest/gtest.h" +#include "../../src/instance/graph/Graph.h" + + +TEST(LineTests, LineGenerationScheduleOrder) { + std::string instanceFolder = "contiguous_lines_debug_instance/"; + std::string datFile = "graph.dat"; + Graph graphFromSingleFile("../resources/test/instances/" + instanceFolder + datFile); + + for(const auto& line : graphFromSingleFile.getPTLines()) { + for(const auto& schedule : line.getTimetables()) { + for(size_t i = 0; i < line.scheduleSize(); ++i) { + ASSERT_GT(schedule.at(i), schedule.at(i + 1)); //assert schedule value order + } + } + ASSERT_TRUE(line.checkSchedules()); //assert line schedule check function is coherent with our preceding assertion + } +} + +int main(int argc, char* argv[]) { + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} \ No newline at end of file diff --git a/test/src/TransitPreprocessUnitTest.cpp b/test/src/TransitPreprocessUnitTest.cpp new file mode 100644 index 0000000..e211100 --- /dev/null +++ b/test/src/TransitPreprocessUnitTest.cpp @@ -0,0 +1,3 @@ +// +// Created by romain on 20/03/24. +// -- GitLab