Skip to content

Commit

Permalink
Remove the crate float-cmp.
Browse files Browse the repository at this point in the history
We can do a "classic" float comparison as clippy suggests https://rust-lang.github.io/rust-clippy/rust-1.72.0/index.html#/float_cmp and remove `float-cmp` from

```rust
let error_margin = f64::EPSILON; // Use an epsilon for comparison
// Or, if Rust <= 1.42, use `std::f64::EPSILON` constant instead.
// let error_margin = std::f64::EPSILON;
if (y - 1.23f64).abs() < error_margin { }
if (y - x).abs() > error_margin { }
```

Note: we compare `f64` for predicate value here https://github.com/Orange-OpenSource/hurl/blob/07512a9cbfbba17cd16df3706f3a0c5c98b67d3d/packages/hurl/src/runner/number.rs#L32-L40
so there is no reason to use `float-cmp` in jsonpath module
  • Loading branch information
jcamiel authored and hurl-bot committed Oct 25, 2024
1 parent 1a4c949 commit d5f1b3e
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 18 deletions.
11 changes: 0 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/hurl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ clap = { version = "4.5.20", features = ["cargo", "string", "wrap_help"] }
curl = "0.4.47"
curl-sys = "0.4.77"
encoding = "0.2.33"
float-cmp = "0.10.0"
glob = "0.3.1"
hex = "0.4.3"
hex-literal = "0.4.1"
Expand Down
8 changes: 3 additions & 5 deletions packages/hurl/src/jsonpath/eval/selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
*
*/

use float_cmp::approx_eq;

use crate::jsonpath::ast::{Predicate, PredicateFunc, Selector, Slice};
use crate::jsonpath::JsonpathResult;

Expand Down Expand Up @@ -154,8 +152,8 @@ impl Predicate {
match (value, self.func.clone()) {
(_, PredicateFunc::KeyExist) => true,
(serde_json::Value::Number(v), PredicateFunc::Equal(ref num)) => {
approx_eq!(f64, v.as_f64().unwrap(), num.to_f64(), ulps = 2)
} //v.as_f64().unwrap() == num.to_f64(),
(v.as_f64().unwrap() - num.to_f64()).abs() < f64::EPSILON
}
(serde_json::Value::Number(v), PredicateFunc::GreaterThan(ref num)) => {
v.as_f64().unwrap() > num.to_f64()
}
Expand All @@ -176,7 +174,7 @@ impl Predicate {
v != *s
}
(serde_json::Value::Number(v), PredicateFunc::NotEqual(ref num)) => {
!approx_eq!(f64, v.as_f64().unwrap(), num.to_f64(), ulps = 2)
(v.as_f64().unwrap() - num.to_f64()).abs() >= f64::EPSILON
}
(serde_json::Value::Bool(v), PredicateFunc::EqualBool(ref s)) => v == *s,
_ => false,
Expand Down
1 change: 0 additions & 1 deletion packages/hurl_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ repository = "https://github.com/Orange-OpenSource/hurl"

[dependencies]
colored = "2.1.0"
float-cmp = "0.10.0"
libxml = "0.3.3"
regex = "1.11.1"

Expand Down

0 comments on commit d5f1b3e

Please sign in to comment.