Implement classes check

This commit is contained in:
Dennis 2024-07-12 19:13:16 +02:00
parent 2596a9354f
commit 5d6c27762c
No known key found for this signature in database
GPG Key ID: 6937EAEA33A3FA5D
6 changed files with 38 additions and 15 deletions

View File

@ -104,14 +104,14 @@ fn main() {
.run(flatc_rust::Args {
extra: &["--gen-all"],
inputs: &[
Path::new("include/engine/api/flatbuffers/position.fbs"),
Path::new("include/engine/api/flatbuffers/waypoint.fbs"),
Path::new("include/engine/api/flatbuffers/route.fbs"),
Path::new("include/engine/api/flatbuffers/table.fbs"),
Path::new("include/engine/api/flatbuffers/fbresult.fbs"),
Path::new("generated/include/engine/api/flatbuffers/position.fbs"),
Path::new("generated/include/engine/api/flatbuffers/waypoint.fbs"),
Path::new("generated/include/engine/api/flatbuffers/route.fbs"),
Path::new("generated/include/engine/api/flatbuffers/table.fbs"),
Path::new("generated/include/engine/api/flatbuffers/fbresult.fbs"),
],
out_dir: Path::new("target/flatbuffers/"),
..Default::default()
})
.expect("flatc failed generated files");
.expect("flatc failed generating files");
}

View File

@ -16,7 +16,7 @@ fn approx_equal_within_offset_range(actual: f64, expectation: f64, offset: f64)
actual >= expectation - offset && actual <= expectation + offset
}
pub fn approximate_within_range(actual: f64, expectation: f64, offset: &Offset) -> bool{
pub fn approximate_within_range(actual: f64, expectation: f64, offset: &Offset) -> bool {
match offset {
Offset::Absolute(a) => approx_equal_within_offset_range(actual, expectation, *a),
Offset::Percentage(p) => aprox_equal_within_percentage_range(actual, expectation, *p),

View File

@ -1,5 +1,8 @@
use super::{
nearest_response::NearestResponse, osm::{OSMNode, OSMWay}, osm_db::OSMDb, osrm_error::OSRMError,
nearest_response::NearestResponse,
osm::{OSMNode, OSMWay},
osm_db::OSMDb,
osrm_error::OSRMError,
route_response::RouteResponse,
};
use crate::{common::local_task::LocalTask, Location};

View File

@ -1,5 +1,3 @@
use serde::Deserialize;
use super::{location::Location, nearest_response::Waypoint};
@ -11,7 +9,7 @@ pub struct Maneuver {
pub location: Location,
pub modifier: Option<String>, // TODO: should be an enum
pub r#type: String, // TODO: should be an enum
pub exit: Option<u64>
pub exit: Option<u64>,
}
#[derive(Debug, Clone, Deserialize)]
@ -37,6 +35,7 @@ pub struct Intersection {
pub entry: Vec<bool>,
pub bearings: Vec<u64>,
pub location: Location,
pub classes: Option<Vec<String>>,
}
#[derive(Deserialize, Default, Debug)]

View File

@ -16,8 +16,7 @@ use core::panic;
use cucumber::{
codegen::ParametersProvider,
gherkin::{Step, Table},
given, then, when,
World,
given, then, when, World,
};
use futures::{future, FutureExt};
use geo_types::Point;
@ -1124,6 +1123,28 @@ fn request_route(world: &mut OSRMWorld, step: &Step, state: String) {
};
assert_eq!(actual, expectation);
},
"classes" => {
// '[' + s.intersections.map(i => '(' + (i.classes ? i.classes.join(',') : '') + ')').join(',') + ']');
let (_, response) = route_result.as_ref().expect("no route response in 'classes'");
let first_route = &response.routes[0];
let first_leg = first_route.legs.first().expect("no first leg on route");
let actual_classes = first_leg.steps.iter().map(|step| {
"[".to_string() +
&step.intersections.iter().map(|intersection| {
let tmp = match &intersection.classes {
Some(classes) => {
classes.join(",")
},
None => "".to_string(),
};
"(".to_string() + &tmp + ")"
}).collect::<Vec<_>>().join(",") + "]"
}).collect::<Vec<_>>().join(",");
let expected_classes = test_case.get("classes").expect("test case classes not found");
assert_eq!(&actual_classes, expected_classes, "classes don't match");
}
// TODO: more checks need to be implemented
_ => {
@ -1151,7 +1172,7 @@ fn main() {
future::ready(()).boxed()
})
// .with_writer(DotWriter::default().normalized())
.filter_run("features/", |fe, r, sc| {
.filter_run("features", |fe, r, sc| {
// .filter_run("features/bicycle/classes.feature", |fe, r, sc| {
let tag = "todo".to_string();
!sc.tags.contains(&tag)