MCPcopy Index your code
hub / github.com/nodejs/node / assert_array_approx_equals

Function assert_array_approx_equals

test/fixtures/wpt/resources/testharness.js:1763–1788  ·  view source on GitHub ↗

* Assert that each array property in ``actual`` is a number within * ± `epsilon` of the corresponding property in `expected`. * * @param {Array} actual - Array of test values. * @param {Array} expected - Array of values expected to be close to the values in ``actual``. * @pa

(actual, expected, epsilon, description)

Source from the content-addressed store, hash-verified

1761 * @param {string} [description] - Description of the condition being tested.
1762 */
1763 function assert_array_approx_equals(actual, expected, epsilon, description)
1764 {
1765 /*
1766 * Test if two primitive arrays are equal within +/- epsilon
1767 */
1768 assert(actual.length === expected.length,
1769 "assert_array_approx_equals", description,
1770 "lengths differ, expected ${expected} got ${actual}",
1771 {expected:expected.length, actual:actual.length});
1772
1773 for (var i = 0; i < actual.length; i++) {
1774 assert(actual.hasOwnProperty(i) === expected.hasOwnProperty(i),
1775 "assert_array_approx_equals", description,
1776 "property ${i}, property expected to be ${expected} but was ${actual}",
1777 {i:i, expected:expected.hasOwnProperty(i) ? "present" : "missing",
1778 actual:actual.hasOwnProperty(i) ? "present" : "missing"});
1779 assert(typeof actual[i] === "number",
1780 "assert_array_approx_equals", description,
1781 "property ${i}, expected a number but got a ${type_actual}",
1782 {i:i, type_actual:typeof actual[i]});
1783 assert(Math.abs(actual[i] - expected[i]) <= epsilon,
1784 "assert_array_approx_equals", description,
1785 "property ${i}, expected ${expected} +/- ${epsilon}, expected ${expected} but got ${actual}",
1786 {i:i, expected:expected[i], actual:actual[i], epsilon:epsilon});
1787 }
1788 }
1789 expose_assert(assert_array_approx_equals, "assert_array_approx_equals");
1790
1791 /**

Callers

nothing calls this directly

Calls 2

assertFunction · 0.70
hasOwnPropertyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…