Skip to content

Commit b826bd5

Browse files
committed
feat:added test files
--- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: failed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: failed ---
1 parent f3d811f commit b826bd5

File tree

3 files changed

+206
-0
lines changed

3 files changed

+206
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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 bench = require( '@stdlib/bench' );
24+
var randu = require( '@stdlib/random/base/randu' );
25+
var randint = require( '@stdlib/random/base/discrete-uniform' );
26+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
27+
var pkg = require( './../package.json' ).name;
28+
var addon = require( './../src/addon.node' );
29+
30+
31+
// MAIN //
32+
33+
bench( pkg+':native', function benchmark( b ) {
34+
var n;
35+
var p;
36+
var y;
37+
var i;
38+
39+
b.tic();
40+
for ( i = 0; i < b.iterations; i++ ) {
41+
p = randu();
42+
n = randint( 1, 200 );
43+
y = addon( p, n );
44+
if ( isnan( y ) ) {
45+
b.fail( 'should not return NaN' );
46+
}
47+
}
48+
b.toc();
49+
if ( isnan( y ) ) {
50+
b.fail( 'should not return NaN' );
51+
}
52+
b.pass( 'benchmark finished' );
53+
b.end();
54+
});
55+
56+
bench( pkg+':native:factory', function benchmark( b ) {
57+
var myquantile;
58+
var n;
59+
var p;
60+
var y;
61+
var i;
62+
63+
n = 8;
64+
myquantile = addon.factory( n );
65+
66+
b.tic();
67+
for ( i = 0; i < b.iterations; i++ ) {
68+
p = randu();
69+
y = myquantile( p );
70+
if ( isnan( y ) ) {
71+
b.fail( 'should not return NaN' );
72+
}
73+
}
74+
b.toc();
75+
if ( isnan( y ) ) {
76+
b.fail( 'should not return NaN' );
77+
}
78+
b.pass( 'benchmark finished' );
79+
b.end();
80+
});
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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 addon = require( './../src/addon.node' );
24+
25+
26+
// MAIN //
27+
28+
/**
29+
* Evaluates the quantile function for the Wilcoxon signed rank test statistic with `n` observations at a given probability `p`.
30+
*
31+
* @private
32+
* @param {number} p - input probability
33+
* @param {PositiveInteger} n - number of observations
34+
* @returns {number} evaluated quantile
35+
*
36+
* @example
37+
* var v = quantile( 0.5, 5 );
38+
* // returns 11
39+
*
40+
* @example
41+
* var v = quantile( 0.9, 7 );
42+
* // returns ~21
43+
*
44+
* @example
45+
* var v = quantile( NaN, 10 );
46+
* // returns NaN
47+
*/
48+
function quantile( p, n ) {
49+
return addon( p, n );
50+
}
51+
52+
53+
// EXPORTS //
54+
55+
module.exports = quantile;
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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 addon = require( './../src/addon.node' );
25+
26+
// TESTS //
27+
28+
tape( 'main export is a function', function test( t ) {
29+
t.ok( true, __filename );
30+
t.strictEqual( typeof addon, 'function', 'main export is a function' );
31+
t.end();
32+
});
33+
34+
tape( 'the function returns expected quantiles for valid inputs', function test( t ) {
35+
var probabilities = [ 0.1, 0.25, 0.5, 0.75, 0.9 ];
36+
var sampleSizes = [ 3, 5, 7, 10 ];
37+
var expected;
38+
var actual;
39+
var p;
40+
var n;
41+
var i;
42+
var j;
43+
44+
for ( i = 0; i < sampleSizes.length; i++ ) {
45+
n = sampleSizes[ i ];
46+
for ( j = 0; j < probabilities.length; j++ ) {
47+
p = probabilities[ j ];
48+
actual = addon( p, n );
49+
50+
// Compute expected value based on known results or formula (placeholder logic here):
51+
expected /* Insert logic or precomputed values */;
52+
t.strictEqual( actual, expected, 'returns '+expected+' for p: '+p+', n: '+n );
53+
}
54+
}
55+
t.end();
56+
});
57+
58+
tape( 'the function returns NaN for invalid inputs', function test( t ) {
59+
var invalidProbabilities = [ -0.1, 1.1, NaN ];
60+
var invalidSampleSizes = [ -5, 0, 3.5, NaN ];
61+
var i;
62+
63+
for ( i = 0; i < invalidProbabilities.length; i++ ) {
64+
t.ok( isNaN( addon( invalidProbabilities[ i ], 5 ) ), 'returns NaN for invalid probability: '+invalidProbabilities[ i ] );
65+
}
66+
67+
for ( i = 0; i < invalidSampleSizes.length; i++ ) {
68+
t.ok( isNaN( addon( 0.5, invalidSampleSizes[ i ] ) ), 'returns NaN for invalid sample size: '+invalidSampleSizes[ i ] );
69+
}
70+
t.end();
71+
});

0 commit comments

Comments
 (0)