Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
mesozoic-drones committed Nov 9, 2023
1 parent d5767a4 commit 7763562
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
14 changes: 7 additions & 7 deletions include/just_gtfs/just_gtfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down
37 changes: 25 additions & 12 deletions tests/unit_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#include <iterator>

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")
{
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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();

0 comments on commit 7763562

Please sign in to comment.