fujiapple852 / trippy

A network diagnostic tool
https://trippy.cli.rs
Apache License 2.0
3.8k stars 82 forks source link

Fix unit tests on i386 #1317

Closed fujiapple852 closed 2 months ago

fujiapple852 commented 2 months ago

Fix tests which fail on i386

https://buildd.debian.org/status/fetch.php?pkg=trippy&arch=i386&ver=0.11.0%2Bdfsg-1&stamp=1727294503&raw=0

state::tests::test_scenario::file_ipv4_3probes_3hops_completed_yaml_expects stdout ----
thread 'state::tests::test_scenario::file_ipv4_3probes_3hops_completed_yaml_expects' panicked at crates/trippy-core/src/state.rs:862:47:
assertion `left == right` failed
  left: 781.6666666666666
 right: 781.6666666666665

---- state::tests::test_scenario::file_ipv4_nat_yaml_expects stdout ----
thread 'state::tests::test_scenario::file_ipv4_nat_yaml_expects' panicked at crates/trippy-core/src/state.rs:862:47:
assertion `left == right` failed
  left: 781.6666666666666
 right: 781.6666666666665

failures:
    state::tests::test_scenario::file_ipv4_3probes_3hops_completed_yaml_expects
    state::tests::test_scenario::file_ipv4_nat_yaml_expects
c-git commented 2 months ago

I will look for it, I think there is an approximately equal assert you can use instead.

c-git commented 2 months ago

I don't recall where I saw it. I thought it was std but can't find it. I guess I was mistaken. There are lots of options for float equality but I thought there was one in std, which I can't find. It's easy to find options but let me know if you want me to point out a few.

fujiapple852 commented 2 months ago

Thanks, it just needed:

(expected - actual).abs() < f64::EPSILON
c-git commented 2 months ago

IIRC that only works when the values being subtracted were close to 0 themselves as the EPSILON values changes but if it works here it's good enough until we need something more.

PS. I found what I was remembering it wasn't in std it was in insta.