Deprecated
(will be removed after 1.0.0) Import from https://deno.land/std/assert/assert_almost_equals.ts instead.
import { assertAlmostEquals } from "https://deno.land/std@0.220.1/testing/asserts.ts";
Make an assertion that actual
and expected
are almost equal numbers
through a given tolerance. It can be used to take into account IEEE-754
double-precision floating-point representation limitations. If the values
are not almost equal then throw.
Examples
Example 1
Example 1
import { assertAlmostEquals } from "https://deno.land/std@0.220.1/testing/asserts.ts";
assertAlmostEquals(0.01, 0.02, 0.1); // Doesn't throw
assertAlmostEquals(0.01, 0.02); // Throws
assertAlmostEquals(0.1 + 0.2, 0.3, 1e-16); // Doesn't throw
assertAlmostEquals(0.1 + 0.2, 0.3, 1e-17); // Throws