diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000000000000000000000000000000000000..c8f91cccb63061bd23bc604dc7d7f5f15230308e --- /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 a3bcdc521f14ca796549e590c8423c553178f7d2..4bea03d2a6eb93524b341c658c3c4fdd6f9df24b 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 0000000000000000000000000000000000000000..451d74dfa26120d1acbaca161d1fe7f2217a1644 --- /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 0000000000000000000000000000000000000000..eff443c6ef5eb6ab598bfaae27f9427fdb4f6af7 --- /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 0000000000000000000000000000000000000000..bc8b3c43d45e7b6110af5f370d319f286779d995 --- /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 0000000000000000000000000000000000000000..e2111003004bf6a78a09e73b1cd2495119610922 --- /dev/null +++ b/test/src/TransitPreprocessUnitTest.cpp @@ -0,0 +1,3 @@ +// +// Created by romain on 20/03/24. +//