diff --git a/test/unary_test.js b/test/unary_test.js index 083c7d8..8458830 100644 --- a/test/unary_test.js +++ b/test/unary_test.js @@ -5,12 +5,12 @@ import * as unaryFunctions from '../src/unary.js'; import * as utils from './utils.js'; describe('test unary', function() { - function testUnary(op, input, expected, shape, atolTolerance) { + function testUnary(op, input, expected, shape, atol) { const x = new Tensor(shape, input); const y = unaryFunctions[op](x); utils.checkShape(y, shape); - if (atolTolerance !== undefined) { - utils.checkValueByATOL(y, expected, atolTolerance); + if (atol !== undefined) { + utils.checkValueByATOL(y, expected, atol); } else { utils.checkValue(y, expected); } @@ -384,7 +384,8 @@ describe('test unary', function() { -1.0692689659512902, 0.04121219038394666, ], - [3], 1 / 1024); + [3], + 1 / 1024); testUnary( 'log', [ @@ -406,7 +407,8 @@ describe('test unary', function() { 0.34275879190200165, -2.753918343538326, ], - [3, 4], 1 / 1024); + [3, 4], + 1 / 1024); testUnary( 'log', [ @@ -485,7 +487,8 @@ describe('test unary', function() { 0.31843664006339245, -0.8416115978644251, ], - [3, 4, 5], 1 / 1024); + [3, 4, 5], + 1 / 1024); testUnary( 'log', [ @@ -564,7 +567,8 @@ describe('test unary', function() { 0.31843664006339245, -0.8416115978644251, ], - [3, 2, 2, 5], 1 / 1024); + [3, 2, 2, 5], + 1 / 1024); }); it('neg', function() { @@ -618,7 +622,8 @@ describe('test unary', function() { 0.21339342411295945, -0.6558230571220807, ], - [3, 4], 1 / 1024); + [3, 4], + 1 / 1024); testUnary( 'sin', [ @@ -643,7 +648,8 @@ describe('test unary', function() { 0.21339342411295945, -0.6558230571220807, ], - [3, 2, 2], 1 / 1024); + [3, 2, 2], + 1 / 1024); testUnary( 'sin', [ @@ -674,7 +680,8 @@ describe('test unary', function() { 0.21339342411295945, -0.6558230571220807, ], - [3, 2, 2, 1], 1 / 1024); + [3, 2, 2, 1], + 1 / 1024); }); it('tan', function() { diff --git a/test/utils.js b/test/utils.js index 54cd4bb..fadb282 100644 --- a/test/utils.js +++ b/test/utils.js @@ -48,12 +48,13 @@ export function checkValue(tensor, expected, nulp = 0) { } } -export function checkValueByATOL(tensor, expected, tolerance) { - assert.isTrue(tensor.size === expected.length); +export function checkValueByATOL(actual, expected, tolerance) { + assert.isTrue(actual.size === expected.length); for (let i = 0; i < expected.length; ++i) { - const actual = tensor.getValueByIndex(i); - assert.isTrue(actual >= expected[i] - tolerance && actual <= expected[i] + tolerance, - `${actual} is almost equal to ${expected[i]} by ${tolerance} tolerance of ATOL metrics`); + const actualValue = actual.getValueByIndex(i); + assert.isTrue(actualValue >= expected[i] - tolerance && actualValue <= expected[i] + tolerance, + `${actualValue} is almost equal to ${expected[i]} by ${tolerance} tolerance of ATOL` + + 'metrics'); } }