diff --git a/.clang-format b/.clang-format index bd274289..66b6161d 100644 --- a/.clang-format +++ b/.clang-format @@ -41,7 +41,7 @@ BraceWrapping: SplitEmptyNamespace: true AfterCaseLabel: true BreakBeforeBinaryOperators: All -BreakBeforeBraces: Custom +BreakBeforeBraces: Stroustrup BreakBeforeInheritanceComma: false BreakInheritanceList: BeforeComma BreakBeforeTernaryOperators: true diff --git a/.github/workflows/build-matrix.yml b/.github/workflows/build-matrix.yml index 774a70d9..fa5087a0 100644 --- a/.github/workflows/build-matrix.yml +++ b/.github/workflows/build-matrix.yml @@ -10,14 +10,14 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [windows-latest, ubuntu-latest, macos-latest] # + os: [windows-latest, ubuntu-latest] # , macos-latest include: - os: windows-latest compiler: msvc - os: ubuntu-latest compiler: gcc - - os: macos-latest - compiler: clang +# - os: macos-latest +# compiler: clang steps: - name: Checkout code uses: actions/checkout@v4.1.4 @@ -42,3 +42,7 @@ jobs: - name: Build run: | cmake --build build --config Release + + - name: Test + run: | + cmake --build build --target test diff --git a/geometry/include/utils/utils.h b/geometry/include/utils/utils.h index c6bc097c..b277e6f1 100644 --- a/geometry/include/utils/utils.h +++ b/geometry/include/utils/utils.h @@ -7,7 +7,7 @@ #include #include #include -#include <../../include/spatial/CoordinateComponent.h> +#include constexpr long double operator"" _km(const long double value) { return value; diff --git a/geometry/test/CMakeLists.txt b/geometry/test/CMakeLists.txt index 12780c8f..da1b3be8 100644 --- a/geometry/test/CMakeLists.txt +++ b/geometry/test/CMakeLists.txt @@ -3,6 +3,7 @@ project("geometry_test" ) +include(CTest) enable_testing() add_executable(${PROJECT_NAME}) @@ -24,7 +25,9 @@ target_link_libraries(${PROJECT_NAME} PRIVATE ) set(BINARY ${PROJECT_NAME}) -add_test(NAME ${BINARY} COMMAND ${BINARY}) + +add_test(NAME geomety COMMAND ${BINARY}_test) +add_test(NAME TestK2dTree COMMAND ${BINARY}_test) target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_BINARY_DIR}) target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/logging/src) diff --git a/geometry/test/test_kdTree.cpp b/geometry/test/test_kdTree.cpp index 7148f789..3199b8fc 100644 --- a/geometry/test/test_kdTree.cpp +++ b/geometry/test/test_kdTree.cpp @@ -3,7 +3,7 @@ // #include -#include "../../logging/src/LoggingPool.h" +#include "LoggerFactory.h" #include "utils.h" #include "usings.h" @@ -11,7 +11,8 @@ #include -TEST(geomety, TestK2dTree) { +TEST(geomety, TestK2dTree) +{ auto kdTree = geometry::kd_tree::spatialK2dTree({}); const auto firstCoordinate = geometry::kd_tree::spatialCoordinate(1.0); const auto secondCoordinate = geometry::kd_tree::spatialCoordinate(2.0); @@ -21,8 +22,7 @@ TEST(geomety, TestK2dTree) { } -class TestK2dTree : public testing::Test -{ +class TestK2dTree : public testing::Test { using hasher = geometry::utils::CoordinateComponentHash; using equalizer = geometry::utils::CoordinateComponentEqual; @@ -30,9 +30,10 @@ class TestK2dTree : public testing::Test std::unordered_map stations; std::unique_ptr kdTree; - void SetUp() override { + void SetUp() override + { // arrange - LoggingPool::getInstance().getLogger(Target::CONSOLE)->setLevel(LoggerBridge::ERROR); + getConsoleLogger(LoggerName::GEOMETRY)->info("TestK2dTree::SetUp"); stations[geometry::kd_tree::coordinateComponent(geometry::kd_tree::spatialCoordinate(47.4230127859742), geometry::kd_tree::spatialCoordinate(9.369479194531577))] = "St. Gallen Train Station"; stations[geometry::kd_tree::coordinateComponent(geometry::kd_tree::spatialCoordinate(47.41190313108875), geometry::kd_tree::spatialCoordinate(9.25303543394843))] = "Gossau Train Station"; stations[geometry::kd_tree::coordinateComponent(geometry::kd_tree::spatialCoordinate(47.41549705750434), geometry::kd_tree::spatialCoordinate(9.18936624689178))] = "Flawil Train Station"; @@ -40,8 +41,7 @@ class TestK2dTree : public testing::Test stations[geometry::kd_tree::coordinateComponent(geometry::kd_tree::spatialCoordinate(47.5002860698031), geometry::kd_tree::spatialCoordinate(8.723829255246654))] = "Wintherthur Train Station"; std::vector coordinates; - for (const auto& coordinate : stations | std::views::keys) - { + for (const auto& coordinate : stations | std::views::keys) { coordinates.push_back(coordinate); } @@ -49,23 +49,25 @@ class TestK2dTree : public testing::Test } }; -TEST_F(TestK2dTree, TestK2dTreeStGallenToWinterthur) { +TEST_F(TestK2dTree, TestK2dTreeStGallenToWinterthur) +{ // act const auto findNearestFromRickenbach = geometry::kd_tree::coordinateComponent(geometry::kd_tree::spatialCoordinate(47.53556052653995), geometry::kd_tree::spatialCoordinate(8.789113533722448)); const auto findNeaerestFromKreuzbleiche = geometry::kd_tree::coordinateComponent(geometry::kd_tree::spatialCoordinate(47.419620275547636), geometry::kd_tree::spatialCoordinate(9.359281921519944)); const auto nearestRickenbach = kdTree->nearest(findNearestFromRickenbach); - LoggingPool::getInstance().getLogger(Target::CONSOLE)->info(std::format("Nearest to Rickenbach is: {}", stations[nearestRickenbach])); + getConsoleLogger(LoggerName::GEOMETRY)->info(std::format("Nearest to Rickenbach is: {}", stations[nearestRickenbach])); const auto neaerestKreuzbleiche = kdTree->nearest(findNeaerestFromKreuzbleiche); - LoggingPool::getInstance().getLogger(Target::CONSOLE)->info(std::format("Nearest to Kreuzbleiche is: {}", stations[neaerestKreuzbleiche])); + getConsoleLogger(LoggerName::GEOMETRY)->info(std::format("Nearest to Kreuzbleiche is: {}", stations[neaerestKreuzbleiche])); // assert ASSERT_TRUE(stations[nearestRickenbach] == "Wintherthur Train Station"); ASSERT_TRUE(stations[neaerestKreuzbleiche] == "St. Gallen Train Station"); } -TEST_F(TestK2dTree, TestK2dTreeRangeSearch) { +TEST_F(TestK2dTree, TestK2dTreeRangeSearch) +{ // act const auto findNeaerestFromKreuzbleiche = geometry::kd_tree::coordinateComponent(geometry::kd_tree::spatialCoordinate(47.419620275547636), geometry::kd_tree::spatialCoordinate(9.359281921519944)); @@ -73,11 +75,9 @@ TEST_F(TestK2dTree, TestK2dTreeRangeSearch) { const auto nearestRickenbach = kdTree->rangeSearch(findNeaerestFromKreuzbleiche, rangeInKiloMeters); // assert - for (auto it = nearestRickenbach.begin(); it != nearestRickenbach.end(); ++it) - { - LoggingPool::getInstance().getLogger(Target::CONSOLE)->info(std::format("Nearest to Kreuzbleiche is: {}", stations[*it])); - switch (std::distance(nearestRickenbach.begin(), it)) - { + for (auto it = nearestRickenbach.begin(); it != nearestRickenbach.end(); ++it) { + getConsoleLogger(LoggerName::GEOMETRY)->info(std::format("Nearest to Kreuzbleiche is: {}", stations[*it])); + switch (std::distance(nearestRickenbach.begin(), it)) { case 0: ASSERT_TRUE(stations[*it] == "St. Gallen Train Station"); break; diff --git a/raptor/CMakeLists.txt b/raptor/CMakeLists.txt index 4b30d3c4..482523d4 100644 --- a/raptor/CMakeLists.txt +++ b/raptor/CMakeLists.txt @@ -2,9 +2,7 @@ project("raptor" DESCRIPTION "C++ implementation of raptor algorithm" ) -add_library(${PROJECT_NAME} SHARED - src/utils/helperFunctions.h -) +add_library(${PROJECT_NAME} SHARED) target_sources(${PROJECT_NAME} PRIVATE src/Raptor.cpp @@ -45,6 +43,7 @@ target_sources(${PROJECT_NAME} PRIVATE src/RaptorConnection.cpp src/RaptorConnection.h src/utils/LocalDateTime.cpp + src/utils/helperFunctions.h PUBLIC include/RaptorAlgorithm.h include/config/QueryConfig.h diff --git a/raptor/include/LocalDateTime.h b/raptor/include/LocalDateTime.h index b5e64f83..ef3c9887 100644 --- a/raptor/include/LocalDateTime.h +++ b/raptor/include/LocalDateTime.h @@ -23,6 +23,8 @@ namespace raptor::utils { dateTime = local_days{year / month / day} + hour + minute + second; } + LocalDateTime() = default; + [[nodiscard]] long long secondsOfDay() const { using namespace std::chrono; const auto time_since_epoch = dateTime.time_since_epoch(); @@ -54,7 +56,6 @@ namespace raptor::utils { const auto new_seconds = duration_cast(time_of_day % minutes(1)); return LocalDateTime{year{1970}, month{1}, day{1}, new_hours, new_minutes, new_seconds}; } - }; inline LocalDateTime fromSecondsOfDay(const long long total_seconds, const std::chrono::year year, const std::chrono::month month, const std::chrono::day day) { diff --git a/raptor/src/LabelPostprocessor.cpp b/raptor/src/LabelPostprocessor.cpp index 91569a58..dddb31bd 100644 --- a/raptor/src/LabelPostprocessor.cpp +++ b/raptor/src/LabelPostprocessor.cpp @@ -108,10 +108,6 @@ namespace raptor { throw std::runtime_error("Unknown label type"); } - // Convert timestamps to LocalDateTime if necessary - // auto departureTime = DateTimeUtils::convertToLocalDateTime(departureTimestamp, referenceDate); - // auto arrivalTime = DateTimeUtils::convertToLocalDateTime(arrivalTimestamp, referenceDate); - connection->addLeg(std::make_shared(routeId, tripId, fromStopId, toStopId, departureTimestamp, arrivalTimestamp, type)); } diff --git a/raptor/test/CMakeLists.txt b/raptor/test/CMakeLists.txt index cc4462de..af97126d 100644 --- a/raptor/test/CMakeLists.txt +++ b/raptor/test/CMakeLists.txt @@ -2,15 +2,14 @@ project("raptor_test" DESCRIPTION "Raptor test" ) - +include(CTest) enable_testing() add_executable(${PROJECT_NAME}) target_sources(${PROJECT_NAME} PRIVATE - test_raptor.cpp test_routeBuilder.cpp - test_raptorDataBuilder.cpp + test_raptorAlgorithm.cpp RaptorRouterTestBuilder.h RaptorRouterTestBuilder.cpp ) @@ -29,7 +28,8 @@ target_link_libraries(${PROJECT_NAME} PRIVATE ) set(BINARY ${PROJECT_NAME}) -add_test(NAME ${BINARY} COMMAND ${BINARY}) +add_test(NAME RaptorAlgoTest COMMAND ${BINARY}_test) +add_test(NAME RouteBuilderTest COMMAND ${BINARY}_test) target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_BINARY_DIR}) target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/logging/include) @@ -38,8 +38,6 @@ target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/raptor/in target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/raptor/include/config) target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/schedule/include) - add_definitions(-DTEST_DATA_DIRRECTORY="C:/Users/MichaelBrunner/Downloads/gtfs_fp2024_2024-05-27/Verkehrsbetriebe_der_Stadt_St_Gallen/") - # if(USE_ZURICH_GTFS) # # # add_definitions(-DTEST_DATA_DIR="C:/Users/MichaelBrunner/Downloads/2024_google_transit/") diff --git a/raptor/test/RaptorRouterTestBuilder.h b/raptor/test/RaptorRouterTestBuilder.h index fe8df40e..0ce37881 100644 --- a/raptor/test/RaptorRouterTestBuilder.h +++ b/raptor/test/RaptorRouterTestBuilder.h @@ -2,8 +2,7 @@ // Created by MichaelBrunner on 20/07/2024. // -#ifndef RAPTORROUTERTESTBUILDER_H -#define RAPTORROUTERTESTBUILDER_H +#pragma once #include "utils/RaptorDataBuilder.h" #include @@ -75,4 +74,3 @@ class RaptorRouterTestBuilder static std::shared_ptr build(const std::vector& routes, const std::vector& transfers, int dayStart, int dayEnd, int sameStopTransferTime); }; -#endif //RAPTORROUTERTESTBUILDER_H diff --git a/raptor/test/sample-feed/agency.txt b/raptor/test/sample-feed/agency.txt deleted file mode 100644 index 8a3578f4..00000000 --- a/raptor/test/sample-feed/agency.txt +++ /dev/null @@ -1,2 +0,0 @@ -agency_id,agency_name,agency_url,agency_timezone -"DTA","Demo Transit Authority","http://google.com","America/Los_Angeles" \ No newline at end of file diff --git a/raptor/test/sample-feed/calendar.txt b/raptor/test/sample-feed/calendar.txt deleted file mode 100644 index 99acc2ec..00000000 --- a/raptor/test/sample-feed/calendar.txt +++ /dev/null @@ -1,3 +0,0 @@ -service_id,monday,tuesday,wednesday,thursday,friday,saturday,sunday,start_date,end_date -"FULLW","1","1","1","1","1","1","1","20070101","20101231" -"WE","0","0","0","0","0","1","1","20070101","20101231" \ No newline at end of file diff --git a/raptor/test/sample-feed/calendar_dates.txt b/raptor/test/sample-feed/calendar_dates.txt deleted file mode 100644 index 3b4c9b80..00000000 --- a/raptor/test/sample-feed/calendar_dates.txt +++ /dev/null @@ -1,2 +0,0 @@ -service_id,date,exception_type -"FULLW","20070604","2" \ No newline at end of file diff --git a/raptor/test/sample-feed/fare_attributes.txt b/raptor/test/sample-feed/fare_attributes.txt deleted file mode 100644 index 9c3b421f..00000000 --- a/raptor/test/sample-feed/fare_attributes.txt +++ /dev/null @@ -1,3 +0,0 @@ -fare_id,price,currency_type,payment_method,transfers,transfer_duration -p,1.25,USD,0,0, -a,5.25,USD,0,0, \ No newline at end of file diff --git a/raptor/test/sample-feed/fare_rules.txt b/raptor/test/sample-feed/fare_rules.txt deleted file mode 100644 index acf470dd..00000000 --- a/raptor/test/sample-feed/fare_rules.txt +++ /dev/null @@ -1,5 +0,0 @@ -fare_id,route_id,origin_id,destination_id,contains_id -p,AB,,, -p,STBA,,, -p,BFC,,, -a,AAMV,,, \ No newline at end of file diff --git a/raptor/test/sample-feed/frequencies.txt b/raptor/test/sample-feed/frequencies.txt deleted file mode 100644 index 47941ef3..00000000 --- a/raptor/test/sample-feed/frequencies.txt +++ /dev/null @@ -1,12 +0,0 @@ -trip_id,start_time,end_time,headway_secs -STBA,6:00:00,22:00:00,1800 -CITY1,6:00:00,7:59:59,1800 -CITY2,6:00:00,7:59:59,1800 -CITY1,8:00:00,9:59:59,600 -CITY2,8:00:00,9:59:59,600 -CITY1,10:00:00,15:59:59,1800 -CITY2,10:00:00,15:59:59,1800 -CITY1,16:00:00,18:59:59,600 -CITY2,16:00:00,18:59:59,600 -CITY1,19:00:00,22:00:00,1800 -CITY2,19:00:00,22:00:00,1800 \ No newline at end of file diff --git a/raptor/test/sample-feed/routes.txt b/raptor/test/sample-feed/routes.txt deleted file mode 100644 index eacd412e..00000000 --- a/raptor/test/sample-feed/routes.txt +++ /dev/null @@ -1,6 +0,0 @@ -route_id,agency_id,route_short_name,route_long_name,route_desc,route_type,route_url,route_color,route_text_color -"AB","DTA","10","Airport - Bullfrog","","3","","","" -"BFC","DTA","20","Bullfrog - Furnace Creek Resort","","3","","","" -"STBA","DTA","30","Stagecoach - Airport Shuttle","","3","","","" -"CITY","DTA","40","City","","3","","","" -"AAMV","DTA","50","Airport - Amargosa Valley","","3","","","" \ No newline at end of file diff --git a/raptor/test/sample-feed/shapes.txt b/raptor/test/sample-feed/shapes.txt deleted file mode 100644 index aa62a022..00000000 --- a/raptor/test/sample-feed/shapes.txt +++ /dev/null @@ -1 +0,0 @@ -shape_id,shape_pt_lat,shape_pt_lon,shape_pt_sequence,shape_dist_traveled \ No newline at end of file diff --git a/raptor/test/sample-feed/stop_times.txt b/raptor/test/sample-feed/stop_times.txt deleted file mode 100644 index 530252ab..00000000 --- a/raptor/test/sample-feed/stop_times.txt +++ /dev/null @@ -1,29 +0,0 @@ -trip_id,arrival_time,departure_time,stop_id,stop_sequence,stop_headsign,pickup_type,drop_off_time,shape_dist_traveled -"STBA","6:00:00","6:00:00","STAGECOACH","1","","","" -"STBA","6:20:00","6:20:00","BEATTY_AIRPORT","2","","","" -"CITY1","6:00:00","6:00:00","STAGECOACH","1","","","" -"CITY1","6:05:00","6:07:00","NANAA","2","","","" -"CITY1","6:12:00","6:14:00","NADAV","3","","","" -"CITY1","6:19:00","6:21:00","DADAN","4","","","" -"CITY1","6:26:00","6:28:00","EMSI","5","","","" -"CITY2","6:28:00","6:30:00","EMSI","1","","","" -"CITY2","6:35:00","6:37:00","DADAN","2","","","" -"CITY2","6:42:00","6:44:00","NADAV","3","","","" -"CITY2","6:49:00","6:51:00","NANAA","4","","","" -"CITY2","6:56:00","6:58:00","STAGECOACH","5","","","" -"AB1","8:00:00","8:00:00","BEATTY_AIRPORT","1","","","" -"AB1","8:10:00","8:15:00","BULLFROG","2","","","" -"AB2","12:05:00","12:05:00","BULLFROG","1","","","" -"AB2","12:15:00","12:15:00","BEATTY_AIRPORT","2","","","" -"BFC1","8:20:00","8:20:00","BULLFROG","1","","","" -"BFC1","9:20:00","9:20:00","FUR_CREEK_RES","2","","","" -"BFC2","11:00:00","11:00:00","FUR_CREEK_RES","1","","","" -"BFC2","12:00:00","12:00:00","BULLFROG","2","","","" -"AAMV1","8:00:00","8:00:00","BEATTY_AIRPORT","1","","","" -"AAMV1","9:00:00","9:00:00","AMV","2","","","" -"AAMV2","10:00:00","10:00:00","AMV","1","","","" -"AAMV2","11:00:00","11:00:00","BEATTY_AIRPORT","2","","","" -"AAMV3","13:00:00","13:00:00","BEATTY_AIRPORT","1","","","" -"AAMV3","14:00:00","14:00:00","AMV","2","","","" -"AAMV4","15:00:00","15:00:00","AMV","1","","","" -"AAMV4","16:00:00","16:00:00","BEATTY_AIRPORT","2","","","" \ No newline at end of file diff --git a/raptor/test/sample-feed/stops.txt b/raptor/test/sample-feed/stops.txt deleted file mode 100644 index 0a15701b..00000000 --- a/raptor/test/sample-feed/stops.txt +++ /dev/null @@ -1,10 +0,0 @@ -stop_id,stop_name,stop_desc,stop_lat,stop_lon,zone_id,stop_url -"FUR_CREEK_RES","Furnace Creek Resort (Demo)","","36.425288","-117.133162","","" -"BEATTY_AIRPORT","Nye County Airport (Demo)","","36.868446","-116.784582","","" -"BULLFROG","Bullfrog (Demo)","","36.88108","-116.81797","","" -"STAGECOACH","Stagecoach Hotel & Casino (Demo)","","36.915682","-116.751677","","" -"NADAV","North Ave / D Ave N (Demo)","","36.914893","-116.76821","","" -"NANAA","North Ave / N A Ave (Demo)","","36.914944","-116.761472","","" -"DADAN","Doing Ave / D Ave N (Demo)","","36.909489","-116.768242","","" -"EMSI","E Main St / S Irving St (Demo)","","36.905697","-116.76218","","" -"AMV","Amargosa Valley (Demo)","","36.641496","-116.40094","","" \ No newline at end of file diff --git a/raptor/test/sample-feed/trips.txt b/raptor/test/sample-feed/trips.txt deleted file mode 100644 index 5869c830..00000000 --- a/raptor/test/sample-feed/trips.txt +++ /dev/null @@ -1,12 +0,0 @@ -route_id,service_id,trip_id,trip_headsign,direction_id,block_id,shape_id -"AB","FULLW","AB1","to Bullfrog","0","1","" -"AB","FULLW","AB2","to Airport","1","2","" -"STBA","FULLW","STBA","Shuttle","","","" -"CITY","FULLW","CITY1","","0","","" -"CITY","FULLW","CITY2","","1","","" -"BFC","FULLW","BFC1","to Furnace Creek Resort","0","1","" -"BFC","FULLW","BFC2","to Bullfrog","1","2","" -"AAMV","WE","AAMV1","to Amargosa Valley","0","","" -"AAMV","WE","AAMV2","to Airport","1","","" -"AAMV","WE","AAMV3","to Amargosa Valley","0","","" -"AAMV","WE","AAMV4","to Airport","1","","" \ No newline at end of file diff --git a/raptor/test/test-data-fictional/routes.txt b/raptor/test/test-data-fictional/routes.txt deleted file mode 100644 index d6904849..00000000 --- a/raptor/test/test-data-fictional/routes.txt +++ /dev/null @@ -1,11 +0,0 @@ -route_id,agency_id,route_short_name,route_long_name,route_desc,route_type -"route1","1","R1","Route 1","Route from stopA to stopC","3" -"route2","1","R2","Route 2","Route from stopC to stopH","3" -"route3","1","R3","Route 3","Route from stopB to stopF","3" -"route4","1","R4","Route 4","Route from stopD to stopL","3" -"AB","DTA","","Airport ⇒ Bullfrog","","3","","" -"BFC","DTA","","Bullfrog ⇒ Furnace Creek Resort","","3","","" -"STBA","DTA","","Stagecoach ⇒ Airport Shuttle","","3","","" -"CITY","DTA","Ō","Bar Circle, Route with ĸool unicode shortname","3","3","","" -"AAMV","DTA","","Airport ⇒ Amargosa Valley","","3","","" - diff --git a/raptor/test/test-data-fictional/stop_times.txt b/raptor/test/test-data-fictional/stop_times.txt deleted file mode 100644 index 03e8d4cc..00000000 --- a/raptor/test/test-data-fictional/stop_times.txt +++ /dev/null @@ -1,49 +0,0 @@ -trip_id,arrival_time,departure_time,stop_id,stop_sequence,pickup_type -"trip1","10:00:00","10:00:00","stopA","1","0" -"trip1","10:10:00","10:10:00","stopB","2","0" -"trip1","10:20:00","10:20:00","stopC","3","0" -"trip2","11:00:00","11:00:00","stopC","1","0" -"trip2","11:10:00","11:10:00","stopD","2","0" -"trip2","11:20:00","11:20:00","stopE","3","0" -"trip2","11:30:00","11:30:00","stopG","4","0" -"trip2","11:40:00","11:40:00","stopF","5","0" -"trip2","11:50:00","11:50:00","stopH","6","0" -"trip3","12:00:00","12:00:00","stopB","1","0" -"trip3","12:10:00","12:10:00","stopC","2","0" -"trip3","12:20:00","12:20:00","stopF","3","0" -"trip4","13:00:00","13:00:00","stopC","1","0" -"trip4","13:10:00","13:10:00","stopD","2","0" -"trip4","13:20:00","13:20:00","stopE","3","0" -"trip4","13:30:00","13:30:00","stopG","4","0" -"trip4","13:40:00","13:40:00","stopI","5","0" -"trip4","13:50:00","13:50:00","stopJ","6","0" -"trip4","14:00:00","14:00:00","stopK","7","0" -"trip4","14:10:00","14:10:00","stopL","8","0" -"STBA","6:00:00","6:00:00","STAGECOACH","0","to airport","1","0","0.212" -"STBA","6:20:00","6:20:00","BEATTY_AIRPORT","2","","0","0","1.043" -"CITY1","6:00:00","6:00:00","STAGECOACH","0","","","","" -"CITY1","6:05:00","6:07:00","NANAA","5","going to nadav","2","3","" -"CITY1","6:12:00","6:14:00","NADAV","10","","","","" -"CITY1","6:19:00","6:21:00","DADAN","15","","","","" -"CITY1","6:26:00","6:28:00","EMSI","20","","","","" -"CITY2","6:28:00","6:30:00","EMSI","100","","","","" -"CITY2","6:35:00","6:37:00","DADAN","200","","","","" -"CITY2","6:42:00","6:44:00","NADAV","300","","","","" -"CITY2","6:49:00","6:51:00","NANAA","400","","","","" -"CITY2","6:56:00","6:58:00","STAGECOACH","500","","","","" -"AB1","8:00:00","8:00:00","BEATTY_AIRPORT","1","","","","" -"AB1","8:10:00","8:15:00","BULLFROG","2","","","","" -"AB2","12:05:00","12:05:00","BULLFROG","1","","","","" -"AB2","12:15:00","12:15:00","BEATTY_AIRPORT","2","","","","" -"BFC1","8:20:00","8:20:00","BULLFROG","1","","","","" -"BFC1","9:20:00","9:20:00","FUR_CREEK_RES","2","","","","" -"BFC2","11:00:00","11:00:00","FUR_CREEK_RES","1","","","","" -"BFC2","12:00:00","12:00:00","BULLFROG","2","","","","" -"AAMV1","8:00:00","8:00:00","BEATTY_AIRPORT","1","","","","" -"AAMV1","9:00:00","9:00:00","AMV","2","","","","" -"AAMV2","10:00:00","10:00:00","AMV","1","","","","" -"AAMV2","11:00:00","11:00:00","BEATTY_AIRPORT","2","","","","" -"AAMV3","13:00:00","13:00:00","BEATTY_AIRPORT","1","","","","" -"AAMV3","14:00:00","14:00:00","AMV","2","","","","" -"AAMV4","15:00:00","15:00:00","AMV","1","","","","" -"AAMV4","16:00:00","16:00:00","BEATTY_AIRPORT","2","","","","" \ No newline at end of file diff --git a/raptor/test/test-data-fictional/stops.txt b/raptor/test/test-data-fictional/stops.txt deleted file mode 100644 index c2d887aa..00000000 --- a/raptor/test/test-data-fictional/stops.txt +++ /dev/null @@ -1,22 +0,0 @@ -stop_id,stop_name,stop_lat,stop_lon,location_type,parent_station -"stopA","Stop A","47.000001","8.000001","","" -"stopB","Stop B","47.000002","8.000002","","" -"stopC","Stop C","47.000003","8.000003","","" -"stopD","Stop D","47.000004","8.000004","","" -"stopE","Stop E","47.000005","8.000005","","" -"stopF","Stop F","47.000006","8.000006","","" -"stopG","Stop G","47.000007","8.000007","","" -"stopH","Stop H","47.000008","8.000008","","" -"stopI","Stop I","47.000009","8.000009","","" -"stopJ","Stop J","47.000010","8.000010","","" -"stopK","Stop K","47.000011","8.000011","","" -"stopL","Stop L","47.000012","8.000012","","" -"FUR_CREEK_RES","Furnace Creek Resort (Demo)","36.425288","-117.133162","","","1234","", -"BEATTY_AIRPORT","Nye County Airport (Demo)","36.868446","-116.784582","","","1235","0","BEATTY_AIRPORT_STATION" -"BULLFROG","Bullfrog (Demo)","36.88108","-116.81797","","","","" -"STAGECOACH","Stagecoach Hotel & Casino (Demo)","36.915682","-116.751677","","","1236","","" -"NADAV","North Ave / D Ave N (Demo)","36.914893","-116.76821","","","1237","","" -"NANAA","North Ave / N A Ave (Demo)","36.914944","-116.761472","","","1238","","" -"DADAN","Doing Ave / D Ave N (Demo)","36.909489","-116.768242","","","","","" -"EMSI","E Main St / S Irving St (Demo)","36.905697","-116.76218","","","","","" -"AMV","Amargosa Valley (Demo)","36.641496","-116.40094","","","","","" diff --git a/raptor/test/test-data-fictional/transfers.txt b/raptor/test/test-data-fictional/transfers.txt deleted file mode 100644 index 61dd0c9e..00000000 --- a/raptor/test/test-data-fictional/transfers.txt +++ /dev/null @@ -1,9 +0,0 @@ -from_stop_id,to_stop_id,transfer_type,min_transfer_time -"stopB","stopB","0","120" -"stopC","stopC","0","120" -"stopD","stopD","0","120" -"stopE","stopE","0","120" -"stopG","stopG","0","120" -"stopF","stopF","0","120" -"NADAV","NANAA","3","120" -"EMSI","NANAA","2","180" \ No newline at end of file diff --git a/raptor/test/test-data-fictional/trips.txt b/raptor/test/test-data-fictional/trips.txt deleted file mode 100644 index 26e86711..00000000 --- a/raptor/test/test-data-fictional/trips.txt +++ /dev/null @@ -1,16 +0,0 @@ -route_id,service_id,trip_id,trip_headsign,trip_short_name,direction_id -"route1","1","trip1","Route 1","Trip 1","0" -"route2","1","trip2","Route 2","Trip 2","0" -"route3","1","trip3","Route 3","Trip 3","0" -"route4","1","trip4","Route 4","Trip 4","0" -"AB","FULLW","AB1","to Bullfrog","0","1","" -"AB","FULLW","AB2","to Airport","1","2","" -"STBA","FULLW","STBA","Shuttle","","","" -"CITY","FULLW","CITY1","","0","","" -"CITY","FULLW","CITY2","","1","","" -"BFC","FULLW","BFC1","to Furnace Creek Resort","0","1","" -"BFC","FULLW","BFC2","to Bullfrog","1","2","" -"AAMV","WE","AAMV1","to Amargosa Valley","0","","" -"AAMV","WE","AAMV2","to Airport","1","","" -"AAMV","WE","AAMV3","to Amargosa Valley","0","","" -"AAMV","WE","AAMV4","to Airport","1","","" \ No newline at end of file diff --git a/raptor/test/test_raptor.cpp b/raptor/test/test_raptor.cpp deleted file mode 100644 index 463f2e67..00000000 --- a/raptor/test/test_raptor.cpp +++ /dev/null @@ -1,192 +0,0 @@ -// // -// // Created by MichaelBrunner on 27/06/2024. -// // -// -// -// #include "DataReader.h" -// #include "GtfsReaderStrategyFactory.h" -// #include "IRaptorAlgorithmFactory.h" -// #include "LoggerFactory.h" -// #include "Raptor.h" -// #include "RaptorAlgorithmFactory.h" -// #include "raptorTypes.h" -// #include "gtfs/GtfsTxtReaderStrategyFactory.h" -// -// #include -// -// #include -// #include -// -// -// ////////// TEST ROUTES ////////// -// -// //// O (stopA) -// //// | -// //// O (stopB) -// //// |\ -// //// | \ -// //// O O (stopC) -// //// | | -// //// | O (stopD) -// //// | | \ -// //// | | \ -// //// | O O (stopE) -// //// | | -// //// | O (stopG) -// //// | / \ -// //// | / \ -// //// O O O (stopF) -// //// \ / \ -// //// O \ -// //// O (stopH) -// //// | -// //// O (stopI) -// //// | -// //// O (stopJ) -// //// | -// //// O (stopK) -// //// | -// //// O (stopL) -// /// -// -// -// /// O (Furnace Creek Resort) -// /// | -// /// O (Nye County Airport) -// /// | -// /// O (Bullfrog) ------------ O (Stagecoach Hotel & Casino) -// /// \ / -// /// \ / -// /// \ / -// /// \ / -// /// O (North Ave / D Ave N) -// /// | -// /// O (North Ave / N A Ave) -// /// | -// /// O (Doing Ave / D Ave N) -// /// | -// /// O (E Main St / S Irving St) -// /// | -// /// O (Amargosa Valley) -// /// -// -// -// -// class RaptorTest : public testing::Test -// { -// protected: -// std::unique_ptr>> reader; -// // raptor::utils::ConnectionRequest request; -// -// std::string basePath = TEST_DATA_DIRRECTORY; -// -// std::unique_ptr readerFactory; -// -// std::map lFileNameMap; -// -// void SetUp() override { -// basePath.back() == '/' ? basePath : basePath += '/'; -// readerFactory = schedule::gtfs::createGtfsReaderStrategyFactory(schedule::gtfs::ReaderType::CSV_PARALLEL, std::move(basePath)); -// } -// -// void TearDown() override { -// std::cout << "GtfsReaderStrategiesTest::TearDown()" << '\n'; -// reader.reset(nullptr); -// } -// }; -// -// -// TEST_F(RaptorTest, InitialTest) { -// -// -// // const auto agencyStrategy = readerFactory->getStrategy(schedule::gtfs::GtfsReaderStrategyFactory::Type::AGENCY); -// // const auto calendarStrategy = readerFactory->getStrategy(schedule::gtfs::GtfsReaderStrategyFactory::Type::CALENDAR); -// // const auto calendarDatesStrategy = readerFactory->getStrategy(schedule::gtfs::GtfsReaderStrategyFactory::Type::CALENDAR_DATE); -// const auto routesStrategy = readerFactory->getStrategy(GtfsStrategyType::ROUTE); -// const auto stopStrategy = readerFactory->getStrategy(GtfsStrategyType::STOP); -// const auto stopTimeStrategy = readerFactory->getStrategy(GtfsStrategyType::STOP_TIME); -// const auto transferStrategy = readerFactory->getStrategy(GtfsStrategyType::TRANSFER); -// const auto tripStrategy = readerFactory->getStrategy(GtfsStrategyType::TRIP); -// -// std::vector strategies = {/*agencyStrategy, calendarStrategy, calendarDatesStrategy,*/ routesStrategy, stopStrategy, stopTimeStrategy, transferStrategy, tripStrategy}; // -// -// const std::unique_ptr>> reader = std::make_unique(std::move(strategies)); -// reader->readData(); -// auto relationManager = schedule::gtfs::TimetableManager(std::move(reader->getData().get())); -// -// // auto stopIdSource = relationManager.getStopIdFromStopName("Zürich, Bahnhof Affoltern"); -// // ASSERT_STREQ(stopIdSource.c_str(), "ch:1:sloid:91054::22"); -// -// // auto stopIdSource = relationManager.getStopIdFromStopName("Meilen, Bahnhof"); // "Erlenbach ZH, Trottgatter" -// // auto stopIdSources = relationManager.getStopIdsFromStopName("Küsnacht ZH, Bahnhof"); -// // -// // auto stopIdTarget = relationManager.getStopIdFromStopName("Kempraten, Bahnhof"); // "Erlenbach ZH, Bahnhof "Erlenbach ZH, Erlenhöhe"" -// // // ASSERT_STREQ(stopIdTarget.c_str(), "ch:1:sloid:87965::50"); -// // auto stopIdTargets = relationManager.getStopIdsFromStopName("Erlenbach ZH, Bahnhof"); // "Erlenbach ZH, Erlenhöhe""Meilen, Bahnhof"Zürich, Seebach -// -// auto stopIdSources = relationManager.getStopIdsFromStopName("Zürich, Holzerhurd"); -// -// auto stopIdTargets = relationManager.getStopIdsFromStopName("Zürich, Bahnhof Stadelhofen"); -// -// // stopIdTarget = relationManager.getStopIdFromStopName("Zürich, Seebach"); -// // ASSERT_TRUE(stopIdTarget.c_str() == "ch:1:sloid:91354::1" || "ch:1:sloid:91354::20" || "ch:1:sloid:91354::21" || "ch:1:sloid:91354::22" || "ch:1:sloid:91354::50"); -// -// -// const std::unique_ptr factory = std::make_unique(); -// ASSERT_TRUE(factory); -// -// auto strategy = factory->create(raptor::strategy::factory::IRaptorAlgorithmFactory::RAPTOR, std::move(relationManager)); -// std::unique_ptr raptor = std::make_unique(std::move(strategy)); -// ASSERT_TRUE(raptor); -// -// const auto connectionRequest = raptor::utils::ConnectionRequest{std::move(stopIdSources), std::move(stopIdTargets), 35999}; // 09:59:59 -// -// auto connections = raptor->getConnections(connectionRequest); -// } -// -// TEST_F(RaptorTest, RaptorAlgorithm) { -// -// // const auto agencyStrategy = readerFactory->getStrategy(schedule::gtfs::GtfsReaderStrategyFactory::Type::AGENCY); -// const auto calendarStrategy = readerFactory->getStrategy(GtfsStrategyType::CALENDAR); -// const auto calendarDatesStrategy = readerFactory->getStrategy(GtfsStrategyType::CALENDAR_DATE); -// const auto routesStrategy = readerFactory->getStrategy(GtfsStrategyType::ROUTE); -// const auto stopStrategy = readerFactory->getStrategy(GtfsStrategyType::STOP); -// const auto stopTimeStrategy = readerFactory->getStrategy(GtfsStrategyType::STOP_TIME); -// const auto transferStrategy = readerFactory->getStrategy(GtfsStrategyType::TRANSFER); -// const auto tripStrategy = readerFactory->getStrategy(GtfsStrategyType::TRIP); -// -// std::vector strategies = {/*agencyStrategy,*/ -// calendarStrategy, -// calendarDatesStrategy, -// routesStrategy, -// stopStrategy, -// stopTimeStrategy, -// transferStrategy, -// tripStrategy}; // -// -// const auto reader = std::make_unique(std::move(strategies)); -// reader->readData(); -// -// auto timeTableManager = schedule::gtfs::TimetableManager(std::move(reader->getData().get())); -// -// auto stopIdSources = timeTableManager.getStopIdsFromStopName("St. Gallen, Vonwil"); -// ASSERT_TRUE(!stopIdSources.empty()); -// -// auto stopIdTargets = timeTableManager.getStopIdsFromStopName("St. Gallen,Klinik Stephanshorn"); -// ASSERT_TRUE(!stopIdTargets.empty()); -// std::unordered_map> routeStops; -// -// getLogger(Target::CONSOLE, LoggerName::RAPTOR)->info(" ------------------------- "); -// getLogger(Target::CONSOLE, LoggerName::RAPTOR)->info(" "); -// -// const auto factory = std::make_unique(); -// ASSERT_TRUE(factory); -// -// auto strategy = factory->create(raptor::strategy::factory::IRaptorAlgorithmFactory::RAPTOR, std::move(timeTableManager)); -// std::unique_ptr raptor = std::make_unique(std::move(strategy)); -// ASSERT_TRUE(raptor); -// -// const auto connectionRequest = raptor::utils::ConnectionRequest{std::move(stopIdSources), std::move(stopIdTargets), 52'920}; // 14:42:00 -// -// auto connections = raptor->getConnections(connectionRequest); -// } diff --git a/raptor/test/test_raptorAlgorithm.cpp b/raptor/test/test_raptorAlgorithm.cpp new file mode 100644 index 00000000..b18ecb13 --- /dev/null +++ b/raptor/test/test_raptorAlgorithm.cpp @@ -0,0 +1,162 @@ +// +// Created by MichaelBrunner on 20/07/2024. +// + + +#include "Leg.h" +#include "LocalDateTime.h" +#include "LoggerFactory.h" +#include "RaptorRouter.h" +#include "RaptorRouterTestBuilder.h" +#include +#include +#include +#include +#include +#include +#include +#include + + +class RaptorAlgoTest : public ::testing::Test +{ +protected: + std::unique_ptr builder; + + raptor::utils::LocalDateTime START_OF_DAY{raptor::utils::LocalDateTime{2021y, std::chrono::January, 1d, 0h, 0min, 0s}}; + + raptor::utils::LocalDateTime FIVE_AM; + raptor::utils::LocalDateTime EIGHT_AM; + raptor::utils::LocalDateTime NINE_AM; + + void SetUp() override { + builder = std::make_unique(); + + FIVE_AM = START_OF_DAY.addHours(std::chrono::hours(5)); + EIGHT_AM = START_OF_DAY.addHours(std::chrono::hours(8)); + NINE_AM = START_OF_DAY.addHours(std::chrono::hours(9)); + } + + void TearDown() override { + builder.reset(); + } +}; + +TEST_F(RaptorAlgoTest, TestRaptorAlgo1) { + + // Arrange + const auto raptorData = builder->buildWithDefaults(); + + const std::string STOP_A = "A"; + const std::string STOP_B = "B"; + + // Get the list of connections between the stops + const auto queryConfig = raptor::config::QueryConfig(); + const auto raptorRouter = raptor::RaptorRouter(std::move(*raptorData)); + auto NINE_AM_SECONDS = static_cast(START_OF_DAY.secondsOfDay()); + // Act + const auto connections = raptorRouter.routeEarliestArrival({{"A", NINE_AM_SECONDS}}, {{"B", 0}}, queryConfig); + + // Assert + const auto legs = connections[0]->getLegs(); + const auto& leg = legs[0]; + const auto departureTime = raptor::utils::fromSecondsOfToday(leg->getDepartureTime()); + const auto arrivalTime = raptor::utils::fromSecondsOfToday(leg->getArrivalTime()); + + ASSERT_EQ(connections.size(), 1); + ASSERT_EQ(legs.size(), 1); + ASSERT_EQ(leg->getRouteId(), "R1-F"); + ASSERT_EQ(leg->getTripId(), "R1-F-0"); + ASSERT_EQ(departureTime.secondsOfDay(), 18'000); + ASSERT_EQ(arrivalTime.secondsOfDay(), 18'300); +} + +TEST_F(RaptorAlgoTest, TestRaptorAlgo2) { + + // Arrange + const auto raptorData = builder->buildWithDefaults(); + + const std::string STOP_A = "A"; + const std::string STOP_B = "Q"; + + const auto queryConfig = raptor::config::QueryConfig(); + const auto raptorRouter = raptor::RaptorRouter(*raptorData); + auto EIGHT_AM_SECONDS = static_cast(EIGHT_AM.secondsOfDay()); + + // Act + const auto connections = raptorRouter.routeEarliestArrival({{"A", EIGHT_AM_SECONDS}}, {{"Q", 0}}, queryConfig); + + // Assert + ASSERT_EQ(connections.size(), 2); + + ///////////////////// test first connection ///////////////////// + /// + { + const auto& connection1 = connections[0]; + + ASSERT_EQ(connection1->getLegs().size(), 3); + + const auto leg1 = connection1->getLegs()[0]; + ASSERT_EQ(leg1->getRouteId(), "R1-F"); + ASSERT_EQ(leg1->getTripId(), "R1-F-12"); + ASSERT_EQ(leg1->getFromStopId(), "A"); + ASSERT_EQ(leg1->getToStopId(), "D"); + ASSERT_EQ(leg1->getDepartureTime(), 28'800); + ASSERT_EQ(leg1->getArrivalTime(), 29'820); + ASSERT_TRUE(leg1->getType().value() == raptor::Leg::Type::ROUTE); + + const auto leg2 = connection1->getLegs()[1]; + ASSERT_EQ(leg2->getRouteId(), "transfer_D_N"); + ASSERT_EQ(leg2->getTripId(), ""); + ASSERT_EQ(leg2->getFromStopId(), "D"); + ASSERT_EQ(leg2->getToStopId(), "N"); + ASSERT_EQ(leg2->getDepartureTime(), 29'820); + ASSERT_EQ(leg2->getArrivalTime(), 33'420); + ASSERT_TRUE(leg2->getType().value() == raptor::Leg::Type::WALK_TRANSFER); + + const auto leg3 = connection1->getLegs()[2]; + ASSERT_EQ(leg3->getRouteId(), "R3-F"); + ASSERT_EQ(leg3->getTripId(), "R3-F-17"); + ASSERT_EQ(leg3->getFromStopId(), "N"); + ASSERT_EQ(leg3->getToStopId(), "Q"); + ASSERT_EQ(leg3->getDepartureTime(), 34'020); + ASSERT_EQ(leg3->getArrivalTime(), 35'040); + ASSERT_EQ(leg3->getType().value(), raptor::Leg::Type::ROUTE); + } + + ///////////////////// test second connection ///////////////////// + /// + + { + const auto& connection2 = connections[1]; + + ASSERT_EQ(connection2->getLegs().size(), 3); + + const auto leg1 = connection2->getLegs()[0]; + ASSERT_EQ(leg1->getRouteId(), "R1-F"); + ASSERT_EQ(leg1->getTripId(), "R1-F-12"); + ASSERT_EQ(leg1->getFromStopId(), "A"); + ASSERT_EQ(leg1->getToStopId(), "F"); + ASSERT_EQ(leg1->getDepartureTime(), 28'800); + ASSERT_EQ(leg1->getArrivalTime(), 30'540); + ASSERT_TRUE(leg1->getType().value() == raptor::Leg::Type::ROUTE); + + const auto leg2 = connection2->getLegs()[1]; + ASSERT_EQ(leg2->getRouteId(), "R4-R"); + ASSERT_EQ(leg2->getTripId(), "R4-R-14"); + ASSERT_EQ(leg2->getFromStopId(), "F"); + ASSERT_EQ(leg2->getToStopId(), "P"); + ASSERT_EQ(leg2->getDepartureTime(), 30'960); + ASSERT_EQ(leg2->getArrivalTime(), 31'260); + ASSERT_TRUE(leg2->getType().value() == raptor::Leg::Type::ROUTE); + + const auto leg3 = connection2->getLegs()[2]; + ASSERT_EQ(leg3->getRouteId(), "R3-F"); + ASSERT_EQ(leg3->getTripId(), "R3-F-14"); + ASSERT_EQ(leg3->getFromStopId(), "P"); + ASSERT_EQ(leg3->getToStopId(), "Q"); + ASSERT_EQ(leg3->getDepartureTime(), 32'040); + ASSERT_EQ(leg3->getArrivalTime(), 32'340); + ASSERT_EQ(leg3->getType().value(), raptor::Leg::Type::ROUTE); + } +} diff --git a/raptor/test/test_raptorDataBuilder.cpp b/raptor/test/test_raptorDataBuilder.cpp deleted file mode 100644 index 13a876d2..00000000 --- a/raptor/test/test_raptorDataBuilder.cpp +++ /dev/null @@ -1,93 +0,0 @@ -// -// Created by MichaelBrunner on 20/07/2024. -// - - -#include "Leg.h" -#include "LocalDateTime.h" -#include "LoggerFactory.h" -#include "RaptorRouter.h" -#include "RaptorRouterTestBuilder.h" -#include "utils/RaptorDataBuilder.h" - - -#include -#include -#include -#include -#include -#include -#include -#include - - - -TEST(RaptorAlgoTest, TestRaptorAlgo1) { - // Setup the builder and build the RaptorAlgorithm instance - RaptorRouterTestBuilder builder; - const auto raptorData = builder.buildWithDefaults(); - - // Define constants for the test - const std::string STOP_A = "A"; - const std::string STOP_B = "B"; - constexpr int NINE_AM = 9 * 3600; // 9 AM in seconds - - // Get the list of connections between the stops - const auto queryConfig = raptor::config::QueryConfig(); - const auto raptorRouter = raptor::RaptorRouter(std::move(*raptorData)); - auto result = raptorRouter.routeEarliestArrival({{"A", 0}}, {{"B", 0}}, queryConfig); - - std::ranges::for_each(result, [](const auto& connection) { - const auto legs = connection->getLegs(); - getConsoleLogger(LoggerName::RAPTOR)->info(std::format("Connection: {}", connection->getLegs().size())); - }); - - - // std::vector connections = ConvenienceMethods::routeLatestDeparture(raptor, STOP_A, STOP_B, NINE_AM); - - // Assert the size of the connections list - // ASSERT_EQ(connections.size(), 1); -} - -TEST(RaptorAlgoTest, TestRaptorAlgo2) { - - const raptor::utils::LocalDateTime START_OF_DAY{2021y, std::chrono::January, 1d, 0h, 0min, 0s}; - const raptor::utils::LocalDateTime FIVE_AM = START_OF_DAY.addHours(std::chrono::hours(5)); - const raptor::utils::LocalDateTime EIGHT_AM = START_OF_DAY.addHours(std::chrono::hours(8)); - const raptor::utils::LocalDateTime NINE_AM = START_OF_DAY.addHours(std::chrono::hours(9)); - - // Setup the builder and build the RaptorAlgorithm instance - RaptorRouterTestBuilder builder; - const auto raptorData = builder.buildWithDefaults(); - - // Define constants for the test - const std::string STOP_A = "A"; - const std::string STOP_B = "Q"; - - // Get the list of connections between the stops - const auto queryConfig = raptor::config::QueryConfig(); - const auto raptorRouter = raptor::RaptorRouter(*raptorData); - auto EIGHT_AM_SECONDS = static_cast(EIGHT_AM.secondsOfDay()); - - for (auto results = raptorRouter.routeEarliestArrival({{"A", EIGHT_AM_SECONDS}}, {{"Q", 0}}, queryConfig); - const auto& connection : results) - { - for (const auto legs = connection->getLegs(); - const auto& leg : legs) - { - getConsoleLogger(LoggerName::RAPTOR)->info(std::format("Route id {}", leg->getRouteId())); - } - } - - // std::vector connections = ConvenienceMethods::routeLatestDeparture(raptor, STOP_A, STOP_B, NINE_AM); - - // Assert the size of the connections list - // ASSERT_EQ(connections.size(), 1); -} - - - -// int main(int argc, char** argv) { -// ::testing::InitGoogleTest(&argc, argv); -// return RUN_ALL_TESTS(); -// } diff --git a/raptor/test/test_routeBuilder.cpp b/raptor/test/test_routeBuilder.cpp index 970b32f7..83257957 100644 --- a/raptor/test/test_routeBuilder.cpp +++ b/raptor/test/test_routeBuilder.cpp @@ -2,10 +2,7 @@ // Created by MichaelBrunner on 20/07/2024. // - - -#include "../include/RouteBuilder.h" - +#include "include/RouteBuilder.h" #include @@ -17,6 +14,7 @@ class RouteBuilderTest : public ::testing::Test static const std::string STOP_1; static const std::string STOP_2; static const std::string STOP_3; + std::unique_ptr builder; void SetUp() override { diff --git a/schedule/CMakeLists.txt b/schedule/CMakeLists.txt index e000891b..cf231dc0 100644 --- a/schedule/CMakeLists.txt +++ b/schedule/CMakeLists.txt @@ -75,6 +75,7 @@ target_sources(${PROJECT_NAME} src/gtfs/GtfsCsvParserReaderStrategyFactory.h src/gtfs/strategies/csv_reader_fast/csv_wrapper.h src/utils/helperFunctions.cpp + src/utils/ServiceDayTime.h PUBLIC include/GtfsData.h include/model/Agency.h @@ -87,7 +88,6 @@ target_sources(${PROJECT_NAME} include/model/Transfer.h include/GtfsReaderStrategyFactory.h include/IGtfsReaderStrategyFactory.h - src/utils/ServiceDayTime.h include/GtfsReader.h include/model/helperFunctions.h ) diff --git a/schedule/benchmarks/CMakeLists.txt b/schedule/benchmarks/CMakeLists.txt index 9b8b0eef..39f631d1 100644 --- a/schedule/benchmarks/CMakeLists.txt +++ b/schedule/benchmarks/CMakeLists.txt @@ -26,16 +26,9 @@ target_link_libraries(${PROJECT_NAME} PRIVATE target_compile_definitions(${PROJECT_NAME} PRIVATE gtfs_EXPORTS) -#target_include_directories(${PROJECT_NAME} PRIVATE ${benchmark_SOURCE_DIR}/include ${benchmark_SOURCE_DIR}) -#target_include_directories(${PROJECT_NAME} PRIVATE ${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}) +add_definitions(-DTEST_DATA_DIR="C:/Users/MichaelBrunner/Downloads/gtfs_fp2024_2024-05-27/") -if(USE_ZURICH_GTFS) - add_definitions(-DTEST_DATA_DIR="C:/Users/MichaelBrunner/Downloads/2024_google_transit/") -else () - add_definitions(-DTEST_DATA_DIR="${CMAKE_SOURCE_DIR}/schedule/test/test-data/") - add_definitions(-DTEST_DATA_DIR_FULL_GTFS="C:/Users/MichaelBrunner/Downloads/gtfs_fp2024_2024-05-27/") -endif() diff --git a/schedule/benchmarks/gtfs_benchmark.cpp b/schedule/benchmarks/gtfs_benchmark.cpp index 9ca52be0..0b76de27 100644 --- a/schedule/benchmarks/gtfs_benchmark.cpp +++ b/schedule/benchmarks/gtfs_benchmark.cpp @@ -6,8 +6,8 @@ #include -#include "../include/GtfsData.h" -#include "model/Agency.h" +#include +#include #include #include @@ -50,20 +50,23 @@ static void BM_reference(benchmark::State& state) { } } -class GtfsReaderFixture : public benchmark::Fixture { +class GtfsReaderFixture : public benchmark::Fixture +{ protected: std::unique_ptr readerFactory; + public: void SetUp(::benchmark::State& state) override { - readerFactory = schedule::gtfs::createGtfsReaderStrategyFactory(schedule::gtfs::ReaderType::TXT, TEST_DATA_DIR); + readerFactory = schedule::gtfs::createGtfsReaderStrategyFactory(schedule::gtfs::ReaderType::CSV_PARALLEL, TEST_DATA_DIR); } void TearDown(::benchmark::State& state) override { } }; -BENCHMARK_F(GtfsReaderFixture, BM_read_agencies)(benchmark::State& state) { - auto strategy = std::vector>(); +BENCHMARK_F(GtfsReaderFixture, BM_read_agencies) +(benchmark::State& state) { + auto strategy = std::vector>{}; const std::function readerStrategy = readerFactory->getStrategy(GtfsStrategyType::AGENCY); strategy.push_back(readerStrategy); const auto reader = std::make_unique(std::move(strategy)); @@ -73,9 +76,9 @@ BENCHMARK_F(GtfsReaderFixture, BM_read_agencies)(benchmark::State& state) { } } -BENCHMARK_F(GtfsReaderFixture, BM_read_calendar_dates)(benchmark::State& state) { +BENCHMARK_F(GtfsReaderFixture, BM_read_calendar_dates) +(benchmark::State& state) { auto strategy = std::vector>(); - std::string basePath = TEST_DATA_DIR; const std::function readerStrategy = readerFactory->getStrategy(GtfsStrategyType::CALENDAR_DATE); strategy.push_back(readerStrategy); const auto reader = std::make_unique(std::move(strategy)); @@ -85,9 +88,9 @@ BENCHMARK_F(GtfsReaderFixture, BM_read_calendar_dates)(benchmark::State& state) } } -BENCHMARK_F(GtfsReaderFixture, BM_read_stop_times)(benchmark::State& state) { +BENCHMARK_F(GtfsReaderFixture, BM_read_stop_times) +(benchmark::State& state) { auto strategy = std::vector>(); - const std::string basePath = TEST_DATA_DIR; const std::function readerStrategy = readerFactory->getStrategy(GtfsStrategyType::STOP_TIME); strategy.push_back(readerStrategy); const auto reader = std::make_unique(std::move(strategy)); @@ -99,11 +102,8 @@ BENCHMARK_F(GtfsReaderFixture, BM_read_stop_times)(benchmark::State& state) { - BENCHMARK_REGISTER_F(GtfsReaderFixture, BM_read_agencies); BENCHMARK_REGISTER_F(GtfsReaderFixture, BM_read_calendar_dates); BENCHMARK_REGISTER_F(GtfsReaderFixture, BM_read_stop_times); BENCHMARK(BM_pointer); BENCHMARK(BM_reference); - - diff --git a/schedule/benchmarks/gtfs_schedule_benchmark.cpp b/schedule/benchmarks/gtfs_schedule_benchmark.cpp index d0d1a015..adffb98d 100644 --- a/schedule/benchmarks/gtfs_schedule_benchmark.cpp +++ b/schedule/benchmarks/gtfs_schedule_benchmark.cpp @@ -2,15 +2,9 @@ // Created by MichaelBrunner on 16/06/2024. // -#include "../include/GtfsReader.h" -#include "gtfs/strategies/GtfsAgencyReader.h" -#include "gtfs/strategies/GtfsCalendarDateReader.h" -#include "gtfs/strategies/GtfsCalendarReader.h" -#include "gtfs/strategies/GtfsRouteReader.h" -#include "gtfs/strategies/GtfsStopReader.h" -#include "gtfs/strategies/GtfsStopTimeReader.h" -#include "gtfs/strategies/GtfsTransferReader.h" -#include "gtfs/strategies/GtfsTripReader.h" +#include "GtfsReaderStrategyFactory.h" +#include "include/GtfsReader.h" + #include #include @@ -24,30 +18,35 @@ static void BM_read_gtfs_schedule(benchmark::State& state) { auto strategy = std::vector>(); - const std::string basePath = TEST_DATA_DIR; - const std::function calendarDatesReaderStrategy = schedule::gtfs::GtfsCalendarDateReader(basePath + "calendar_dates.txt"); - const std::function calendarReaderStrategy = schedule::gtfs::GtfsCalendarReader(basePath + "calendar.txt"); - const std::function stopTimeReaderStrategy = schedule::gtfs::GtfsStopTimeReader(basePath + "stop_times.txt"); - const std::function agencyReaderStrategy = schedule::gtfs::GtfsAgencyReader(basePath + "agency.txt"); - const std::function routeReaderStrategy = schedule::gtfs::GtfsRouteReader(basePath + "routes.txt"); - const std::function stopReaderStrategy = schedule::gtfs::GtfsStopReader(basePath + "stops.txt"); - const std::function transferReaderStrategy = schedule::gtfs::GtfsTransferReader(basePath + "transfers.txt"); - const std::function tripReaderStrategy = schedule::gtfs::GtfsTripReader(basePath + "trips.txt"); - - strategy.push_back(calendarDatesReaderStrategy); - strategy.push_back(stopTimeReaderStrategy); - strategy.push_back(agencyReaderStrategy); - strategy.push_back(routeReaderStrategy); - strategy.push_back(stopReaderStrategy); - strategy.push_back(transferReaderStrategy); - strategy.push_back(tripReaderStrategy); - strategy.push_back(calendarReaderStrategy); - - const auto reader = std::make_unique(std::move(strategy)); - for (auto _ : state) - { - reader->readData(); - } + std::string basePath = TEST_DATA_DIR; + + const auto readerFactory = schedule::gtfs::createGtfsReaderStrategyFactory(schedule::gtfs::ReaderType::CSV_PARALLEL, std::move(basePath)); + + + // create strategy callable objects + const auto agencyStrategy = readerFactory->getStrategy(GtfsStrategyType::AGENCY); + const auto calendarStrategy = readerFactory->getStrategy(GtfsStrategyType::CALENDAR); + const auto calendarDatesStrategy = readerFactory->getStrategy(GtfsStrategyType::CALENDAR_DATE); + const auto routesStrategy = readerFactory->getStrategy(GtfsStrategyType::ROUTE); + const auto stopStrategy = readerFactory->getStrategy(GtfsStrategyType::STOP); + const auto stopTimeStrategy = readerFactory->getStrategy(GtfsStrategyType::STOP_TIME); + const auto transferStrategy = readerFactory->getStrategy(GtfsStrategyType::TRANSFER); + const auto tripStrategy = readerFactory->getStrategy(GtfsStrategyType::TRIP); + + strategy.push_back(agencyStrategy); + strategy.push_back(calendarStrategy); + strategy.push_back(calendarDatesStrategy); + strategy.push_back(routesStrategy); + strategy.push_back(stopStrategy); + strategy.push_back(stopTimeStrategy); + strategy.push_back(transferStrategy); + strategy.push_back(tripStrategy); + + const auto reader = std::make_unique(std::move(strategy)); + for (auto _ : state) + { + reader->readData(); + } } BENCHMARK(BM_read_gtfs_schedule); diff --git a/schedule/include/GtfsData.h b/schedule/include/GtfsData.h index 8ff94e31..b7166e41 100644 --- a/schedule/include/GtfsData.h +++ b/schedule/include/GtfsData.h @@ -26,8 +26,7 @@ namespace schedule::gtfs { std::unordered_map routes; std::unordered_map stops; std::unordered_map> stopTimes; - std::unordered_map> transferFrom; - std::unordered_map> transferTo; + std::unordered_map> transfer; std::unordered_map trips; }; diff --git a/schedule/src/gtfs/GtfsCsvParserReaderStrategyFactory.cpp b/schedule/src/gtfs/GtfsCsvParserReaderStrategyFactory.cpp index f4795a09..1a0eb1b2 100644 --- a/schedule/src/gtfs/GtfsCsvParserReaderStrategyFactory.cpp +++ b/schedule/src/gtfs/GtfsCsvParserReaderStrategyFactory.cpp @@ -23,7 +23,7 @@ namespace schedule::gtfs { } init(); } - std::function& GtfsCsvParserReaderStrategyFactory::getStrategy(GtfsStrategyType aType) { + std::function& GtfsCsvParserReaderStrategyFactory::getStrategy(const GtfsStrategyType aType) { return strategies[aType]; } void GtfsCsvParserReaderStrategyFactory::init() { diff --git a/schedule/src/gtfs/strategies/csv_reader/GtfsTransferReaderCsv.cpp b/schedule/src/gtfs/strategies/csv_reader/GtfsTransferReaderCsv.cpp index 3efdb6d1..8b529b08 100644 --- a/schedule/src/gtfs/strategies/csv_reader/GtfsTransferReaderCsv.cpp +++ b/schedule/src/gtfs/strategies/csv_reader/GtfsTransferReaderCsv.cpp @@ -77,7 +77,7 @@ namespace schedule::gtfs { { auto fromStopId = tempStop.fromStopId; - aReader.getData().get().transferFrom[fromStopId].emplace_back( + aReader.getData().get().transfer[fromStopId].emplace_back( std::move(tempStop.fromStopId), std::move(tempStop.toStopId), static_cast(std::stoi(tempStop.transferType)), diff --git a/schedule/src/gtfs/strategies/csv_reader_fast/GtfsRouteReaderCsvParser.cpp b/schedule/src/gtfs/strategies/csv_reader_fast/GtfsRouteReaderCsvParser.cpp index d3860b5d..a47dbeae 100644 --- a/schedule/src/gtfs/strategies/csv_reader_fast/GtfsRouteReaderCsvParser.cpp +++ b/schedule/src/gtfs/strategies/csv_reader_fast/GtfsRouteReaderCsvParser.cpp @@ -44,6 +44,7 @@ namespace schedule::gtfs { std::string routeLongName; std::string routeDesc; int routeType; + reader.read_header(io::ignore_no_column, "route_id", "agency_id", "route_short_name", "route_long_name", "route_desc", "route_type"); while (reader.read_row(routeId, agencyId, routeShortName, routeLongName, routeDesc, routeType)) { diff --git a/schedule/src/gtfs/strategies/csv_reader_fast/GtfsTransferReaderCsvParser.cpp b/schedule/src/gtfs/strategies/csv_reader_fast/GtfsTransferReaderCsvParser.cpp index e3e63b0e..99d8e40d 100644 --- a/schedule/src/gtfs/strategies/csv_reader_fast/GtfsTransferReaderCsvParser.cpp +++ b/schedule/src/gtfs/strategies/csv_reader_fast/GtfsTransferReaderCsvParser.cpp @@ -47,7 +47,7 @@ namespace schedule::gtfs { auto temp = fromStopId; - aReader.getData().get().transferFrom[temp].emplace_back( + aReader.getData().get().transfer[temp].emplace_back( std::move(fromStopId), std::move(toStopId), static_cast(transferType), diff --git a/schedule/src/gtfs/strategies/txt_reader/GtfsTransferReader.cpp b/schedule/src/gtfs/strategies/txt_reader/GtfsTransferReader.cpp index 7b3127e1..3592d7d3 100644 --- a/schedule/src/gtfs/strategies/txt_reader/GtfsTransferReader.cpp +++ b/schedule/src/gtfs/strategies/txt_reader/GtfsTransferReader.cpp @@ -40,17 +40,12 @@ namespace schedule::gtfs { continue; } - aReader.getData().get().transferFrom[std::string(fields[headerMap["from_stop_id"]])].emplace_back( + aReader.getData().get().transfer[std::string(fields[headerMap["from_stop_id"]])].emplace_back( std::string(fields[headerMap["from_stop_id"]]), std::string(fields[headerMap["to_stop_id"]]), static_cast(std::stoi(std::string(fields[headerMap["transfer_type"]]))), std::stoi(std::string(fields[headerMap["min_transfer_time"]]))); - aReader.getData().get().transferTo[(std::string(fields[headerMap["to_stop_id"]]))].emplace_back( - std::string(fields[headerMap["from_stop_id"]]), - std::string(fields[headerMap["to_stop_id"]]), - static_cast(std::stoi(std::string(fields[headerMap["transfer_type"]]))), - std::stoi(std::string(fields[headerMap["min_transfer_time"]]))); } } } // gtfs \ No newline at end of file diff --git a/schedule/test/CMakeLists.txt b/schedule/test/CMakeLists.txt index a8db740f..a50fdeac 100644 --- a/schedule/test/CMakeLists.txt +++ b/schedule/test/CMakeLists.txt @@ -6,12 +6,12 @@ if (NOT ${CMAKE_BUILD_TYPE} STREQUAL "Debug") message(STATUS "Tests should be built in Debug mode") endif () +include(CTest) enable_testing() add_executable(${PROJECT_NAME}) target_sources(${PROJECT_NAME} PRIVATE - test_gtfsReader.cpp test_gtfsReaderTxt.cpp test_main.cpp test_gtfsReaderCsv.cpp @@ -29,7 +29,8 @@ target_link_libraries(${PROJECT_NAME} PRIVATE ) set(BINARY ${PROJECT_NAME}_tests_test) -add_test(NAME ${BINARY} COMMAND ${BINARY}) +add_test(NAME GtfsCsvReaderStrategiesTest COMMAND ${PROJECT_NAME}_test) +add_test(NAME GTFS COMMAND ${PROJECT_NAME}_test) target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/schedule/include) target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_BINARY_DIR}) @@ -42,13 +43,6 @@ message(STATUS "CMAKE_SOURCE_DIR: ${CMAKE_SOURCE_DIR}/schedule/test/test-data/") add_definitions(-DTEST_DATA_DIR="${CMAKE_SOURCE_DIR}/schedule/test/test-data/") -#if(USE_ZURICH_GTFS) -# add_definitions(-DTEST_DATA_DIR="C:/Users/MichaelBrunner/Downloads/2024_google_transit/") -#else () -# # add_definitions(-DTEST_DATA_DIR="${CMAKE_SOURCE_DIR}/schedule/test/test-data/") -# add_definitions(-DTEST_DATA_DIR="C:/Users/MichaelBrunner/Downloads/gtfs_fp2024_2024-05-27/") -#endif() - diff --git a/schedule/test/test_gtfsReader.cpp b/schedule/test/test_gtfsReader.cpp deleted file mode 100644 index 4201518c..00000000 --- a/schedule/test/test_gtfsReader.cpp +++ /dev/null @@ -1,124 +0,0 @@ -// -// Created by MichaelBrunner on 02/06/2024. -// - -#include "GtfsReaderStrategyFactory.h" -#include "LoggerFactory.h" -#include "gtfs/GtfsTxtReaderStrategyFactory.h" -#include -#include <../include/GtfsReader.h> - -#include -#include -#include -#include -#include -#include - -#include - -namespace fmt { - template<> - struct formatter - { - template - constexpr auto parse(ParseContext& ctx) { - return ctx.begin(); - } - - template - auto format(const std::chrono::year& y, FormatContext& ctx) { - return fmt::format_to(ctx.out(), "{}", static_cast(y)); - } - }; - - template<> - struct formatter - { - template - constexpr auto parse(ParseContext& ctx) { - return ctx.begin(); - } - - template - auto format(const std::chrono::month& m, FormatContext& ctx) { - return fmt::format_to(ctx.out(), "{}", static_cast(m)); - } - }; - - template<> - struct formatter - { - template - constexpr auto parse(ParseContext& ctx) { - return ctx.begin(); - } - - template - auto format(const std::chrono::day& d, FormatContext& ctx) { - return fmt::format_to(ctx.out(), "{}", static_cast(d)); - } - }; -} - -void printCalendar(const std::vector& calendars) { - std::array weekday_names = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}; - std::ranges::for_each(calendars, [&](const auto& calendar) { - getLogger(Target::CONSOLE, LoggerName::GTFS)->info(fmt::format("Service ID: {}", calendar.serviceId)); - getLogger(Target::CONSOLE, LoggerName::GTFS)->info(fmt::format("Start Date: {}-{}-{}", calendar.startDate.year(), calendar.startDate.month(), calendar.startDate.day())); - getLogger(Target::CONSOLE, LoggerName::GTFS)->info(fmt::format("End Date: {}-{}-{}", calendar.endDate.year(), calendar.endDate.month(), calendar.endDate.day())); - getLogger(Target::CONSOLE, LoggerName::GTFS)->info(fmt::format("Weekday Service: ")); - - std::ranges::for_each(calendar.weekdayService, [&](const auto& dayService) { - auto [day, service] = dayService; - auto day_name = weekday_names[day.c_encoding()]; - getLogger(Target::CONSOLE, LoggerName::GTFS)->info(fmt::format("{}: {}", day_name, (service ? "Service" : "No service"))); - }); - }); -} - -void printAgency(const std::vector& agencies) { - std::ranges::for_each( - agencies, [](const auto& agency) { getLogger(Target::CONSOLE, LoggerName::GTFS)->info(fmt::format("Agency: {} {} {}", agency.agencyId, agency.name, agency.timezone)); }); -} - -void printCalendarDates(const std::vector& calendarDates) { - std::ranges::for_each(calendarDates, [](const auto& calendarDate) { - getLogger(Target::CONSOLE, LoggerName::GTFS)->info(fmt::format("Service ID: {} Date: {}-{}-{} Exception Type: {}", calendarDate.serviceId, calendarDate.date.year(), calendarDate.date.month(), calendarDate.date.day(), static_cast(calendarDate.exceptionType))); - }); -} - -// TEST(TestSuiteName, TestName) -TEST(GTFS, TestStrategyReader) { - using namespace std::literals::string_literals; - std::string basePath = TEST_DATA_DIR; - - const auto readerFactory = schedule::gtfs::createGtfsReaderStrategyFactory(schedule::gtfs::ReaderType::TXT, std::move(basePath)); - - getLogger(Target::CONSOLE, LoggerName::GTFS)->setLevel(LoggerBridge::ERROR); - - - // create strategy callable objects - const auto agencyStrategy = readerFactory->getStrategy(GtfsStrategyType::AGENCY); - const auto calendarStrategy = readerFactory->getStrategy(GtfsStrategyType::CALENDAR); - const auto calendarDatesStrategy = readerFactory->getStrategy(GtfsStrategyType::CALENDAR_DATE); - const auto routesStrategy = readerFactory->getStrategy(GtfsStrategyType::ROUTE); - const auto stopStrategy = readerFactory->getStrategy(GtfsStrategyType::STOP); - const auto stopTimeStrategy = readerFactory->getStrategy(GtfsStrategyType::STOP_TIME); - const auto transferStrategy = readerFactory->getStrategy(GtfsStrategyType::TRANSFER); - const auto tripStrategy = readerFactory->getStrategy(GtfsStrategyType::TRIP); - - std::vector strategies = {agencyStrategy, calendarStrategy, calendarDatesStrategy, routesStrategy, stopStrategy, stopTimeStrategy, transferStrategy, tripStrategy}; - - const std::unique_ptr>> reader = std::make_unique(std::move(strategies)); - reader->readData(); - const auto data = reader->getData(); - // - // EXPECT_FALSE(data.get().agencies.empty() || data.get().calendars.empty() - // || data.get().calendarDates.empty() || data.get().routes.empty() || data.get().stops.empty() - // || data.get().stopTimes.empty() || data.get().transfers.empty() || data.get().trips.empty()); -} - -TEST(GTFS, TestReaderStrategyFactory) { - EXPECT_THROW(schedule::gtfs::GtfsTxtReaderStrategyFactory(""), std::invalid_argument); -} diff --git a/schedule/test/test_gtfsReaderCsv.cpp b/schedule/test/test_gtfsReaderCsv.cpp index 8c98ac66..c21ed5b9 100644 --- a/schedule/test/test_gtfsReaderCsv.cpp +++ b/schedule/test/test_gtfsReaderCsv.cpp @@ -5,7 +5,6 @@ #include "LoggerFactory.h" #include "../include/GtfsReader.h" #include "gtfs/GtfsTxtReaderStrategyFactory.h" -#include "../include/TimetableManager.h" #include "model/CalendarDate.h" #include "utils/DataContainer.h" @@ -148,11 +147,8 @@ TEST_F(GtfsCsvReaderStrategiesTest, testTransferReaderCsv) { reader = std::make_unique(std::move(strategy)); reader->readData(); const schedule::gtfs::GtfsData& data = reader->getData().get(); - const auto transferFrom = data.transferFrom.at("1100079"); + const auto transferFrom = data.transfer.at("1100079"); ASSERT_EQ(transferFrom[0].toStopId, "8014441"); - - const auto transferTo = data.transferTo.at("8014441"); - ASSERT_EQ(transferFrom[0].fromStopId, "1100079"); } TEST_F(GtfsCsvReaderStrategiesTest, testTripReaderCsv) { @@ -163,11 +159,11 @@ TEST_F(GtfsCsvReaderStrategiesTest, testTripReaderCsv) { reader->readData(); const schedule::gtfs::GtfsData& data = reader->getData().get(); - const auto trips = data.trips.at("110.TA.91-10-A-j24-1.7.H"); - ASSERT_TRUE(trips.empty() == false); - ASSERT_EQ(trips[0].routeId, "91-10-A-j24-1"); - ASSERT_EQ(trips[0].serviceId, "TA+hvzd0"); - ASSERT_EQ(trips[0].tripId, "110.TA.91-10-A-j24-1.7.H"); + ASSERT_TRUE(data.trips.empty() == false); + const auto trip = data.trips.at("110.TA.91-10-A-j24-1.7.H"); + ASSERT_EQ(trip.routeId, "91-10-A-j24-1"); + ASSERT_EQ(trip.serviceId, "TA+hvzd0"); + ASSERT_EQ(trip.tripId, "110.TA.91-10-A-j24-1.7.H"); } TEST_F(GtfsCsvReaderStrategiesTest, testrouteReaderCsv) { @@ -182,28 +178,4 @@ TEST_F(GtfsCsvReaderStrategiesTest, testrouteReaderCsv) { ASSERT_TRUE(route.routeId.empty() == false); ASSERT_EQ(route.routeId, "91-10-A-j24-1"); ASSERT_EQ(static_cast(route.routeType), 109); -} - -TEST_F(GtfsCsvReaderStrategiesTest, testRelationManagerCsv) { - - auto strategy = std::vector>(); - const std::function stopTimesStrategy = readerFactory->getStrategy(GtfsStrategyType::STOP_TIME); - const std::function tripsStrategy = readerFactory->getStrategy(GtfsStrategyType::TRIP); - - strategy.push_back(stopTimesStrategy); - strategy.push_back(tripsStrategy); - - reader = std::make_unique(std::move(strategy)); - reader->readData(); - - ASSERT_THROW(schedule::gtfs::TimetableManager(std::move(reader->getData().get())), std::out_of_range); - // try - // { - // const auto relationManager = schedule::gtfs::RelationManager(std::move(reader->getData().get())); - // auto stopIds = relationManager.getStopIdsFromStopName("Bärental, Löffelschmiede"); - // ASSERT_TRUE(stopIds.empty() == false); - // } catch (std::out_of_range& e) - // { - // getLogger(Target::CONSOLE, LoggerName::GTFS)->error(std::format("Invalid relations {}", e.what())); - // } -} +} \ No newline at end of file diff --git a/schedule/test/test_gtfsReaderTxt.cpp b/schedule/test/test_gtfsReaderTxt.cpp index 8a71fb10..ae915e8a 100644 --- a/schedule/test/test_gtfsReaderTxt.cpp +++ b/schedule/test/test_gtfsReaderTxt.cpp @@ -2,9 +2,8 @@ #include "DataReader.h" #include "GtfsReaderStrategyFactory.h" -#include "../include/GtfsReader.h" +#include "include/GtfsReader.h" #include "gtfs/GtfsTxtReaderStrategyFactory.h" -#include "../include/TimetableManager.h" #include "model/CalendarDate.h" #include "utils/DataContainer.h" @@ -17,6 +16,11 @@ #include #include +#include "LoggerFactory.h" +#include +#include +#include + /////////////// TESTS /////////////// ///////////////////////////////////// @@ -147,11 +151,8 @@ TEST_F(GtfsCsvReaderStrategiesTest, testTransferReaderTxt) { reader = std::make_unique(std::move(strategy)); reader->readData(); const schedule::gtfs::GtfsData& data = reader->getData().get(); - const auto transferFrom = data.transferFrom.at("1100079"); + const auto transferFrom = data.transfer.at("1100079"); ASSERT_EQ(transferFrom[0].toStopId, "8014441"); - - const auto transferTo = data.transferTo.at("8014441"); - ASSERT_EQ(transferFrom[0].fromStopId, "1100079"); } TEST_F(GtfsCsvReaderStrategiesTest, testTripReaderTxt) { @@ -162,11 +163,13 @@ TEST_F(GtfsCsvReaderStrategiesTest, testTripReaderTxt) { reader->readData(); const schedule::gtfs::GtfsData& data = reader->getData().get(); - const auto trips = data.trips.at("91-10-A-j24-1"); - ASSERT_TRUE(trips.empty() == false); - ASSERT_EQ(trips[0].routeId, "91-10-A-j24-1"); - ASSERT_EQ(trips[0].serviceId, "TA+p60e0"); - ASSERT_EQ(trips[0].tripId, "1.TA.91-10-A-j24-1.1.H"); + + ASSERT_TRUE(data.trips.empty() == false); + + const auto trip = data.trips.at("106.TA.91-10-A-j24-1.7.H"); + + ASSERT_EQ(trip.routeId, "91-10-A-j24-1"); + ASSERT_EQ(trip.serviceId, "TA+p60e0"); } TEST_F(GtfsCsvReaderStrategiesTest, testrouteReaderTxt) { @@ -182,19 +185,104 @@ TEST_F(GtfsCsvReaderStrategiesTest, testrouteReaderTxt) { ASSERT_EQ(static_cast(route.routeType), 900); } -TEST_F(GtfsCsvReaderStrategiesTest, testRelationManagerTxt) { +namespace fmt { + template<> + struct formatter + { + template + constexpr auto parse(ParseContext& ctx) { + return ctx.begin(); + } + + template + auto format(const std::chrono::year& y, FormatContext& ctx) { + return fmt::format_to(ctx.out(), "{}", static_cast(y)); + } + }; + + template<> + struct formatter + { + template + constexpr auto parse(ParseContext& ctx) { + return ctx.begin(); + } + + template + auto format(const std::chrono::month& m, FormatContext& ctx) { + return fmt::format_to(ctx.out(), "{}", static_cast(m)); + } + }; + + template<> + struct formatter + { + template + constexpr auto parse(ParseContext& ctx) { + return ctx.begin(); + } + + template + auto format(const std::chrono::day& d, FormatContext& ctx) { + return fmt::format_to(ctx.out(), "{}", static_cast(d)); + } + }; +} - auto strategy = std::vector>(); - const std::function stopTimesStrategy = readerFactory->getStrategy(GtfsStrategyType::STOP_TIME);; - const std::function tripsStrategy = readerFactory->getStrategy(GtfsStrategyType::TRIP);; +void printCalendar(const std::vector& calendars) { + std::array weekday_names = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}; + std::ranges::for_each(calendars, [&](const auto& calendar) { + getLogger(Target::CONSOLE, LoggerName::GTFS)->info(fmt::format("Service ID: {}", calendar.serviceId)); + getLogger(Target::CONSOLE, LoggerName::GTFS)->info(fmt::format("Start Date: {}-{}-{}", calendar.startDate.year(), calendar.startDate.month(), calendar.startDate.day())); + getLogger(Target::CONSOLE, LoggerName::GTFS)->info(fmt::format("End Date: {}-{}-{}", calendar.endDate.year(), calendar.endDate.month(), calendar.endDate.day())); + getLogger(Target::CONSOLE, LoggerName::GTFS)->info(fmt::format("Weekday Service: ")); + + std::ranges::for_each(calendar.weekdayService, [&](const auto& dayService) { + auto [day, service] = dayService; + auto day_name = weekday_names[day.c_encoding()]; + getLogger(Target::CONSOLE, LoggerName::GTFS)->info(fmt::format("{}: {}", day_name, (service ? "Service" : "No service"))); + }); + }); +} - strategy.push_back(stopTimesStrategy); - strategy.push_back(tripsStrategy); +void printAgency(const std::vector& agencies) { + std::ranges::for_each( + agencies, [](const auto& agency) { getLogger(Target::CONSOLE, LoggerName::GTFS)->info(fmt::format("Agency: {} {} {}", agency.agencyId, agency.name, agency.timezone)); }); +} - reader = std::make_unique(std::move(strategy)); - reader->readData(); +void printCalendarDates(const std::vector& calendarDates) { + std::ranges::for_each(calendarDates, [](const auto& calendarDate) { + getLogger(Target::CONSOLE, LoggerName::GTFS)->info(fmt::format("Service ID: {} Date: {}-{}-{} Exception Type: {}", calendarDate.serviceId, calendarDate.date.year(), calendarDate.date.month(), calendarDate.date.day(), static_cast(calendarDate.exceptionType))); + }); +} + +TEST(GTFS, TestStrategyReader) { + using namespace std::literals::string_literals; + std::string basePath = TEST_DATA_DIR; + + const auto readerFactory = schedule::gtfs::createGtfsReaderStrategyFactory(schedule::gtfs::ReaderType::TXT, std::move(basePath)); + + getLogger(Target::CONSOLE, LoggerName::GTFS)->setLevel(LoggerBridge::ERROR); - const auto relationManager = schedule::gtfs::TimetableManager(std::move(reader->getData().get())); - auto stopIds = relationManager.getStopIdsFromStopName("Bärental, Löffelschmiede"); - ASSERT_TRUE(stopIds.empty() == false); + + // create strategy callable objects + const auto agencyStrategy = readerFactory->getStrategy(GtfsStrategyType::AGENCY); + const auto calendarStrategy = readerFactory->getStrategy(GtfsStrategyType::CALENDAR); + const auto calendarDatesStrategy = readerFactory->getStrategy(GtfsStrategyType::CALENDAR_DATE); + const auto routesStrategy = readerFactory->getStrategy(GtfsStrategyType::ROUTE); + const auto stopStrategy = readerFactory->getStrategy(GtfsStrategyType::STOP); + const auto stopTimeStrategy = readerFactory->getStrategy(GtfsStrategyType::STOP_TIME); + const auto transferStrategy = readerFactory->getStrategy(GtfsStrategyType::TRANSFER); + const auto tripStrategy = readerFactory->getStrategy(GtfsStrategyType::TRIP); + + std::vector strategies = {agencyStrategy, calendarStrategy, calendarDatesStrategy, routesStrategy, stopStrategy, stopTimeStrategy, transferStrategy, tripStrategy}; + + const std::unique_ptr>> reader = std::make_unique(std::move(strategies)); + reader->readData(); + const auto data = reader->getData().get(); + // + EXPECT_FALSE(data.agencies.empty() || data.calendars.empty() + || data.calendarDates.empty() || data.routes.empty() || data.stops.empty() + || data.stopTimes.empty() || data.transfer.empty() || data.trips.empty()); } + diff --git a/schedule/test/test_main.cpp b/schedule/test/test_main.cpp index 33aed531..5387b067 100644 --- a/schedule/test/test_main.cpp +++ b/schedule/test/test_main.cpp @@ -6,7 +6,7 @@ int main(int argc, char** argv) { // testing::GTEST_FLAG(filter) = "GtfsTripReaderTest.*"; - testing::GTEST_FLAG(break_on_failure) = true; + // testing::GTEST_FLAG(break_on_failure) = true; testing::GTEST_FLAG(color) = "yes"; // testing::GTEST_FLAG(throw_on_failure) = true; testing::InitGoogleTest(&argc, argv);