Skip to content

Commit 939170f

Browse files
PlaneshifterNeerajpathak07
authored andcommitted
refactor: explicitly return zero for non-integer x
--- 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: passed - 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 --- --- 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: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: passed ---
1 parent 8fc9eb6 commit 939170f

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

lib/node_modules/@stdlib/stats/base/dists/signrank/pdf/lib/factory.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
var isPositiveInteger = require( '@stdlib/math/base/assert/is-positive-integer' );
2424
var constantFunction = require( '@stdlib/utils/constant-function' );
25+
var isInteger = require( '@stdlib/math/base/assert/is-integer' );
2526
var isfinite = require( '@stdlib/math/base/assert/is-finite' );
2627
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2728
var exp = require( '@stdlib/math/base/special/exp' );
@@ -69,6 +70,9 @@ function factory( n ) {
6970
if ( isnan( x ) ) {
7071
return NaN;
7172
}
73+
if ( !isInteger( x ) ) {
74+
return 0.0;
75+
}
7276
if ( x < 0.0 || x > mlim ) {
7377
return 0.0;
7478
}

lib/node_modules/@stdlib/stats/base/dists/signrank/pdf/lib/main.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
// MODULES //
2222

2323
var isPositiveInteger = require( '@stdlib/math/base/assert/is-positive-integer' );
24+
var isInteger = require( '@stdlib/math/base/assert/is-integer' );
2425
var isfinite = require( '@stdlib/math/base/assert/is-finite' );
2526
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2627
var exp = require( '@stdlib/math/base/special/exp' );
@@ -75,6 +76,9 @@ function pdf( x, n ) {
7576
) {
7677
return NaN;
7778
}
79+
if ( !isInteger( x ) ) {
80+
return 0.0;
81+
}
7882
mlim = ( n * ( n + 1 ) ) / 2;
7983
if ( x < 0.0 || x > mlim ) {
8084
return 0.0;

lib/node_modules/@stdlib/stats/base/dists/signrank/pdf/test/test.factory.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,20 @@ tape( 'if not provided a positive integer for `n`, the created function always r
107107
t.end();
108108
});
109109

110+
tape( 'the created function returns `0` if provided a non-integer for `x`', function test( t ) {
111+
var pdf = factory( 8 );
112+
var y = pdf( 1.5 );
113+
t.equal( y, 0.0, 'returns expected value' );
114+
115+
y = pdf( 2.5 );
116+
t.equal( y, 0.0, 'returns expected value' );
117+
118+
y = pdf( 0.1 );
119+
t.equal( y, 0.0, 'returns expected value' );
120+
121+
t.end();
122+
});
123+
110124
tape( 'the created function evaluates the PDF for `x` given `n` observations', function test( t ) {
111125
var expected;
112126
var delta;

lib/node_modules/@stdlib/stats/base/dists/signrank/pdf/test/test.pdf.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,18 @@ tape( 'if not provided a positive integer for `n`, the function returns `NaN`',
8080
t.end();
8181
});
8282

83+
tape( 'the function returns `0` if provided a non-integer for `x`', function test( t ) {
84+
var y = pdf( 1.5, 8 );
85+
t.equal( y, 0.0, 'returns expected value' );
86+
t.end();
87+
88+
y = pdf( 2.5, 8 );
89+
t.equal( y, 0.0, 'returns expected value' );
90+
91+
y = pdf( 0.1, 4 );
92+
t.equal( y, 0.0, 'returns expected value' );
93+
});
94+
8395
tape( 'the function evaluates the PDF for `x` given `n` observations', function test( t ) {
8496
var expected;
8597
var delta;

0 commit comments

Comments
 (0)