From 32dffeb54db8c7a5bfa868f85aa8fdc424e18d5c Mon Sep 17 00:00:00 2001 From: Dennis Date: Thu, 30 May 2024 18:32:06 +0200 Subject: [PATCH] Cleanup some code nearest step --- tests/common/osrm_world.rs | 2 +- tests/cucumber.rs | 76 ++++++++++++++++++-------------------- 2 files changed, 36 insertions(+), 42 deletions(-) diff --git a/tests/common/osrm_world.rs b/tests/common/osrm_world.rs index e74d3a1d0..c2826da2e 100644 --- a/tests/common/osrm_world.rs +++ b/tests/common/osrm_world.rs @@ -1,4 +1,4 @@ -use std::{collections::{HashMap, HashSet}, fs::File, path::PathBuf}; +use std::{collections::HashMap, fs::File, path::PathBuf}; use crate::Point; use cucumber::World; diff --git a/tests/cucumber.rs b/tests/cucumber.rs index 57e19f9dd..25ac02365 100644 --- a/tests/cucumber.rs +++ b/tests/cucumber.rs @@ -158,10 +158,6 @@ fn request_nearest(world: &mut OSRMWorld, step: &Step) { } else { println!("{cache_path:?} does not exist"); } - // extract osm file (partition, preprocess) - - // parse table from Step and build query list - // run queries (in parallel) and validate results let routed_path = path.join("build").join("osrm-routed"); if !routed_path.exists() { @@ -170,53 +166,51 @@ fn request_nearest(world: &mut OSRMWorld, step: &Step) { // parse query data let t = &step.table.as_ref().expect("no query table specified"); - let test_cases: Vec<_> = t.rows.iter().skip(1).map(|row|{ - assert_eq!(row.len(), 2, "test case broken: row needs to have two entries"); - let query = row.get(0).unwrap(); - let expected = row.get(1).unwrap(); - assert_eq!(query.len(), 1); - assert_eq!(expected.len(), 1); - (query.chars().next().unwrap(), expected.chars().next().unwrap()) - }).collect(); + let test_cases: Vec<_> = t + .rows + .iter() + .skip(1) + .map(|row| { + assert_eq!( + row.len(), + 2, + "test case broken: row needs to have two entries" + ); + let query = row.get(0).unwrap(); + let expected = row.get(1).unwrap(); + assert_eq!(query.len(), 1); + assert_eq!(expected.len(), 1); + ( + query.chars().next().unwrap(), + expected.chars().next().unwrap(), + ) + }) + .collect(); let data_path = cache_path.join(world.scenario_id.to_owned() + ".osrm"); println!("{routed_path:?} {}", data_path.to_str().unwrap()); - // TODO: this should be a let statement to reduce nesting? - match Command::new(routed_path) + let handle = Command::new(routed_path) .arg(data_path.to_str().unwrap()) - .spawn() - { - Ok(mut child) => { + .spawn(); - for (query, expected) in test_cases { - let query_coord = world.get_location(query); - let expected_coord = world.get_location(expected); - - println!("{query_coord:?} => {expected_coord:?}"); - } - - if let Err(e) = child.kill() { - panic!("shutdown failed: {e}"); - } - }, - Err(e) => panic!("{e}"), + if let Err(e) = handle { + panic!("{e}"); } - // parse expected results + // parse and run test cases + for (query, expected) in test_cases { + let query_coord = world.get_location(query); + let expected_coord = world.get_location(expected); - // run queries + println!("{query_coord:?} => {expected_coord:?}"); + // run queries - // check results + // check results + } - // match Command::new(routed_path) - // .arg(data_path.to_str().unwrap().spawn(); - // .output() - // { - // Ok(o) => println!("{o:?}"), - // Err(e) => panic!("{e}"), - // } - - // todo!("nearest {step:?}"); + if let Err(e) = handle.expect("osrm-routed died unexpectedly").kill() { + panic!("shutdown failed: {e}"); + } } // TODO: move to different file