Skip to content

Commit bd98a5e

Browse files
committed
feat: add tests
--- 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: passed - 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 8b8478c commit bd98a5e

File tree

7 files changed

+479
-0
lines changed

7 files changed

+479
-0
lines changed

lib/node_modules/@stdlib/stats/base/dists/bradford/cdf/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/cdf/test/fixtures/python/medium_c.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env python
2+
#
3+
# @license Apache-2.0
4+
#
5+
# Copyright (c) 2025 The Stdlib Authors.
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
19+
"""Generate fixtures."""
20+
21+
import os
22+
import json
23+
import numpy as np
24+
from scipy.stats import bradford
25+
26+
# Get the file path:
27+
FILE = os.path.realpath(__file__)
28+
29+
# Extract the directory in which this file resides:
30+
DIR = os.path.dirname(FILE)
31+
32+
33+
def gen(x, c, name):
34+
"""Generate fixture data and write to file.
35+
36+
# Arguments
37+
38+
* `x`: domain
39+
* `c`: domain
40+
* `name::str`: output filename
41+
42+
# Examples
43+
44+
``` python
45+
python> x = linspace(0, 1, 2001)
46+
python> c = linspace(0.1, 1000, 2001)
47+
python> gen(x, c, './data.json')
48+
```
49+
"""
50+
y = bradford.cdf(x, c)
51+
52+
# Store data to be written to file as a dictionary:
53+
data = {
54+
"x": x.tolist(),
55+
"c": c.tolist(),
56+
"expected": y.tolist()
57+
}
58+
59+
# Based on the script directory, create an output filepath:
60+
filepath = os.path.join(DIR, name)
61+
62+
# Write the data to the output filepath as JSON:
63+
with open(filepath, "w", encoding="utf-8") as outfile:
64+
json.dump(data, outfile)
65+
66+
67+
def main():
68+
"""Generate fixture data."""
69+
x = np.linspace(0, 1, 1000)
70+
71+
# Small shape parameter:
72+
c = np.linspace(0.1, 1, 1000)
73+
gen(x, c, "small_c.json")
74+
75+
# Medium shape parameter:
76+
c = np.linspace(1, 10, 1000)
77+
gen(x, c, "medium_c.json")
78+
79+
# Large shape parameter:
80+
c = np.linspace(10, 100, 1000)
81+
gen(x, c, "large_c.json")
82+
83+
84+
if __name__ == "__main__":
85+
main()

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

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
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 cdf = 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 cdf, '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 = cdf( NaN, 1.0 );
51+
t.equal( isnan( y ), true, 'returns expected value' );
52+
53+
y = cdf( 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 = cdf( 0.0, 0.0 );
63+
t.equal( isnan( y ), true, 'returns expected value' );
64+
65+
y = cdf( 0.5, -1.0 );
66+
t.equal( isnan( y ), true, 'returns expected value' );
67+
68+
y = cdf( 1.0, NINF );
69+
t.equal( isnan( y ), true, 'returns expected value' );
70+
71+
t.end();
72+
});
73+
74+
tape( 'if provided a `x` outside of `[0,1]`, the created function always returns `NaN`', function test( t ) {
75+
var y;
76+
77+
y = cdf( 2.0, 1.0 );
78+
t.equal( isnan( y ), true, 'returns expected value' );
79+
80+
y = cdf( -0.5, 1.0 );
81+
t.equal( isnan( y ), true, 'returns expected value' );
82+
83+
y = cdf( NINF, 1.0 );
84+
t.equal( isnan( y ), true, 'returns expected value' );
85+
86+
y = cdf( PINF, 1.0 );
87+
t.equal( isnan( y ), true, 'returns expected value' );
88+
89+
t.end();
90+
});
91+
92+
tape( 'the function evaluates the cdf for `x` given small parameter `c`', function test( t ) {
93+
var expected;
94+
var delta;
95+
var tol;
96+
var x;
97+
var c;
98+
var y;
99+
var i;
100+
101+
expected = smallC.expected;
102+
x = smallC.x;
103+
c = smallC.c;
104+
for ( i = 0; i < x.length; i++ ) {
105+
y = cdf( x[i], c[i] );
106+
if ( y === expected[i] ) {
107+
t.equal( y, expected[i], 'x: '+x[i]+'. c:'+c[i]+', y: '+y+', expected: '+expected[i] );
108+
} else {
109+
delta = abs( y - expected[ i ] );
110+
tol = 3.0 * EPS * abs( expected[ i ] );
111+
t.ok( delta <= tol, 'within tolerance. x: '+x[ 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 cdf for `x` given medium parameter `c`', function test( t ) {
118+
var expected;
119+
var delta;
120+
var tol;
121+
var x;
122+
var c;
123+
var y;
124+
var i;
125+
126+
expected = mediumC.expected;
127+
x = mediumC.x;
128+
c = mediumC.c;
129+
for ( i = 0; i < x.length; i++ ) {
130+
y = cdf( x[i], c[i] );
131+
if ( y === expected[i] ) {
132+
t.equal( y, expected[i], 'x: '+x[i]+'. c:'+c[i]+', y: '+y+', expected: '+expected[i] );
133+
} else {
134+
delta = abs( y - expected[ i ] );
135+
tol = 2.2 * EPS * abs( expected[ i ] );
136+
t.ok( delta <= tol, 'within tolerance. x: '+x[ 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 cdf for `x` given large parameter `c`', function test( t ) {
143+
var expected;
144+
var delta;
145+
var tol;
146+
var x;
147+
var c;
148+
var y;
149+
var i;
150+
151+
expected = largeC.expected;
152+
x = largeC.x;
153+
c = largeC.c;
154+
for ( i = 0; i < x.length; i++ ) {
155+
y = cdf( x[i], c[i] );
156+
if ( y === expected[i] ) {
157+
t.equal( y, expected[i], 'x: '+x[i]+'. c: '+c[i]+', y: '+y+', expected: '+expected[i] );
158+
} else {
159+
delta = abs( y - expected[ i ] );
160+
tol = 1.9 * EPS * abs( expected[ i ] );
161+
t.ok( delta <= tol, 'within tolerance. x: '+x[ i ]+'. c: '+c[i]+'. y: '+y+'. E: '+expected[ i ]+'. Δ: '+delta+'. tol: '+tol+'.' );
162+
}
163+
}
164+
t.end();
165+
});

0 commit comments

Comments
 (0)