make tests pull events new way, stop returning from step(). fix termion

and test runner.
This commit is contained in:
Dustin Carlino 2019-03-12 13:24:05 -07:00
parent 505b0a9496
commit 15f6981b1d
3 changed files with 19 additions and 16 deletions

View File

@ -409,12 +409,16 @@ fn process_used_memory_mb() -> usize {
#[cfg(unix)]
pub(crate) fn clear_current_line() {
let (terminal_width, _) = termion::terminal_size().unwrap();
print!(
"{}{}",
termion::clear::CurrentLine,
termion::cursor::Left(terminal_width)
);
// Fails in the test runner.
if let Ok((terminal_width, _)) = termion::terminal_size() {
print!(
"{}{}",
termion::clear::CurrentLine,
termion::cursor::Left(terminal_width)
);
} else {
print!("\r");
}
}
#[cfg(windows)]

View File

@ -2,8 +2,7 @@ use crate::{AgentID, CarID, ParkingSpot, PedestrianID};
use map_model::{BuildingID, BusStopID, IntersectionID, LaneID, Traversable};
use serde_derive::{Deserialize, Serialize};
// TODO rm Clone
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum Event {
CarReachedParkingSpot(CarID, ParkingSpot),
CarOrBikeReachedBorder(CarID, IntersectionID),

View File

@ -268,7 +268,7 @@ impl Sim {
// Running
impl Sim {
pub fn step(&mut self, map: &Map) -> Vec<Event> {
pub fn step(&mut self, map: &Map) {
if !self.spawner.is_done() {
panic!("Forgot to call spawn_all_trips");
}
@ -351,12 +351,11 @@ impl Sim {
}
}
let mut events = self.trips.collect_events();
events.extend(self.transit.collect_events());
self.events_since_last_step.clear();
self.events_since_last_step.extend(events.clone());
// TODO Stop returning these here
events
self.events_since_last_step
.extend(self.trips.collect_events());
self.events_since_last_step
.extend(self.transit.collect_events());
}
pub fn dump_before_abort(&self) {
@ -419,8 +418,9 @@ impl Sim {
if expectations.is_empty() {
return;
}
for ev in self.step(&map).into_iter() {
if ev == *expectations.front().unwrap() {
self.step(&map);
for ev in self.get_events_since_last_step() {
if ev == expectations.front().unwrap() {
println!("At {}, met expectation {:?}", self.time, ev);
expectations.pop_front();
if expectations.is_empty() {