Skip to content

Commit 41ce4c9

Browse files
committed
test: ensure deterministic values and use approximate equality for native addon
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 0d966fa commit 41ce4c9

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

lib/node_modules/@stdlib/math/base/special/log1mexp/test/test.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
var tape = require( 'tape' );
2424
var NINF = require( '@stdlib/constants/float64/ninf' );
2525
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26-
var randu = require( '@stdlib/random/base/randu' );
26+
var uniform = require( '@stdlib/random/base/uniform' );
2727
var abs = require( '@stdlib/math/base/special/abs' );
2828
var exp = require( '@stdlib/math/base/special/exp' );
2929
var expm1 = require( '@stdlib/math/base/special/expm1' );
@@ -67,13 +67,17 @@ tape( 'if provided `+-0`, the function returns -infinity', function test( t ) {
6767
});
6868

6969
tape( 'the function computes the natural logarithm of `1-exp(-|x|)` (`0 < |x| <= ln(2)`)', function test( t ) {
70+
var rand;
7071
var x;
7172
var y;
7273
var v;
7374
var i;
7475

76+
rand = uniform.factory( 0.0, LN2, {
77+
'seed': 129
78+
});
7579
for ( i = 0; i < 1e3; i++ ) {
76-
v = randu() * LN2;
80+
v = rand();
7781
x = log1mexp( v );
7882
y = ln( -expm1( -v ) );
7983
t.strictEqual( x, y, 'returns '+y+' when provided '+v );
@@ -82,13 +86,18 @@ tape( 'the function computes the natural logarithm of `1-exp(-|x|)` (`0 < |x| <=
8286
});
8387

8488
tape( 'the function computes the natural logarithm of `1-exp(-|x|)` (`x > ln(2)`)', function test( t ) {
89+
var rand;
8590
var x;
8691
var y;
8792
var v;
8893
var i;
8994

95+
rand = uniform.factory( LN2 + EPS, 100.0, {
96+
'seed': 91919
97+
});
98+
9099
for ( i = 0; i < 1e3; i++ ) {
91-
v = LN2 + EPS + (randu()*100.0);
100+
v = rand();
92101
x = log1mexp( v );
93102
y = log1p( -exp( -v ) );
94103
t.strictEqual( x, y, 'returns '+y+' when provided '+v );

lib/node_modules/@stdlib/math/base/special/log1mexp/test/test.native.js

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var resolve = require( 'path' ).resolve;
2424
var tape = require( 'tape' );
2525
var NINF = require( '@stdlib/constants/float64/ninf' );
2626
var isnan = require( '@stdlib/math/base/assert/is-nan' );
27-
var randu = require( '@stdlib/random/base/randu' );
27+
var uniform = require( '@stdlib/random/base/uniform' );
2828
var tryRequire = require( '@stdlib/utils/try-require' );
2929
var abs = require( '@stdlib/math/base/special/abs' );
3030
var exp = require( '@stdlib/math/base/special/exp' );
@@ -76,31 +76,56 @@ tape( 'if provided `+-0`, the function returns -infinity', opts, function test(
7676
});
7777

7878
tape( 'the function computes the natural logarithm of `1-exp(-|x|)` (`0 < |x| <= ln(2)`)', opts, function test( t ) {
79+
var delta;
80+
var rand;
81+
var tol;
7982
var x;
8083
var y;
8184
var v;
8285
var i;
8386

87+
rand = uniform.factory( 0.0, LN2, {
88+
'seed': 129
89+
});
8490
for ( i = 0; i < 1e3; i++ ) {
85-
v = randu() * LN2;
91+
v = rand();
8692
x = log1mexp( v );
8793
y = ln( -expm1( -v ) );
88-
t.strictEqual( x, y, 'returns '+y+' when provided '+v );
94+
if ( x === y ) {
95+
t.strictEqual( x, y, 'returns '+y+' when provided '+v );
96+
} else {
97+
delta = abs( x - y );
98+
tol = 1.0 * EPS * abs( y );
99+
t.ok( delta <= tol, 'within tolerance. v: '+v+'. actual: '+x+'. expected: '+y+'. Δ: '+delta+'. tol: '+tol+'.' );
100+
}
89101
}
90102
t.end();
91103
});
92104

93105
tape( 'the function computes the natural logarithm of `1-exp(-|x|)` (`x > ln(2)`)', opts, function test( t ) {
106+
var delta;
107+
var rand;
108+
var tol;
94109
var x;
95110
var y;
96111
var v;
97112
var i;
98113

114+
rand = uniform.factory( LN2 + EPS, 100.0, {
115+
'seed': 919
116+
});
117+
99118
for ( i = 0; i < 1e3; i++ ) {
100-
v = LN2 + EPS + (randu()*100.0);
119+
v = rand();
101120
x = log1mexp( v );
102121
y = log1p( -exp( -v ) );
103-
t.strictEqual( x, y, 'returns '+y+' when provided '+v );
122+
if ( x === y ) {
123+
t.strictEqual( x, y, 'returns '+y+' when provided '+v );
124+
} else {
125+
delta = abs( x - y );
126+
tol = 1.0 * EPS * abs( y );
127+
t.ok( delta <= tol, 'within tolerance. v: '+v+'. actual: '+x+'. expected: '+y+'. Δ: '+delta+'. tol: '+tol+'.' );
128+
}
104129
}
105130
t.end();
106131
});

0 commit comments

Comments
 (0)