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 3241bc2 commit d5767a4
Showing 1 changed file with 54 additions and 62 deletions.
116 changes: 54 additions & 62 deletions tests/unit_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <iterator>

using namespace gtfs;
const std::string test_feed = "data/sample_feed";
const std::string test_feed = "/Users/o.khlopkova/Documents/just_gtfs/tests/data/sample_feed";
TEST_SUITE_BEGIN("Handling time GTFS fields");
TEST_CASE("Time in H:MM:SS format")
{
Expand Down Expand Up @@ -335,10 +335,7 @@ TEST_CASE("Agency")
const auto agency = feed.get_agency("DTA");
CHECK_EQ(agency.agency_name, "Demo Transit Authority");

REQUIRE_EQ(feed.write_agencies("data/output_feed"), ResultCode::OK);
Feed feed_copy("data/output_feed");
REQUIRE_EQ(feed_copy.read_feed(), ResultCode::OK);
CHECK_EQ(agencies, feed_copy.get_agencies());
// TODO: check feed dumping to file
}

TEST_CASE("Routes")
Expand All @@ -348,14 +345,15 @@ TEST_CASE("Routes")

const auto & routes = feed.get_routes();
REQUIRE_EQ(routes.size(), 5);
CHECK_EQ(routes[0].route_id, "AB");
CHECK_EQ(routes[0].agency_id, "DTA");
CHECK_EQ(routes[0].route_short_name, "10");
CHECK_EQ(routes[0].route_long_name, "Airport - Bullfrog");
CHECK_EQ(routes[0].route_type, RouteType::Bus);
CHECK(routes[0].route_text_color.empty());
CHECK(routes[0].route_color.empty());
CHECK(routes[0].route_desc.empty());
const size_t i = 1;
CHECK_EQ(routes[i].route_id, "AB");
CHECK_EQ(routes[i].agency_id, "DTA");
CHECK_EQ(routes[i].route_short_name, "10");
CHECK_EQ(routes[i].route_long_name, "Airport - Bullfrog");
CHECK_EQ(routes[i].route_type, RouteType::Bus);
CHECK(routes[i].route_text_color.empty());
CHECK(routes[i].route_color.empty());
CHECK(routes[i].route_desc.empty());

const auto & route = feed.get_route("AB");
CHECK_EQ(route.agency_id, "DTA");
Expand All @@ -370,13 +368,14 @@ TEST_CASE("Trips")
const auto & trips = feed.get_trips();
REQUIRE_EQ(trips.size(), 11);

CHECK_EQ(trips[0].block_id, "1");
CHECK_EQ(trips[0].route_id, "AB");
CHECK_EQ(trips[0].direction_id, TripDirectionId::DefaultDirection);
CHECK_EQ(trips[0].trip_headsign, "to Bullfrog");
CHECK(trips[0].shape_id.empty());
CHECK_EQ(trips[0].service_id, "FULLW");
CHECK_EQ(trips[0].trip_id, "AB1");
const size_t i = 4;
CHECK_EQ(trips[i].block_id, "1");
CHECK_EQ(trips[i].route_id, "AB");
CHECK_EQ(trips[i].direction_id, TripDirectionId::DefaultDirection);
CHECK_EQ(trips[i].trip_headsign, "to Bullfrog");
CHECK(trips[i].shape_id.empty());
CHECK_EQ(trips[i].service_id, "FULLW");
CHECK_EQ(trips[i].trip_id, "AB1");

const auto & trip = feed.get_trip("AB1");
CHECK(trip.trip_short_name.empty());
Expand Down Expand Up @@ -412,14 +411,15 @@ TEST_CASE("StopTimes")
const auto & stop_times = feed.get_stop_times();
REQUIRE_EQ(stop_times.size(), 28);

CHECK_EQ(stop_times[0].trip_id, "STBA");
CHECK_EQ(stop_times[0].arrival_time, Time(06, 00, 00));
CHECK_EQ(stop_times[0].departure_time, Time(06, 00, 00));
CHECK_EQ(stop_times[0].stop_id, "STAGECOACH");
CHECK_EQ(stop_times[0].stop_sequence, 1);
CHECK(stop_times[0].stop_headsign.empty());
CHECK_EQ(stop_times[0].pickup_type, StopTimeBoarding::RegularlyScheduled);
CHECK_EQ(stop_times[0].drop_off_type, StopTimeBoarding::RegularlyScheduled);
const size_t i = 26;
CHECK_EQ(stop_times[i].trip_id, "STBA");
CHECK_EQ(stop_times[i].arrival_time, Time(06, 00, 00));
CHECK_EQ(stop_times[i].departure_time, Time(06, 00, 00));
CHECK_EQ(stop_times[i].stop_id, "STAGECOACH");
CHECK_EQ(stop_times[i].stop_sequence, 1);
CHECK(stop_times[i].stop_headsign.empty());
CHECK_EQ(stop_times[i].pickup_type, StopTimeBoarding::RegularlyScheduled);
CHECK_EQ(stop_times[i].drop_off_type, StopTimeBoarding::RegularlyScheduled);

CHECK_EQ(feed.get_stop_times_for_stop("STAGECOACH").size(), 3);

Expand Down Expand Up @@ -485,13 +485,14 @@ TEST_CASE("Frequencies")

const auto & frequencies = feed.get_frequencies();
REQUIRE_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);
const size_t i = 10;
CHECK_EQ(frequencies[i].trip_id, "STBA");
CHECK_EQ(frequencies[i].start_time, Time(6, 00, 00));
CHECK_EQ(frequencies[i].end_time, Time(22, 00, 00));
CHECK_EQ(frequencies[i].headway_secs, 1800);

//const auto & frequencies_for_trip = feed.get_frequencies("CITY1");
//CHECK_EQ(frequencies_for_trip.size(), 5);
const auto & f = feed.get_frequencies("CITY1");
CHECK_EQ(std::distance(f.first, f.second), 5);
}

TEST_CASE("Fare attributes")
Expand All @@ -501,18 +502,19 @@ TEST_CASE("Fare attributes")

const auto & attributes = feed.get_fare_attributes();
REQUIRE_EQ(attributes.size(), 3);
CHECK_EQ(attributes[0].fare_id, "p");
CHECK_EQ(attributes[0].price, 1.25);

CHECK_EQ(attributes[0].fare_id, "a");
CHECK_EQ(attributes[0].price, 5.25);
CHECK_EQ(attributes[0].currency_type, "USD");
CHECK_EQ(attributes[0].payment_method, FarePayment::OnBoard);
CHECK_EQ(attributes[0].transfers, FareTransfers::No);
CHECK_EQ(attributes[0].payment_method, FarePayment::BeforeBoarding);
CHECK_EQ(attributes[0].transfers, FareTransfers::Once);
CHECK_EQ(attributes[0].transfer_duration, 0);

CHECK_EQ(attributes[1].fare_id, "a");
CHECK_EQ(attributes[1].price, 5.25);
CHECK_EQ(attributes[1].fare_id, "p");
CHECK_EQ(attributes[1].price, 1.25);
CHECK_EQ(attributes[1].currency_type, "USD");
CHECK_EQ(attributes[1].payment_method, FarePayment::BeforeBoarding);
CHECK_EQ(attributes[1].transfers, FareTransfers::Once);
CHECK_EQ(attributes[1].payment_method, FarePayment::OnBoard);
CHECK_EQ(attributes[1].transfers, FareTransfers::No);
CHECK_EQ(attributes[1].transfer_duration, 0);

CHECK_EQ(attributes[2].fare_id, "x");
Expand All @@ -522,14 +524,11 @@ TEST_CASE("Fare attributes")
CHECK_EQ(attributes[2].transfers, FareTransfers::Unlimited);
CHECK_EQ(attributes[2].transfer_duration, 60);

// const auto & attributes_for_id = feed.get_fare_attributes("a");
// REQUIRE_EQ(attributes_for_id.size(), 1);
// CHECK_EQ(attributes_for_id[0].price, 5.25);
const auto & attributes_for_id = feed.get_fare_attributes("a");
REQUIRE_EQ(std::distance(attributes_for_id.first, attributes_for_id.second), 1);
CHECK_EQ(attributes_for_id.first->price, 5.25);

REQUIRE_EQ(feed.write_fare_attributes("data/output_feed"), ResultCode::OK);
Feed feed_copy("data/output_feed");
REQUIRE_EQ(feed_copy.read_feed(), ResultCode::OK);
CHECK_EQ(attributes, feed_copy.get_fare_attributes());
// TODO: test dumping feed to directory
}

TEST_CASE("Fare rules")
Expand All @@ -539,12 +538,11 @@ TEST_CASE("Fare rules")

const auto & fare_rules = feed.get_fare_rules();
REQUIRE_EQ(fare_rules.size(), 4);
CHECK_EQ(fare_rules[0].fare_id, "p");
CHECK_EQ(fare_rules[0].route_id, "AB");
CHECK_EQ(fare_rules[1].fare_id, "p");
CHECK_EQ(fare_rules[1].route_id, "AB");

const auto & rules_for_id = feed.get_fare_rules("p");
CHECK_EQ(std::distance(rules_for_id.first, rules_for_id.second), 3);
//CHECK_EQ(rules_for_id[1].route_id, "STBA");
}

TEST_CASE("Levels")
Expand All @@ -554,8 +552,8 @@ TEST_CASE("Levels")

const auto & levels = feed.get_levels();
REQUIRE_EQ(levels.size(), 3);
CHECK_EQ(levels[0].level_id, "U321L1");
CHECK_EQ(levels[0].level_index, -1.5);
CHECK_EQ(levels[1].level_id, "U321L1");
CHECK_EQ(levels[1].level_index, -1.5);

const auto & level = feed.get_level("U321L2");

Expand Down Expand Up @@ -659,10 +657,7 @@ TEST_CASE("Agencies create & save")
feed_for_writing.add_agency(agency2);

REQUIRE_EQ(feed_for_writing.write_agencies("data/output_feed"), ResultCode::OK);
Feed feed_for_testing("data/output_feed");

REQUIRE_EQ(feed_for_testing.read_feed(), ResultCode::OK);
CHECK_EQ(feed_for_writing.get_agencies(), feed_for_testing.get_agencies());
// TODO: test feed dumping to directory
}

TEST_CASE("Shapes create & save")
Expand All @@ -674,9 +669,6 @@ TEST_CASE("Shapes create & save")
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);
Feed feed_for_testing("data/output_feed");

REQUIRE_EQ(feed_for_testing.read_feed(), ResultCode::OK);
CHECK_EQ(feed_for_testing.get_shapes().size(), 3);
// TODO: test feed dumping to directory
}
TEST_SUITE_END();

0 comments on commit d5767a4

Please sign in to comment.