Skip to content

Commit 3a31534

Browse files
committed
test: add test.main.js to cover native fallback
1 parent 24e970e commit 3a31534

2 files changed

Lines changed: 104 additions & 2 deletions

File tree

lib/node_modules/@stdlib/stats/base/dists/chi/skewness/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@
3434
"bugs": {
3535
"url": "https://github.com/stdlib-js/stdlib/issues"
3636
},
37-
"dependencies": {},
38-
"devDependencies": {},
37+
"devDependencies": {
38+
"proxyquire": "^2.1.3"
39+
},
3940
"engines": {
4041
"node": ">=0.10.0",
4142
"npm": ">2.7.0"
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var tape = require( 'tape' );
24+
var proxyquire = require( 'proxyquire' );
25+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var abs = require( '@stdlib/math/base/special/abs' );
27+
var NINF = require( '@stdlib/constants/float64/ninf' );
28+
29+
30+
// FIXTURES //
31+
32+
var data = require( './fixtures/julia/data.json' );
33+
34+
35+
// TESTS //
36+
37+
tape( 'main export is a function (pure JavaScript fallback)', function test( t ) {
38+
var skewness = proxyquire( './../lib/index.js', {
39+
'./native.js': new Error( 'Addon not found' )
40+
});
41+
42+
t.ok( true, __filename );
43+
t.strictEqual( typeof skewness, 'function', 'main export is a function' );
44+
t.end();
45+
});
46+
47+
tape( 'if provided `NaN` for `k`, the function returns `NaN` (pure JavaScript fallback)', function test( t ) {
48+
var skewness = proxyquire( './../lib/index.js', {
49+
'./native.js': new Error( 'Addon not found' )
50+
});
51+
52+
var v = skewness( NaN );
53+
t.strictEqual( isnan( v ), true, 'returns expected value' );
54+
t.end();
55+
});
56+
57+
tape( 'if provided a degrees of freedom parameter `k` that is not a positive number, the function returns `NaN` (pure JavaScript fallback)', function test( t ) {
58+
var skewness = proxyquire( './../lib/index.js', {
59+
'./native.js': new Error( 'Addon not found' )
60+
});
61+
62+
var v;
63+
64+
v = skewness( -1.0 );
65+
t.strictEqual( isnan( v ), true, 'returns expected value' );
66+
67+
v = skewness( 0.0 );
68+
t.strictEqual( isnan( v ), true, 'returns expected value' );
69+
70+
v = skewness( NINF );
71+
t.strictEqual( isnan( v ), true, 'returns expected value' );
72+
73+
t.end();
74+
});
75+
76+
tape( 'the function returns the skewness of a chi distribution (pure JavaScript fallback)', function test( t ) {
77+
var skewness = proxyquire( './../lib/index.js', {
78+
'./native.js': new Error( 'Addon not found' )
79+
});
80+
81+
var expected;
82+
var delta;
83+
var tol;
84+
var k;
85+
var i;
86+
var y;
87+
88+
expected = data.expected;
89+
k = data.k;
90+
for ( i = 0; i < expected.length; i++ ) {
91+
y = skewness( k[i] );
92+
if ( y === expected[i] ) {
93+
t.strictEqual( y, expected[i], 'k:'+k[i]+', y: '+y+', expected: '+expected[i] );
94+
} else {
95+
delta = abs( y - expected[ i ] );
96+
tol = 1e-11 * abs( expected[ i ] );
97+
t.ok( delta <= tol, 'within tolerance. k: '+k[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
98+
}
99+
}
100+
t.end();
101+
});

0 commit comments

Comments
 (0)