Skip to content

Commit 52c1a89

Browse files
committed
feat: add tests and their fixtures
--- 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 d01466d commit 52c1a89

File tree

6 files changed

+394
-0
lines changed

6 files changed

+394
-0
lines changed

lib/node_modules/@stdlib/stats/base/dists/bradford/quantile/test/fixtures/python/large_c.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

lib/node_modules/@stdlib/stats/base/dists/bradford/quantile/test/fixtures/python/medium_c.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

lib/node_modules/@stdlib/stats/base/dists/bradford/quantile/test/fixtures/python/small_c.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
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 isnan = require( '@stdlib/math/base/assert/is-nan' );
25+
var abs = require( '@stdlib/math/base/special/abs' );
26+
var EPS = require( '@stdlib/constants/float64/eps' );
27+
var factory = require( './../lib/factory.js' );
28+
29+
30+
// FIXTURES //
31+
32+
var smallC = require( './fixtures/python/small_c.json' );
33+
var mediumC = require( './fixtures/python/medium_c.json' );
34+
var largeC = require( './fixtures/python/large_c.json' );
35+
36+
37+
// TESTS //
38+
39+
tape( 'main export is a function', function test( t ) {
40+
t.ok( true, __filename );
41+
t.strictEqual( typeof factory, 'function', 'main export is a function' );
42+
t.end();
43+
});
44+
45+
tape( 'the function returns a function', function test( t ) {
46+
var quantile = factory( 1.0 );
47+
t.equal( typeof quantile, 'function', 'returns a function' );
48+
t.end();
49+
});
50+
51+
tape( 'if provided `NaN` for any parameter, the created function returns `NaN`', function test( t ) {
52+
var quantile;
53+
var y;
54+
55+
quantile = factory( 1.0 );
56+
y = quantile( NaN );
57+
t.equal( isnan( y ), true, 'returns expected value' );
58+
59+
quantile = factory( NaN );
60+
y = quantile( 0.0 );
61+
t.equal( isnan( y ), true, 'returns expected value' );
62+
63+
quantile = factory( NaN );
64+
y = quantile( NaN );
65+
t.equal( isnan( y ), true, 'returns expected value' );
66+
67+
t.end();
68+
});
69+
70+
tape( 'if provided `c <= 0`, the created function always returns `NaN`', function test( t ) {
71+
var quantile;
72+
var y;
73+
74+
quantile = factory( -1.0 );
75+
76+
y = quantile( 1.0 );
77+
t.equal( isnan( y ), true, 'returns expected value' );
78+
79+
y = quantile( 0.5 );
80+
t.equal( isnan( y ), true, 'returns expected value' );
81+
82+
y = quantile( 0.0 );
83+
t.equal( isnan( y ), true, 'returns expected value' );
84+
85+
t.end();
86+
});
87+
88+
tape( 'if provided a finite `c`, the function returns a function which returns `NaN` when provided a number outside `[0,1]` for `p`', function test( t ) {
89+
var quantile;
90+
var y;
91+
92+
quantile = factory( 1.0 );
93+
94+
y = quantile( -1.0 );
95+
t.equal( isnan( y ), true, 'returns expected value' );
96+
97+
y = quantile( -0.5 );
98+
t.equal( isnan( y ), true, 'returns expected value' );
99+
100+
y = quantile( 1.5 );
101+
t.equal( isnan( y ), true, 'returns expected value' );
102+
103+
y = quantile( 10.0 );
104+
t.equal( isnan( y ), true, 'returns expected value' );
105+
106+
t.end();
107+
});
108+
109+
tape( 'the created function evaluates the quantile for `x` given small `c`', function test( t ) {
110+
var expected;
111+
var quantile;
112+
var delta;
113+
var tol;
114+
var c;
115+
var i;
116+
var p;
117+
var y;
118+
119+
expected = smallC.expected;
120+
p = smallC.p;
121+
c = smallC.c;
122+
for ( i = 0; i < expected.length; i++ ) {
123+
quantile = factory( c[i] );
124+
y = quantile( p[i] );
125+
if ( y === expected[i] ) {
126+
t.equal( y, expected[i], 'p: '+p[i]+'. c: '+c[i]+', y: '+y+', expected: '+expected[i] );
127+
} else {
128+
delta = abs( y - expected[ i ] );
129+
tol = 3.2 * EPS * abs( expected[ i ] );
130+
t.ok( delta <= tol, 'within tolerance. p: '+p[ i ]+'. c: '+c[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
131+
}
132+
}
133+
t.end();
134+
});
135+
136+
tape( 'the created function evaluates the quantile for `x` given a medium `c`', function test( t ) {
137+
var expected;
138+
var quantile;
139+
var delta;
140+
var tol;
141+
var c;
142+
var i;
143+
var p;
144+
var y;
145+
146+
expected = mediumC.expected;
147+
p = mediumC.p;
148+
c = mediumC.c;
149+
for ( i = 0; i < expected.length; i++ ) {
150+
quantile = factory( c[i] );
151+
y = quantile( p[i] );
152+
if ( y === expected[i] ) {
153+
t.equal( y, expected[i], 'p: '+p[i]+'. c: '+c[i]+', y: '+y+', expected: '+expected[i] );
154+
} else {
155+
delta = abs( y - expected[ i ] );
156+
tol = 3.2 * EPS * abs( expected[ i ] );
157+
t.ok( delta <= tol, 'within tolerance. p: '+p[ i ]+'. c: '+c[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
158+
}
159+
}
160+
t.end();
161+
});
162+
163+
tape( 'the created function evaluates the quantile for `x` given a large `c`', function test( t ) {
164+
var expected;
165+
var quantile;
166+
var delta;
167+
var tol;
168+
var c;
169+
var i;
170+
var p;
171+
var y;
172+
173+
expected = largeC.expected;
174+
p = largeC.p;
175+
c = largeC.c;
176+
for ( i = 0; i < expected.length; i++ ) {
177+
quantile = factory( c[i] );
178+
y = quantile( p[i] );
179+
if ( y === expected[i] ) {
180+
t.equal( y, expected[i], 'p: '+p[i]+'. c: '+c[i]+', y: '+y+', expected: '+expected[i] );
181+
} else {
182+
delta = abs( y - expected[ i ] );
183+
tol = 4.8 * EPS * abs( expected[ i ] );
184+
t.ok( delta <= tol, 'within tolerance. p: '+p[ i ]+'. c: '+c[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
185+
}
186+
}
187+
t.end();
188+
});
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 quantile = require( './../lib' );
25+
26+
27+
// TESTS //
28+
29+
tape( 'main export is a function', function test( t ) {
30+
t.ok( true, __filename );
31+
t.strictEqual( typeof quantile, 'function', 'main export is a function' );
32+
t.end();
33+
});
34+
35+
tape( 'attached to the main export is a factory method for generating `quantile` functions', function test( t ) {
36+
t.equal( typeof quantile.factory, 'function', 'exports a factory method' );
37+
t.end();
38+
});
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
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 isnan = require( '@stdlib/math/base/assert/is-nan' );
25+
var abs = require( '@stdlib/math/base/special/abs' );
26+
var PINF = require( '@stdlib/constants/float64/pinf' );
27+
var NINF = require( '@stdlib/constants/float64/ninf' );
28+
var EPS = require( '@stdlib/constants/float64/eps' );
29+
var quantile = require( './../lib' );
30+
31+
32+
// FIXTURES //
33+
34+
var smallC = require( './fixtures/python/small_c.json' );
35+
var mediumC = require( './fixtures/python/medium_c.json' );
36+
var largeC = require( './fixtures/python/large_c.json' );
37+
38+
39+
// TESTS //
40+
41+
tape( 'main export is a function', function test( t ) {
42+
t.ok( true, __filename );
43+
t.strictEqual( typeof quantile, 'function', 'main export is a function' );
44+
t.end();
45+
});
46+
47+
tape( 'if provided `NaN` for any parameter, the function returns `NaN`', function test( t ) {
48+
var y;
49+
50+
y = quantile( NaN, 1.0 );
51+
t.equal( isnan( y ), true, 'returns expected value' );
52+
53+
y = quantile( 0.0, NaN );
54+
t.equal( isnan( y ), true, 'returns expected value' );
55+
56+
t.end();
57+
});
58+
59+
tape( 'if provided `c <= 0`, the function returns `NaN`', function test( t ) {
60+
var y;
61+
62+
y = quantile( 0.0, 0.0 );
63+
t.equal( isnan( y ), true, 'returns expected value' );
64+
65+
y = quantile( 0.5, -1.0 );
66+
t.equal( isnan( y ), true, 'returns expected value' );
67+
68+
y = quantile( 1.0, NINF );
69+
t.equal( isnan( y ), true, 'returns expected value' );
70+
71+
t.end();
72+
});
73+
74+
tape( 'if provided a number outside `[0,1]` for `p` and a valid `c`, the function returns `NaN`', function test( t ) {
75+
var y;
76+
77+
y = quantile( 2.0, 1.0 );
78+
t.equal( isnan( y ), true, 'returns expected value' );
79+
80+
y = quantile( -0.5, 1.0 );
81+
t.equal( isnan( y ), true, 'returns expected value' );
82+
83+
y = quantile( NINF, 1.0 );
84+
t.equal( isnan( y ), true, 'returns expected value' );
85+
86+
y = quantile( PINF, 1.0 );
87+
t.equal( isnan( y ), true, 'returns expected value' );
88+
89+
t.end();
90+
});
91+
92+
tape( 'the function evaluates the quantile for `p` given small parameter `c`', function test( t ) {
93+
var expected;
94+
var delta;
95+
var tol;
96+
var p;
97+
var c;
98+
var y;
99+
var i;
100+
101+
expected = smallC.expected;
102+
p = smallC.p;
103+
c = smallC.c;
104+
for ( i = 0; i < p.length; i++ ) {
105+
y = quantile( p[i], c[i] );
106+
if ( y === expected[i] ) {
107+
t.equal( y, expected[i], 'p: '+p[i]+'. c:'+c[i]+', y: '+y+', expected: '+expected[i] );
108+
} else {
109+
delta = abs( y - expected[ i ] );
110+
tol = 3.2 * EPS * abs( expected[ i ] );
111+
t.ok( delta <= tol, 'within tolerance. p: '+p[ i ]+'. c: '+c[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
112+
}
113+
}
114+
t.end();
115+
});
116+
117+
tape( 'the function evaluates the quantile for `p` given medium parameter `c`', function test( t ) {
118+
var expected;
119+
var delta;
120+
var tol;
121+
var p;
122+
var c;
123+
var y;
124+
var i;
125+
126+
expected = mediumC.expected;
127+
p = mediumC.p;
128+
c = mediumC.c;
129+
for ( i = 0; i < p.length; i++ ) {
130+
y = quantile( p[i], c[i] );
131+
if ( y === expected[i] ) {
132+
t.equal( y, expected[i], 'p: '+p[i]+'. c:'+c[i]+', y: '+y+', expected: '+expected[i] );
133+
} else {
134+
delta = abs( y - expected[ i ] );
135+
tol = 3.2 * EPS * abs( expected[ i ] );
136+
t.ok( delta <= tol, 'within tolerance. p: '+p[ i ]+'. c: '+c[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
137+
}
138+
}
139+
t.end();
140+
});
141+
142+
tape( 'the function evaluates the quantile for `p` given large parameter `c`', function test( t ) {
143+
var expected;
144+
var delta;
145+
var tol;
146+
var p;
147+
var c;
148+
var y;
149+
var i;
150+
151+
expected = largeC.expected;
152+
p = largeC.p;
153+
c = largeC.c;
154+
for ( i = 0; i < p.length; i++ ) {
155+
y = quantile( p[i], c[i] );
156+
if ( y === expected[i] ) {
157+
t.equal( y, expected[i], 'p: '+p[i]+'. c: '+c[i]+', y: '+y+', expected: '+expected[i] );
158+
} else {
159+
delta = abs( y - expected[ i ] );
160+
tol = 4.8 * EPS * abs( expected[ i ] );
161+
t.ok( delta <= tol, 'within tolerance. p: '+p[ i ]+'. c: '+c[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
162+
}
163+
}
164+
t.end();
165+
});

0 commit comments

Comments
 (0)