mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-24 01:15:12 +03:00
adding a test for bikes
This commit is contained in:
parent
5a8e42642f
commit
9d1bb00fbd
@ -1,5 +1,5 @@
|
||||
use crate::{AgentID, CarID, ParkingSpot, PedestrianID};
|
||||
use map_model::{BuildingID, BusStopID, IntersectionID, Traversable};
|
||||
use map_model::{BuildingID, BusStopID, IntersectionID, LaneID, Traversable};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
@ -17,6 +17,8 @@ pub enum Event {
|
||||
PedEntersBus(PedestrianID, CarID),
|
||||
PedLeavesBus(PedestrianID, CarID),
|
||||
|
||||
BikeStoppedAtSidewalk(CarID, LaneID),
|
||||
|
||||
// TODO Remove this one
|
||||
AgentEntersTraversable(AgentID, Traversable),
|
||||
}
|
||||
|
@ -184,6 +184,16 @@ impl Scenario {
|
||||
max_speed: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rand_bike(rng: &mut XorShiftRng) -> VehicleSpec {
|
||||
let length = rand_dist(rng, MIN_BIKE_LENGTH, MAX_BIKE_LENGTH);
|
||||
let max_speed = Some(Speed::miles_per_hour(10.0));
|
||||
VehicleSpec {
|
||||
vehicle_type: VehicleType::Bike,
|
||||
length,
|
||||
max_speed,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl SpawnOverTime {
|
||||
@ -259,7 +269,7 @@ impl SpawnOverTime {
|
||||
spawn_time,
|
||||
TripSpec::UsingBike(
|
||||
SidewalkSpot::building(from_bldg, map),
|
||||
rand_bike(rng),
|
||||
Scenario::rand_bike(rng),
|
||||
goal,
|
||||
),
|
||||
map,
|
||||
@ -435,7 +445,7 @@ impl BorderSpawnOverTime {
|
||||
rng,
|
||||
timer,
|
||||
) {
|
||||
let bike = rand_bike(rng);
|
||||
let bike = Scenario::rand_bike(rng);
|
||||
sim.schedule_trip(
|
||||
spawn_time,
|
||||
TripSpec::CarAppearing(
|
||||
@ -626,13 +636,3 @@ fn rand_dist(rng: &mut XorShiftRng, low: Distance, high: Distance) -> Distance {
|
||||
fn rand_time(rng: &mut XorShiftRng, low: Duration, high: Duration) -> Duration {
|
||||
Duration::seconds(rng.gen_range(low.inner_seconds(), high.inner_seconds()))
|
||||
}
|
||||
|
||||
fn rand_bike(rng: &mut XorShiftRng) -> VehicleSpec {
|
||||
let length = rand_dist(rng, MIN_BIKE_LENGTH, MAX_BIKE_LENGTH);
|
||||
let max_speed = Some(Speed::miles_per_hour(10.0));
|
||||
VehicleSpec {
|
||||
vehicle_type: VehicleType::Bike,
|
||||
length,
|
||||
max_speed,
|
||||
}
|
||||
}
|
||||
|
@ -201,6 +201,10 @@ impl TripManager {
|
||||
map: &Map,
|
||||
scheduler: &mut Scheduler,
|
||||
) {
|
||||
self.events.push(Event::BikeStoppedAtSidewalk(
|
||||
bike,
|
||||
bike_rack.sidewalk_pos.lane(),
|
||||
));
|
||||
let trip = &mut self.trips[self.active_trip_mode.remove(&AgentID::Car(bike)).unwrap().0];
|
||||
|
||||
match trip.legs.pop_front() {
|
||||
|
@ -5,6 +5,7 @@ mod runner;
|
||||
mod sim_completion;
|
||||
mod sim_determinism;
|
||||
mod transit;
|
||||
mod trips;
|
||||
|
||||
use structopt::StructOpt;
|
||||
|
||||
@ -17,6 +18,7 @@ fn main() {
|
||||
sim_completion::run(t.suite("sim_completion"));
|
||||
sim_determinism::run(t.suite("sim_determinism"));
|
||||
transit::run(t.suite("transit"));
|
||||
trips::run(t.suite("trips"));
|
||||
|
||||
t.done();
|
||||
}
|
||||
|
38
tests/src/trips.rs
Normal file
38
tests/src/trips.rs
Normal file
@ -0,0 +1,38 @@
|
||||
use crate::runner::TestRunner;
|
||||
use abstutil::Timer;
|
||||
use geom::Duration;
|
||||
use map_model::{BuildingID, IntersectionID};
|
||||
use sim::{DrivingGoal, Event, Scenario, SidewalkSpot, SimFlags, TripSpec};
|
||||
|
||||
pub fn run(t: &mut TestRunner) {
|
||||
t.run_slow("bike_from_border", |h| {
|
||||
let (map, mut sim, mut rng) = SimFlags::for_test("bike_from_border")
|
||||
.load(Some(Duration::seconds(30.0)), &mut Timer::throwaway());
|
||||
// TODO Hardcoding IDs is fragile
|
||||
let goal_bldg = BuildingID(319);
|
||||
let (ped, bike) = sim.schedule_trip(
|
||||
Duration::ZERO,
|
||||
TripSpec::UsingBike(
|
||||
SidewalkSpot::start_at_border(IntersectionID(186), &map).unwrap(),
|
||||
Scenario::rand_bike(&mut rng),
|
||||
DrivingGoal::ParkNear(goal_bldg),
|
||||
),
|
||||
&map,
|
||||
);
|
||||
sim.spawn_all_trips(&map, &mut Timer::throwaway());
|
||||
h.setup_done(&sim);
|
||||
|
||||
sim.run_until_expectations_met(
|
||||
&map,
|
||||
vec![
|
||||
Event::BikeStoppedAtSidewalk(
|
||||
bike.unwrap(),
|
||||
map.get_b(goal_bldg).front_path.sidewalk.lane(),
|
||||
),
|
||||
Event::PedReachedBuilding(ped.unwrap(), goal_bldg),
|
||||
],
|
||||
Duration::minutes(3),
|
||||
);
|
||||
sim.run_until_done(&map, |_| {}, Some(Duration::minutes(4)));
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue
Block a user