Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 13 additions & 62 deletions lib/node_modules/@stdlib/math/base/special/erf/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' );
var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
var NINF = require( '@stdlib/constants/float64/ninf' );
var PINF = require( '@stdlib/constants/float64/pinf' );
var EPS = require( '@stdlib/constants/float64/eps' );
var abs = require( '@stdlib/math/base/special/abs' );
var isAlmostSameValue = require( '@stdlib/assert/is-almost-same-value' );
var erf = require( './../lib' );


Expand Down Expand Up @@ -57,8 +56,6 @@ tape( 'main export is a function', function test( t ) {

tape( 'the function evaluates the error function for `x` on the interval `[-5,-100]', function test( t ) {
var expected;
var delta;
var tol;
var x;
var y;
var i;
Expand All @@ -67,21 +64,13 @@ tape( 'the function evaluates the error function for `x` on the interval `[-5,-1
x = veryLargeNegative.x;
for ( i = 0; i < x.length; i++ ) {
y = erf( x[i] );
if ( y === expected[i] ) {
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
}
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
}
t.end();
});

tape( 'the function evaluates the error function for `x` on the interval `[5,100]`', function test( t ) {
var expected;
var delta;
var tol;
var x;
var y;
var i;
Expand All @@ -90,21 +79,13 @@ tape( 'the function evaluates the error function for `x` on the interval `[5,100
x = veryLargePositive.x;
for ( i = 0; i < x.length; i++ ) {
y = erf( x[i] );
if ( y === expected[i] ) {
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
}
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
}
t.end();
});

tape( 'the function evaluates the error function for `x` on the interval `[-2.5,-5]`', function test( t ) {
var expected;
var delta;
var tol;
var x;
var y;
var i;
Expand All @@ -113,21 +94,13 @@ tape( 'the function evaluates the error function for `x` on the interval `[-2.5,
x = largeNegative.x;
for ( i = 0; i < x.length; i++ ) {
y = erf( x[i] );
if ( y === expected[i] ) {
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
}
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
}
t.end();
});

tape( 'the function evaluates the error function for `x` on the interval `[2.5,5]`', function test( t ) {
var expected;
var delta;
var tol;
var x;
var y;
var i;
Expand All @@ -136,21 +109,13 @@ tape( 'the function evaluates the error function for `x` on the interval `[2.5,5
x = largePositive.x;
for ( i = 0; i < x.length; i++ ) {
y = erf( x[i] );
if ( y === expected[i] ) {
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
}
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
}
t.end();
});

tape( 'the function evaluates the error function for `x` on the interval `[-1,-3]`', function test( t ) {
var expected;
var delta;
var tol;
var x;
var y;
var i;
Expand All @@ -159,21 +124,13 @@ tape( 'the function evaluates the error function for `x` on the interval `[-1,-3
x = mediumNegative.x;
for ( i = 0; i < x.length; i++ ) {
y = erf( x[i] );
if ( y === expected[i] ) {
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
}
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
}
t.end();
});

tape( 'the function evaluates the error function for `x` on the interval `[1,3]`', function test( t ) {
var expected;
var delta;
var tol;
var x;
var y;
var i;
Expand All @@ -182,13 +139,7 @@ tape( 'the function evaluates the error function for `x` on the interval `[1,3]`
x = mediumPositive.x;
for ( i = 0; i < x.length; i++ ) {
y = erf( x[i] );
if ( y === expected[i] ) {
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
} else {
delta = abs( y - expected[ i ] );
tol = EPS * abs( expected[ i ] );
t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. y: '+y+'. E: '+expected[i]+'. Δ: '+delta+'. tol: '+tol );
}
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
}
t.end();
});
Expand All @@ -203,7 +154,7 @@ tape( 'the function evaluates the error function for `x` on the interval `[-0.8,
x = smallNegative.x;
for ( i = 0; i < x.length; i++ ) {
y = erf( x[i] );
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These and the following changes should be reverted. If we can use exact equality, we should use exact equality.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was the thinking here that you wanted to match the test.native.js tests? If so, it is fine if they slightly diverge, as C implementations are known to sometimes vary due to compiler optimizations. If we can enforce tighter guarantees in JS, we should. So the comment still stands: for this change and the following changes, we should use exact equality tests.

}
t.end();
});
Expand All @@ -218,7 +169,7 @@ tape( 'the function evaluates the error function for `x` on the interval `[0.8,1
x = smallPositive.x;
for ( i = 0; i < x.length; i++ ) {
y = erf( x[i] );
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
}
t.end();
});
Expand All @@ -233,7 +184,7 @@ tape( 'the function evaluates the error function for `x` on the interval `[-0.8,
x = smaller.x;
for ( i = 0; i < x.length; i++ ) {
y = erf( x[i] );
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
}
t.end();
});
Expand All @@ -248,7 +199,7 @@ tape( 'the function evaluates the error function for `x` on the interval `[-1e-3
x = tinyNegative.x;
for ( i = 0; i < x.length; i++ ) {
y = erf( x[i] );
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
}
t.end();
});
Expand All @@ -263,7 +214,7 @@ tape( 'the function evaluates the error function for `x` on the interval `[1e-30
x = tinyPositive.x;
for ( i = 0; i < x.length; i++ ) {
y = erf( x[i] );
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
}
t.end();
});
Expand All @@ -278,7 +229,7 @@ tape( 'the function evaluates the error function for subnormal `x`', function te
x = subnormal.x;
for ( i = 0; i < x.length; i++ ) {
y = erf( x[i] );
t.strictEqual( y, expected[i], 'x: '+x[i]+', y: '+y+', expected: '+expected[i] );
t.strictEqual( isAlmostSameValue( y, expected[ i ], 1 ), true, 'returns expected value' );
}
t.end();
});
Expand Down
Loading