From 995eaec5559235be074446e02f87e022bf69d855 Mon Sep 17 00:00:00 2001 From: Dennis Date: Wed, 5 Jun 2024 12:04:26 +0200 Subject: [PATCH] Move approximate equality test for floats to util --- tests/common/f64_utils.rs | 4 ++++ tests/common/mod.rs | 1 + tests/cucumber.rs | 5 +++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/common/f64_utils.rs b/tests/common/f64_utils.rs index e69de29bb..838bc2732 100644 --- a/tests/common/f64_utils.rs +++ b/tests/common/f64_utils.rs @@ -0,0 +1,4 @@ +pub fn approx_equal(a: f64, b: f64, dp: u8) -> bool { + let p = 10f64.powi(-(dp as i32)); + (a - b).abs() < p +} \ No newline at end of file diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 1e32275df..79611fa75 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -1,4 +1,5 @@ pub mod cli_arguments; +pub mod f64_utils; pub mod file_util; pub mod hash_util; pub mod lexicographic_file_walker; diff --git a/tests/cucumber.rs b/tests/cucumber.rs index a9a975e66..f17740cf7 100644 --- a/tests/cucumber.rs +++ b/tests/cucumber.rs @@ -5,8 +5,9 @@ mod common; use cheap_ruler::CheapRuler; use clap::Parser; use common::{ - cli_arguments::Args, hash_util::md5_of_osrm_executables, nearest_response::NearestResponse, - osm::OSMWay, osrm_world::OSRMWorld, task_starter::TaskStarter, + cli_arguments::Args, f64_utils::approx_equal, hash_util::md5_of_osrm_executables, + nearest_response::NearestResponse, osm::OSMWay, osrm_world::OSRMWorld, + task_starter::TaskStarter, }; use core::panic; use cucumber::{self, gherkin::Step, given, when, World};