All files / tests / js_denotest / test-util / assertAlmostEqualsArray.js

100.00% Branches 4/4
100.00% Lines 29/29
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
x1
x1
x1
x1
x1
x1
x2
x1
x1
x1
x1
x1
x1
x1
x1
x1
x1
x1
x1
x2
x7
x8
x8
x1
x7
x8833
x8833
x7


























/**
 * @file Compare two Float32Array objects with allowing specified error
 *
 * @author aKuad
 */

import { assertAlmostEquals, AssertionError } from "jsr:@std/assert@1";


/**
 * Compare two Float32Array objects with allowing specified error
 *
 * @param {Array} actual The actual array to compare
 * @param {Array} expected The expected array to compare
 * @param {number} tolerance The tolerance to consider the values almost equal
 *
 * @throws {AssertionError} If length of `actual` and `expected` is not equal
 * @throws {AssertionError} If any element has error over than `tolerance`
 */
export function assertAlmostEqualsArray(actual, expected, tolerance) {
  if(actual.length !== expected.length) {
    throw new AssertionError(`Length mismatch:\nactual.length  : ${actual.length}\nexpected.length: ${expected.length}`);
  }

  for(let i = 0; i < actual.length; i++) {
    assertAlmostEquals(actual[i], expected[i], tolerance);
  }
}