fix for frequencies
This commit is contained in:
parent
083d98e431
commit
521d2b76ad
2 changed files with 61 additions and 12 deletions
|
@ -977,7 +977,7 @@ public:
|
|||
|
||||
inline Result read_frequencies();
|
||||
inline const Frequencies & get_frequencies() const;
|
||||
inline std::optional<Frequency> get_frequency(const Id & trip_id) const;
|
||||
inline Frequencies get_frequencies(const Id & trip_id) const;
|
||||
inline void add_frequency(const Frequency & frequency);
|
||||
|
||||
inline Result read_transfers();
|
||||
|
@ -1697,7 +1697,7 @@ inline const CalendarDates & Feed::get_calendar_dates() const { return calendar_
|
|||
|
||||
inline CalendarDates Feed::get_calendar_dates(const Id & service_id, bool sort_by_date) const
|
||||
{
|
||||
std::vector<CalendarDate> res;
|
||||
CalendarDates res;
|
||||
for (const auto & calendar_date : calendar_dates)
|
||||
{
|
||||
if (calendar_date.service_id == service_id)
|
||||
|
@ -1776,16 +1776,15 @@ inline Result Feed::read_frequencies()
|
|||
|
||||
inline const Frequencies & Feed::get_frequencies() const { return frequencies; }
|
||||
|
||||
inline std::optional<Frequency> Feed::get_frequency(const Id & trip_id) const
|
||||
inline Frequencies Feed::get_frequencies(const Id & trip_id) const
|
||||
{
|
||||
const auto it = std::find_if(
|
||||
frequencies.begin(), frequencies.end(),
|
||||
[&trip_id](const Frequency & frequency) { return frequency.trip_id == trip_id; });
|
||||
|
||||
if (it == frequencies.end())
|
||||
return std::nullopt;
|
||||
|
||||
return *it;
|
||||
Frequencies res;
|
||||
for (const auto & frequency : frequencies)
|
||||
{
|
||||
if (frequency.trip_id == trip_id)
|
||||
res.push_back(frequency);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
inline void Feed::add_frequency(const Frequency & frequency) { frequencies.push_back(frequency); }
|
||||
|
|
|
@ -223,7 +223,7 @@ TEST_CASE("Read GTFS feed")
|
|||
CHECK_EQ(feed.get_stop_times().size(), 28);
|
||||
}
|
||||
|
||||
TEST_CASE("Agencies")
|
||||
TEST_CASE("Agency")
|
||||
{
|
||||
Feed feed("data/sample_feed");
|
||||
auto res = feed.read_agencies();
|
||||
|
@ -342,4 +342,54 @@ TEST_CASE("Shapes")
|
|||
auto const shape = feed.get_shape("10237");
|
||||
CHECK_EQ(shape.size(), 4);
|
||||
}
|
||||
|
||||
TEST_CASE("Calendar")
|
||||
{
|
||||
Feed feed("data/sample_feed");
|
||||
auto res = feed.read_calendar();
|
||||
CHECK_EQ(res.code, ResultCode::OK);
|
||||
|
||||
const auto & calendar = feed.get_calendar();
|
||||
CHECK_EQ(calendar.size(), 2);
|
||||
CHECK_EQ(calendar[0].service_id, "FULLW");
|
||||
CHECK_EQ(calendar[0].start_date, Date(2007, 01, 01));
|
||||
CHECK_EQ(calendar[0].end_date, Date(2010, 12, 31));
|
||||
CHECK_EQ(calendar[0].monday, CalendarAvailability::Available);
|
||||
CHECK_EQ(calendar[0].sunday, CalendarAvailability::Available);
|
||||
|
||||
auto calendar_for_service = feed.get_calendar("FULLW");
|
||||
CHECK(calendar_for_service);
|
||||
}
|
||||
|
||||
TEST_CASE("Calendar dates")
|
||||
{
|
||||
Feed feed("data/sample_feed");
|
||||
auto res = feed.read_calendar_dates();
|
||||
CHECK_EQ(res.code, ResultCode::OK);
|
||||
|
||||
const auto & calendar_dates = feed.get_calendar_dates();
|
||||
CHECK_EQ(calendar_dates.size(), 1);
|
||||
CHECK_EQ(calendar_dates[0].service_id, "FULLW");
|
||||
CHECK_EQ(calendar_dates[0].date, Date(2007, 06, 04));
|
||||
CHECK_EQ(calendar_dates[0].exception_type, CalendarDateException::Removed);
|
||||
|
||||
auto calendar_dates_for_service = feed.get_calendar_dates("FULLW");
|
||||
CHECK_EQ(calendar_dates_for_service.size(), 1);
|
||||
}
|
||||
|
||||
TEST_CASE("Frequencies")
|
||||
{
|
||||
Feed feed("data/sample_feed");
|
||||
auto res = feed.read_frequencies();
|
||||
CHECK_EQ(res.code, ResultCode::OK);
|
||||
|
||||
const auto & frequencies = feed.get_frequencies();
|
||||
CHECK_EQ(frequencies.size(), 11);
|
||||
CHECK_EQ(frequencies[0].trip_id, "STBA");
|
||||
CHECK_EQ(frequencies[0].start_time, Time(6, 00, 00));
|
||||
CHECK_EQ(frequencies[0].end_time, Time(22, 00, 00));
|
||||
CHECK_EQ(frequencies[0].headway_secs, 1800);
|
||||
auto const frequencies_for_trip = feed.get_frequencies("CITY1");
|
||||
CHECK_EQ(frequencies_for_trip.size(), 5);
|
||||
}
|
||||
TEST_SUITE_END();
|
||||
|
|
Loading…
Add table
Reference in a new issue