From 7763562d81e6dc8260f471ce1b28eb2136b6a1c4 Mon Sep 17 00:00:00 2001 From: Khlopkova Olga Date: Thu, 9 Nov 2023 19:49:33 +0300 Subject: [PATCH] upd --- include/just_gtfs/just_gtfs.h | 14 ++++++------- tests/unit_tests.cpp | 37 +++++++++++++++++++++++------------ 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/include/just_gtfs/just_gtfs.h b/include/just_gtfs/just_gtfs.h index 5cd3947..a24f104 100644 --- a/include/just_gtfs/just_gtfs.h +++ b/include/just_gtfs/just_gtfs.h @@ -1261,7 +1261,7 @@ class Feed inline Feed() = default; inline explicit Feed(const std::string & gtfs_path); - inline Result read_feed(); + inline Result read_feed(bool strict=true); inline Result write_feed(const std::string & gtfs_path) const; inline Result write_agencies(const std::string & gtfs_path) const; @@ -1458,22 +1458,22 @@ inline bool ErrorParsingOptionalFile(const Result & res) return res != ResultCode::OK && res != ResultCode::ERROR_FILE_ABSENT; } -inline Result Feed::read_feed() +inline Result Feed::read_feed(bool strict) { // Read required files: - if (auto res = read_agencies(); res != ResultCode::OK) + if (auto res = read_agencies(); strict && res != ResultCode::OK) return res; - if (auto res = read_stops(); res != ResultCode::OK) + if (auto res = read_stops(); strict && res != ResultCode::OK) return res; - if (auto res = read_routes(); res != ResultCode::OK) + if (auto res = read_routes(); strict && res != ResultCode::OK) return res; - if (auto res = read_trips(); res != ResultCode::OK) + if (auto res = read_trips(); strict && res != ResultCode::OK) return res; - if (auto res = read_stop_times(); res != ResultCode::OK) + if (auto res = read_stop_times(); strict && res != ResultCode::OK) return res; // Read conditionally required files: diff --git a/tests/unit_tests.cpp b/tests/unit_tests.cpp index 8a690ca..09570a7 100644 --- a/tests/unit_tests.cpp +++ b/tests/unit_tests.cpp @@ -6,7 +6,9 @@ #include using namespace gtfs; -const std::string test_feed = "/Users/o.khlopkova/Documents/just_gtfs/tests/data/sample_feed"; +const std::string test_feed = "data/sample_feed"; +const std::string test_output_feed = "data/output_feed"; + TEST_SUITE_BEGIN("Handling time GTFS fields"); TEST_CASE("Time in H:MM:SS format") { @@ -335,7 +337,10 @@ TEST_CASE("Agency") const auto agency = feed.get_agency("DTA"); CHECK_EQ(agency.agency_name, "Demo Transit Authority"); - // TODO: check feed dumping to file + REQUIRE_EQ(feed.write_agencies(test_output_feed), ResultCode::OK); + Feed feed_copy(test_output_feed); + REQUIRE_EQ(feed_copy.read_feed(false), ResultCode::OK); + CHECK_EQ(agencies, feed_copy.get_agencies()); } TEST_CASE("Routes") @@ -458,9 +463,8 @@ TEST_CASE("Calendar") CHECK_EQ(calendar[0].monday, CalendarAvailability::Available); CHECK_EQ(calendar[0].sunday, CalendarAvailability::Available); - //const auto & calendar_for_service = feed.get_calendar("FULLW"); - //const auto & calendar_for_service = feed.get_calendar_dates("FULLW"); - //CHECK(calendar_for_service); + const auto & calendar_for_service = feed.get_calendar_dates("FULLW"); + CHECK_EQ(std::distance(calendar_for_service.first, calendar_for_service.second), 1); } TEST_CASE("Calendar dates") @@ -474,8 +478,8 @@ TEST_CASE("Calendar dates") CHECK_EQ(calendar_dates[0].date, Date(2007, 06, 04)); CHECK_EQ(calendar_dates[0].exception_type, CalendarDateException::Removed); - //const auto & calendar_dates_for_service = feed.get_calendar_dates("FULLW"); - //CHECK_EQ(calendar_dates_for_service.size(), 1); + const auto & d = feed.get_calendar_dates("FULLW"); + CHECK_EQ(std::distance(d.first, d.second), 1); } TEST_CASE("Frequencies") @@ -528,7 +532,10 @@ TEST_CASE("Fare attributes") REQUIRE_EQ(std::distance(attributes_for_id.first, attributes_for_id.second), 1); CHECK_EQ(attributes_for_id.first->price, 5.25); - // TODO: test dumping feed to directory + REQUIRE_EQ(feed.write_fare_attributes(test_output_feed), ResultCode::OK); + Feed feed_copy(test_output_feed); + REQUIRE_EQ(feed_copy.read_feed(false), ResultCode::OK); + CHECK_EQ(attributes, feed_copy.get_fare_attributes()); } TEST_CASE("Fare rules") @@ -656,8 +663,11 @@ TEST_CASE("Agencies create & save") feed_for_writing.add_agency(agency1); feed_for_writing.add_agency(agency2); - REQUIRE_EQ(feed_for_writing.write_agencies("data/output_feed"), ResultCode::OK); - // TODO: test feed dumping to directory + REQUIRE_EQ(feed_for_writing.write_agencies(test_output_feed), ResultCode::OK); + Feed feed_for_testing(test_output_feed); + + REQUIRE_EQ(feed_for_testing.read_feed(false), ResultCode::OK); + CHECK_EQ(feed_for_writing.get_agencies(), feed_for_testing.get_agencies()); } TEST_CASE("Shapes create & save") @@ -668,7 +678,10 @@ TEST_CASE("Shapes create & save") feed_for_writing.add_shape(ShapePoint{"id1", 61.199419, -149.867680, 1, 178}); feed_for_writing.add_shape(ShapePoint{"id2", 61.199972, -149.867731, 2, 416}); - REQUIRE_EQ(feed_for_writing.write_shapes("data/output_feed"), ResultCode::OK); - // TODO: test feed dumping to directory + REQUIRE_EQ(feed_for_writing.write_shapes(test_output_feed), ResultCode::OK); + Feed feed_for_testing(test_output_feed); + + REQUIRE_EQ(feed_for_testing.read_feed(false), ResultCode::OK); + CHECK_EQ(feed_for_testing.get_shapes().size(), 3); } TEST_SUITE_END();