Cleanup some code nearest step
This commit is contained in:
		
							parent
							
								
									3f14453f5b
								
							
						
					
					
						commit
						32dffeb54d
					
				| @ -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 crate::Point; | ||||||
| use cucumber::World; | use cucumber::World; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -158,10 +158,6 @@ fn request_nearest(world: &mut OSRMWorld, step: &Step) { | |||||||
|     } else { |     } else { | ||||||
|         println!("{cache_path:?} does not exist"); |         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"); |     let routed_path = path.join("build").join("osrm-routed"); | ||||||
|     if !routed_path.exists() { |     if !routed_path.exists() { | ||||||
| @ -170,53 +166,51 @@ fn request_nearest(world: &mut OSRMWorld, step: &Step) { | |||||||
| 
 | 
 | ||||||
|     // parse query data
 |     // parse query data
 | ||||||
|     let t = &step.table.as_ref().expect("no query table specified"); |     let t = &step.table.as_ref().expect("no query table specified"); | ||||||
|     let test_cases: Vec<_> = t.rows.iter().skip(1).map(|row|{ |     let test_cases: Vec<_> = t | ||||||
|         assert_eq!(row.len(), 2, "test case broken: row needs to have two entries"); |         .rows | ||||||
|         let query = row.get(0).unwrap(); |         .iter() | ||||||
|         let expected = row.get(1).unwrap(); |         .skip(1) | ||||||
|         assert_eq!(query.len(), 1); |         .map(|row| { | ||||||
|         assert_eq!(expected.len(), 1); |             assert_eq!( | ||||||
|         (query.chars().next().unwrap(), expected.chars().next().unwrap()) |                 row.len(), | ||||||
|     }).collect(); |                 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"); |     let data_path = cache_path.join(world.scenario_id.to_owned() + ".osrm"); | ||||||
|     println!("{routed_path:?} {}", data_path.to_str().unwrap()); |     println!("{routed_path:?} {}", data_path.to_str().unwrap()); | ||||||
|     // TODO: this should be a let statement to reduce nesting?
 |     let handle = Command::new(routed_path) | ||||||
|     match Command::new(routed_path) |  | ||||||
|         .arg(data_path.to_str().unwrap()) |         .arg(data_path.to_str().unwrap()) | ||||||
|         .spawn() |         .spawn(); | ||||||
|     { |  | ||||||
|         Ok(mut child) => { |  | ||||||
| 
 | 
 | ||||||
|             for (query, expected) in test_cases { |     if let Err(e) = handle { | ||||||
|                 let query_coord = world.get_location(query); |         panic!("{e}"); | ||||||
|                 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}"), |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     // 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)
 |     if let Err(e) = handle.expect("osrm-routed died unexpectedly").kill() { | ||||||
|     //     .arg(data_path.to_str().unwrap().spawn();
 |         panic!("shutdown failed: {e}"); | ||||||
|     //     .output()
 |     } | ||||||
|     // {
 |  | ||||||
|     //     Ok(o) => println!("{o:?}"),
 |  | ||||||
|     //     Err(e) => panic!("{e}"),
 |  | ||||||
|     // }
 |  | ||||||
| 
 |  | ||||||
|     // todo!("nearest {step:?}");
 |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // TODO: move to different file
 | // TODO: move to different file
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user