Skip to content

Commit d4f4761

Browse files
committed
test: update tests according to current project conventions
--- 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 8dfb26b commit d4f4761

File tree

1 file changed

+39
-36
lines changed
  • lib/node_modules/@stdlib/math/base/special/expf/test

1 file changed

+39
-36
lines changed

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

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,22 @@
2121
// MODULES //
2222

2323
var tape = require( 'tape' );
24-
var isnan = require( '@stdlib/math/base/assert/is-nan' );
25-
var absf = require( '@stdlib/math/base/special/absf' );
24+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
25+
var f32 = require( '@stdlib/number/float64/base/to-float32' );
26+
var ulpdiff = require( '@stdlib/number/float32/base/ulp-difference' );
27+
var isPositiveZerof = require( '@stdlib/math/base/assert/is-positive-zerof' );
2628
var PINF = require( '@stdlib/constants/float32/pinf' );
2729
var NINF = require( '@stdlib/constants/float32/ninf' );
28-
var EPS = require( '@stdlib/constants/float32/eps' );
2930
var expf = require( './../lib' );
3031

3132

3233
// FIXTURES //
3334

34-
var mediumNegative = require( './fixtures/julia/medium_negative_float32.json' );
35-
var mediumPositive = require( './fixtures/julia/medium_positive_float32.json' );
36-
var smallNegative = require( './fixtures/julia/small_negative_float32.json' );
37-
var smallPositive = require( './fixtures/julia/small_positive_float32.json' );
38-
var tiny = require( './fixtures/julia/tiny_float32.json' );
35+
var mediumNegative = require( './fixtures/julia/medium_negative.json' );
36+
var mediumPositive = require( './fixtures/julia/medium_positive.json' );
37+
var smallNegative = require( './fixtures/julia/small_negative.json' );
38+
var smallPositive = require( './fixtures/julia/small_positive.json' );
39+
var tiny = require( './fixtures/julia/tiny.json' );
3940

4041

4142
// TESTS //
@@ -48,8 +49,6 @@ tape( 'main export is a function', function test( t ) {
4849

4950
tape( 'the function accurately computes the natural exponential function for negative medium numbers', function test( t ) {
5051
var expected;
51-
var delta;
52-
var tol;
5352
var x;
5453
var v;
5554
var i;
@@ -58,18 +57,16 @@ tape( 'the function accurately computes the natural exponential function for neg
5857
expected = mediumNegative.expected;
5958

6059
for ( i = 0; i < x.length; i++ ) {
60+
x[ i ] = f32( x[ i ] );
61+
expected[ i ] = f32( expected[ i ] );
6162
v = expf( x[ i ] );
62-
delta = absf( v - expected[ i ] );
63-
tol = 50 * EPS * absf( expected[ i ] );
64-
t.ok( delta <= tol, 'within tolerance. x: ' + x[ i ] + '. Value: ' + v + '. Expected: ' + expected[ i ] + '. Tolerance: ' + tol + '.' );
63+
t.strictEqual( ulpdiff( v, expected[ i ] ) <= 1, true, 'returns expected value' );
6564
}
6665
t.end();
6766
});
6867

6968
tape( 'the function accurately computes the natural exponential function for positive medium numbers', function test( t ) {
7069
var expected;
71-
var delta;
72-
var tol;
7370
var x;
7471
var v;
7572
var i;
@@ -78,18 +75,16 @@ tape( 'the function accurately computes the natural exponential function for pos
7875
expected = mediumPositive.expected;
7976

8077
for ( i = 0; i < x.length; i++ ) {
78+
x[ i ] = f32( x[ i ] );
79+
expected[ i ] = f32( expected[ i ] );
8180
v = expf( x[ i ] );
82-
delta = absf( v - expected[ i ] );
83-
tol = 50 * EPS * absf( expected[ i ] );
84-
t.ok( delta <= tol, 'within tolerance. x: ' + x[ i ] + '. Value: ' + v + '. Expected: ' + expected[ i ] + '. Tolerance: ' + tol + '.' );
81+
t.strictEqual( ulpdiff( v, expected[ i ] ) <= 1, true, 'returns expected value' );
8582
}
8683
t.end();
8784
});
8885

8986
tape( 'the function accurately computes the natural exponential function for negative small numbers', function test( t ) {
9087
var expected;
91-
var delta;
92-
var tol;
9388
var x;
9489
var v;
9590
var i;
@@ -98,18 +93,16 @@ tape( 'the function accurately computes the natural exponential function for neg
9893
expected = smallNegative.expected;
9994

10095
for ( i = 0; i < x.length; i++ ) {
96+
x[ i ] = f32( x[ i ] );
97+
expected[ i ] = f32( expected[ i ] );
10198
v = expf( x[ i ] );
102-
delta = absf( v - expected[ i ] );
103-
tol = 50 * EPS * absf( expected[ i ] );
104-
t.ok( delta <= tol, 'within tolerance. x: ' + x[ i ] + '. Value: ' + v + '. Expected: ' + expected[ i ] + '. Tolerance: ' + tol + '.' );
99+
t.strictEqual( ulpdiff( v, expected[ i ] ) <= 1, true, 'returns expected value' );
105100
}
106101
t.end();
107102
});
108103

109104
tape( 'the function accurately computes the natural exponential function for positive small numbers', function test( t ) {
110105
var expected;
111-
var delta;
112-
var tol;
113106
var x;
114107
var v;
115108
var i;
@@ -118,18 +111,16 @@ tape( 'the function accurately computes the natural exponential function for pos
118111
expected = smallPositive.expected;
119112

120113
for ( i = 0; i < x.length; i++ ) {
114+
x[ i ] = f32( x[ i ] );
115+
expected[ i ] = f32( expected[ i ] );
121116
v = expf( x[ i ] );
122-
delta = absf( v - expected[ i ] );
123-
tol = 50 * EPS * absf( expected[ i ] );
124-
t.ok( delta <= tol, 'within tolerance. x: ' + x[ i ] + '. Value: ' + v + '. Expected: ' + expected[ i ] + '. Tolerance: ' + tol + '.' );
117+
t.strictEqual( ulpdiff( v, expected[ i ] ) <= 1, true, 'returns expected value' );
125118
}
126119
t.end();
127120
});
128121

129122
tape( 'the function accurately computes the natural exponential function for very small `x`', function test( t ) {
130123
var expected;
131-
var delta;
132-
var tol;
133124
var x;
134125
var v;
135126
var i;
@@ -138,28 +129,40 @@ tape( 'the function accurately computes the natural exponential function for ver
138129
expected = tiny.expected;
139130

140131
for ( i = 0; i < x.length; i++ ) {
132+
x[ i ] = f32( x[ i ] );
133+
expected[ i ] = f32( expected[ i ] );
141134
v = expf( x[ i ] );
142-
delta = absf( v - expected[ i ] );
143-
tol = 50 * EPS * absf( expected[ i ] );
144-
t.ok( delta <= tol, 'within tolerance. x: ' + x[ i ] + '. Value: ' + v + '. Expected: ' + expected[ i ] + '. Tolerance: ' + tol + '.' );
135+
t.strictEqual( ulpdiff( v, expected[ i ] ) <= 0, true, 'returns expected value' );
145136
}
146137
t.end();
147138
});
148139

149140
tape( 'the function returns `0` if provided a `-infinity`', function test( t ) {
150141
var val = expf( NINF );
151-
t.equal( val, 0.0, 'returns expected value' );
142+
t.strictEqual( isPositiveZerof( val ), true, 'returns expected value' );
152143
t.end();
153144
});
154145

155146
tape( 'the function returns `+infinity` if provided a `+infinity`', function test( t ) {
156147
var val = expf( PINF );
157-
t.equal( val, PINF, 'returns expected value' );
148+
t.strictEqual( val, PINF, 'returns expected value' );
158149
t.end();
159150
});
160151

161152
tape( 'the function returns `NaN` if provided a `NaN`', function test( t ) {
162153
var val = expf( NaN );
163-
t.equal( isnan( val ), true, 'returns expected value' );
154+
t.strictEqual( isnanf( val ), true, 'returns expected value' );
155+
t.end();
156+
});
157+
158+
tape( 'the function returns `1` if provided `+-0`', function test( t ) {
159+
var val;
160+
161+
val = expf( f32( -0.0 ) );
162+
t.strictEqual( val, f32( 1.0 ), 'returns expected value' );
163+
164+
val = expf( f32( +0.0 ) );
165+
t.strictEqual( val, f32( 1.0 ), 'returns expected value' );
166+
164167
t.end();
165168
});

0 commit comments

Comments
 (0)