mirror of
https://github.com/denoland/std.git
synced 2024-11-21 20:50:22 +00:00
fix(assert): fix tolerance calculation when comparing negative values (#5019)
This commit is contained in:
parent
2d5b5b42bc
commit
a6781da213
@ -40,7 +40,7 @@ export function assertAlmostEquals(
|
||||
}
|
||||
const delta = Math.abs(expected - actual);
|
||||
if (tolerance === undefined) {
|
||||
tolerance = isFinite(expected) ? expected * 1e-7 : 1e-7;
|
||||
tolerance = isFinite(expected) ? Math.abs(expected * 1e-7) : 1e-7;
|
||||
}
|
||||
if (delta <= tolerance) {
|
||||
return;
|
||||
|
@ -8,7 +8,9 @@ Deno.test("assertAlmostEquals() matches values within default precision range",
|
||||
assertAlmostEquals(NaN, NaN);
|
||||
assertAlmostEquals(Number.NaN, Number.NaN);
|
||||
assertAlmostEquals(9e20, 9.0000000001e20);
|
||||
assertAlmostEquals(-9e20, -9.0000000001e20);
|
||||
assertAlmostEquals(1.000000001e-8, 1.000000002e-8);
|
||||
assertAlmostEquals(-1.000000001e-8, -1.000000002e-8);
|
||||
});
|
||||
|
||||
Deno.test("assertAlmostEquals() throws values outside default precision range", () => {
|
||||
|
Loading…
Reference in New Issue
Block a user