abstreet/sim/tests/transit.rs

69 lines
2.2 KiB
Rust
Raw Normal View History

extern crate abstutil;
extern crate control;
extern crate map_model;
extern crate sim;
#[test]
fn bus_reaches_stops() {
2018-10-03 00:36:04 +03:00
let (map, control_map, mut sim) = sim::load(
sim::SimFlags::for_test("bus_reaches_stops"),
Some(sim::Tick::from_seconds(30)),
);
2018-09-07 23:22:37 +03:00
let route = map.get_bus_route("48").unwrap();
let bus = sim.seed_bus_route(route, &map)[0];
let mut expectations: Vec<sim::Event> = Vec::new();
// TODO assert stuff about other buses as well, although the timing is a little unclear
for stop in route.stops.iter().skip(1) {
expectations.push(sim::Event::BusArrivedAtStop(bus, *stop));
expectations.push(sim::Event::BusDepartedFromStop(bus, *stop));
}
sim.run_until_expectations_met(
&map,
&control_map,
2018-09-07 23:22:37 +03:00
expectations,
sim::Tick::from_minutes(10),
);
2018-09-04 21:55:45 +03:00
sim.run_until_done(&map, &control_map, Box::new(|_sim| {}));
}
// TODO this test is strictly more complicated than bus_reaches_stops, should it subsume it?
#[test]
fn ped_uses_bus() {
2018-10-03 00:36:04 +03:00
let (map, control_map, mut sim) = sim::load(
sim::SimFlags::for_test("bus_reaches_stops"),
2018-09-04 21:55:45 +03:00
Some(sim::Tick::from_seconds(30)),
);
2018-09-07 23:22:37 +03:00
let route = map.get_bus_route("48").unwrap();
let bus = sim.seed_bus_route(route, &map)[0];
let ped_stop1 = route.stops[1];
let ped_stop2 = route.stops[2];
// TODO Need to fix this test after stabilizing a map
2018-09-04 21:55:45 +03:00
let ped = sim.make_ped_using_bus(
&map,
map_model::BuildingID(123),
map_model::BuildingID(456),
2018-09-04 21:55:45 +03:00
sim::RouteID(0),
2018-09-07 23:22:37 +03:00
ped_stop1,
ped_stop2,
2018-09-04 21:55:45 +03:00
);
sim.run_until_expectations_met(
&map,
&control_map,
vec![
2018-09-07 23:22:37 +03:00
sim::Event::BusArrivedAtStop(bus, ped_stop1),
2018-09-04 21:55:45 +03:00
sim::Event::PedEntersBus(ped, bus),
2018-09-07 23:22:37 +03:00
sim::Event::BusDepartedFromStop(bus, ped_stop1),
sim::Event::BusArrivedAtStop(bus, ped_stop2),
2018-09-04 21:55:45 +03:00
sim::Event::PedLeavesBus(ped, bus),
2018-09-07 23:22:37 +03:00
sim::Event::BusDepartedFromStop(bus, ped_stop2),
sim::Event::BusArrivedAtStop(bus, route.stops[3]),
2018-09-04 21:55:45 +03:00
// TODO PedReachedBuilding, once the seeding specifies a building instead of picking
],
sim::Tick::from_minutes(10),
);
}