From ee5461d311ed4deda7de615bd265039ffb5f8568 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sun, 2 Oct 2022 22:01:24 -0500 Subject: [PATCH] Fix math for calculating cleaned size --- tests/flags.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/flags.rs b/tests/flags.rs index c810f56..b9fe847 100644 --- a/tests/flags.rs +++ b/tests/flags.rs @@ -103,11 +103,14 @@ fn count_cleaned(target: &TempDir, args: &[&str], old_size: u64) -> Result // Make sure this is accurate. let new_size = get_size(target.path())?; - // Cargo-sweep and `get_size` appear to have different rounding behavior. - // Make sure this is within one byte. + // Due to rounding and truncation we might have an inexact result. Make sure these are within 1% of each other, + // but don't require an exact match. + let calculated_size = old_size - cleaned; + let diff = new_size.abs_diff(calculated_size); + let one_percent = old_size as f64 * 0.01; assert!( - old_size - cleaned - new_size <= 1, - "new_size={}, old_size={}, cleaned={}", + diff <= one_percent as u64, + "new_size={}, old_size={}, cleaned={}, diff={diff}, 1%={one_percent}", new_size, old_size, cleaned