Skip to content

Commit 797e2e1

Browse files
committed
chore: clean-up and update 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: na - task: lint_r status: na - task: lint_c_src status: passed - 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 7e5c88b commit 797e2e1

File tree

6 files changed

+78
-64
lines changed

6 files changed

+78
-64
lines changed

lib/node_modules/@stdlib/stats/base/dists/gamma/logcdf/benchmark/c/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,3 @@ clean:
144144
$(QUIET) -rm -f *.o *.out
145145

146146
.PHONY: clean
147-

lib/node_modules/@stdlib/stats/base/dists/gamma/logcdf/src/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,3 @@ clean-addon:
6868
clean: clean-addon
6969

7070
.PHONY: clean
71-

lib/node_modules/@stdlib/stats/base/dists/gamma/logcdf/src/addon.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,3 @@
2020
#include "stdlib/math/base/napi/ternary.h"
2121

2222
STDLIB_MATH_BASE_NAPI_MODULE_DDD_D( stdlib_base_dists_gamma_logcdf )
23-

lib/node_modules/@stdlib/stats/base/dists/gamma/logcdf/src/main.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,3 @@
3535
double stdlib_base_dists_gamma_logcdf( const double x, const double alpha, const double beta ) {
3636
return stdlib_base_ln( stdlib_base_dists_gamma_cdf( x, alpha, beta ) );
3737
}
38-

lib/node_modules/@stdlib/stats/base/dists/gamma/logcdf/test/test.logcdf.js

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
var tape = require( 'tape' );
2424
var isnan = require( '@stdlib/math/base/assert/is-nan' );
25-
var randu = require( '@stdlib/random/base/randu' );
25+
var uniform = require( '@stdlib/random/base/uniform' );
2626
var PINF = require( '@stdlib/constants/float64/pinf' );
2727
var NINF = require( '@stdlib/constants/float64/ninf' );
2828
var EPS = require( '@stdlib/constants/float64/eps' );
@@ -40,47 +40,52 @@ tape( 'main export is a function', function test( t ) {
4040
});
4141

4242
tape( 'if provided `NaN` for any parameter, the function returns `NaN`', function test( t ) {
43-
var y = logcdf( NaN, 1.0, 1.0 );
44-
t.equal( isnan( y ), true, 'returns NaN' );
43+
var y;
44+
45+
y = logcdf( NaN, 1.0, 1.0 );
46+
t.equal( isnan( y ), true, 'returns expected value' );
47+
4548
y = logcdf( 0.0, NaN, 1.0 );
46-
t.equal( isnan( y ), true, 'returns NaN' );
49+
t.equal( isnan( y ), true, 'returns expected value' );
50+
4751
y = logcdf( 0.0, 1.0, NaN );
48-
t.equal( isnan( y ), true, 'returns NaN' );
52+
t.equal( isnan( y ), true, 'returns expected value' );
53+
4954
t.end();
5055
});
5156

5257
tape( 'if provided `+infinity` for `x` and a finite `alpha` and `beta`, the function returns `1`', function test( t ) {
5358
var y = logcdf( PINF, 0.5, 1.0 );
54-
t.equal( y, 0.0, 'returns 0' );
59+
t.equal( y, 0.0, 'returns expected value' );
5560
t.end();
5661
});
5762

5863
tape( 'if provided `-infinity` for `x` and a finite `alpha` and `beta`, the function returns `0`', function test( t ) {
5964
var y = logcdf( NINF, 0.5, 1.0 );
60-
t.equal( y, NINF, 'returns -Infinity' );
65+
t.equal( y, NINF, 'returns expected value' );
6166
t.end();
6267
});
6368

6469
tape( 'if provided `alpha < 0`, the function returns `NaN`', function test( t ) {
6570
var y;
6671

6772
y = logcdf( 2.0, -1.0, 2.0 );
68-
t.equal( isnan( y ), true, 'returns NaN' );
73+
t.equal( isnan( y ), true, 'returns expected value' );
6974

7075
y = logcdf( 0.0, -1.0, 2.0 );
71-
t.equal( isnan( y ), true, 'returns NaN' );
76+
t.equal( isnan( y ), true, 'returns expected value' );
7277

7378
y = logcdf( 2.0, NINF, 1.0 );
74-
t.equal( isnan( y ), true, 'returns NaN' );
79+
t.equal( isnan( y ), true, 'returns expected value' );
7580

7681
y = logcdf( 2.0, NINF, PINF );
77-
t.equal( isnan( y ), true, 'returns NaN' );
82+
t.equal( isnan( y ), true, 'returns expected value' );
7883

7984
y = logcdf( 2.0, NINF, NINF );
80-
t.equal( isnan( y ), true, 'returns NaN' );
85+
t.equal( isnan( y ), true, 'returns expected value' );
8186

8287
y = logcdf( 2.0, NINF, NaN );
83-
t.equal( isnan( y ), true, 'returns NaN' );
88+
t.equal( isnan( y ), true, 'returns expected value' );
8489

8590
t.end();
8691
});
@@ -89,25 +94,25 @@ tape( 'if provided `beta <= 0`, the function returns `NaN`', function test( t )
8994
var y;
9095

9196
y = logcdf( 2.0, 2.0, 0.0 );
92-
t.equal( isnan( y ), true, 'returns NaN' );
97+
t.equal( isnan( y ), true, 'returns expected value' );
9398

9499
y = logcdf( 2.0, 2.0, -1.0 );
95-
t.equal( isnan( y ), true, 'returns NaN' );
100+
t.equal( isnan( y ), true, 'returns expected value' );
96101

97102
y = logcdf( 0.0, 2.0, -1.0 );
98-
t.equal( isnan( y ), true, 'returns NaN' );
103+
t.equal( isnan( y ), true, 'returns expected value' );
99104

100105
y = logcdf( 2.0, 1.0, NINF );
101-
t.equal( isnan( y ), true, 'returns NaN' );
106+
t.equal( isnan( y ), true, 'returns expected value' );
102107

103108
y = logcdf( 2.0, PINF, NINF );
104-
t.equal( isnan( y ), true, 'returns NaN' );
109+
t.equal( isnan( y ), true, 'returns expected value' );
105110

106111
y = logcdf( 2.0, NINF, NINF );
107-
t.equal( isnan( y ), true, 'returns NaN' );
112+
t.equal( isnan( y ), true, 'returns expected value' );
108113

109114
y = logcdf( 2.0, NaN, NINF );
110-
t.equal( isnan( y ), true, 'returns NaN' );
115+
t.equal( isnan( y ), true, 'returns expected value' );
111116

112117
t.end();
113118
});
@@ -116,22 +121,22 @@ tape( 'if provided an `alpha` equal to `0` and `beta` is positive, the function
116121
var y;
117122

118123
y = logcdf( PINF, 0.0, 2.0 );
119-
t.equal( y, 0.0, 'returns 0 for x greater than 0' );
124+
t.equal( y, 0.0, 'returns expected value' );
120125

121126
y = logcdf( 2.5, 0.0, 2.0 );
122-
t.equal( y, 0.0, 'returns 0 for x greater than 0' );
127+
t.equal( y, 0.0, 'returns expected value' );
123128

124129
y = logcdf( 0.0, 0.0, 2.0 );
125-
t.equal( y, 0.0, 'returns 0 for x equal to 0' );
130+
t.equal( y, 0.0, 'returns expected value' );
126131

127132
y = logcdf( -2.0, 0.0, 2.0 );
128-
t.equal( y, NINF, 'returns -Infinity for x smaller than 0' );
133+
t.equal( y, NINF, 'returns expected value' );
129134

130135
y = logcdf( NINF, 0.0, 2.0 );
131-
t.equal( y, NINF, 'returns -Infinity for x smaller than 0' );
136+
t.equal( y, NINF, 'returns expected value' );
132137

133138
y = logcdf( NaN, 0.0, 2.0 );
134-
t.equal( isnan( y ), true, 'returns NaN' );
139+
t.equal( isnan( y ), true, 'returns expected value' );
135140

136141
t.end();
137142
});
@@ -145,9 +150,9 @@ tape( 'the function evaluates the logarithm of the CDF', function test( t ) {
145150
var y;
146151

147152
for ( i = 0; i < 1000; i++ ) {
148-
x = ( randu()*10.0 ) + EPS;
149-
alpha = ( randu()*10.0 ) + EPS;
150-
beta = ( randu()*10.0 ) + EPS;
153+
x = uniform( EPS, 10.0 );
154+
alpha = uniform( EPS, 10.0 );
155+
beta = uniform( EPS, 10.0 );
151156
y = logcdf( x, alpha, beta );
152157
expected = ln( cdf( x, alpha, beta ) );
153158
t.equal( y, expected, 'x: '+x+', alpha: '+alpha+', beta: '+beta+', y: '+y+', expected: '+expected );

lib/node_modules/@stdlib/stats/base/dists/gamma/logcdf/test/test.native.js

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222

2323
var resolve = require( 'path' ).resolve;
2424
var tape = require( 'tape' );
25-
var abs = require( '@stdlib/math/base/special/abs' );
2625
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2726
var tryRequire = require( '@stdlib/utils/try-require' );
2827
var PINF = require( '@stdlib/constants/float64/pinf' );
2928
var NINF = require( '@stdlib/constants/float64/ninf' );
3029
var EPS = require( '@stdlib/constants/float64/eps' );
31-
var randu = require( '@stdlib/random/base/randu' );
30+
var abs = require( '@stdlib/math/base/special/abs' );
31+
var uniform = require( '@stdlib/random/base/uniform' );
3232
var ln = require( '@stdlib/math/base/special/ln' );
3333
var cdf = require( '@stdlib/stats/base/dists/gamma/cdf' );
3434

@@ -53,64 +53,76 @@ tape( 'if provided `NaN` for any parameter, the function returns `NaN`', opts, f
5353
var y;
5454

5555
y = logcdf( NaN, 1.0, 1.0 );
56-
t.equal( isnan( y ), true, 'returns NaN' );
56+
t.equal( isnan( y ), true, 'returns expected value' );
5757

5858
y = logcdf( 0.0, NaN, 1.0 );
59-
t.equal( isnan( y ), true, 'returns NaN' );
59+
t.equal( isnan( y ), true, 'returns expected value' );
6060

6161
y = logcdf( 0.0, 1.0, NaN );
62-
t.equal( isnan( y ), true, 'returns NaN' );
62+
t.equal( isnan( y ), true, 'returns expected value' );
63+
64+
t.end();
65+
});
6366

67+
tape( 'if provided `+infinity` for `x` and a finite `alpha` and `beta`, the function returns `1`', opts, function test( t ) {
68+
var y = logcdf( PINF, 0.5, 1.0 );
69+
t.equal( y, 0.0, 'returns expected value' );
6470
t.end();
6571
});
6672

67-
tape( 'if provided a negative `alpha`, the function returns `NaN`', opts, function test( t ) {
73+
tape( 'if provided `-infinity` for `x` and a finite `alpha` and `beta`, the function returns `0`', opts, function test( t ) {
74+
var y = logcdf( NINF, 0.5, 1.0 );
75+
t.equal( y, NINF, 'returns expected value' );
76+
t.end();
77+
});
78+
79+
tape( 'if provided `alpha < 0`, the function returns `NaN`', opts, function test( t ) {
6880
var y;
6981

7082
y = logcdf( 2.0, -1.0, 2.0 );
71-
t.equal( isnan( y ), true, 'returns NaN' );
83+
t.equal( isnan( y ), true, 'returns expected value' );
7284

7385
y = logcdf( 0.0, -1.0, 2.0 );
74-
t.equal( isnan( y ), true, 'returns NaN' );
86+
t.equal( isnan( y ), true, 'returns expected value' );
7587

7688
y = logcdf( 2.0, NINF, 1.0 );
77-
t.equal( isnan( y ), true, 'returns NaN' );
89+
t.equal( isnan( y ), true, 'returns expected value' );
7890

7991
y = logcdf( 2.0, NINF, PINF );
80-
t.equal( isnan( y ), true, 'returns NaN' );
92+
t.equal( isnan( y ), true, 'returns expected value' );
8193

8294
y = logcdf( 2.0, NINF, NINF );
83-
t.equal( isnan( y ), true, 'returns NaN' );
95+
t.equal( isnan( y ), true, 'returns expected value' );
8496

8597
y = logcdf( 2.0, NINF, NaN );
86-
t.equal( isnan( y ), true, 'returns NaN' );
98+
t.equal( isnan( y ), true, 'returns expected value' );
8799

88100
t.end();
89101
});
90102

91-
tape( 'if provided a nonpositive `beta`, the function returns `NaN`', opts, function test( t ) {
103+
tape( 'if provided `beta <= 0`, the function returns `NaN`', opts, function test( t ) {
92104
var y;
93105

94106
y = logcdf( 2.0, 2.0, 0.0 );
95-
t.equal( isnan( y ), true, 'returns NaN' );
107+
t.equal( isnan( y ), true, 'returns expected value' );
96108

97109
y = logcdf( 2.0, 2.0, -1.0 );
98-
t.equal( isnan( y ), true, 'returns NaN' );
110+
t.equal( isnan( y ), true, 'returns expected value' );
99111

100112
y = logcdf( 0.0, 2.0, -1.0 );
101-
t.equal( isnan( y ), true, 'returns NaN' );
113+
t.equal( isnan( y ), true, 'returns expected value' );
102114

103115
y = logcdf( 2.0, 1.0, NINF );
104-
t.equal( isnan( y ), true, 'returns NaN' );
116+
t.equal( isnan( y ), true, 'returns expected value' );
105117

106118
y = logcdf( 2.0, PINF, NINF );
107-
t.equal( isnan( y ), true, 'returns NaN' );
119+
t.equal( isnan( y ), true, 'returns expected value' );
108120

109121
y = logcdf( 2.0, NINF, NINF );
110-
t.equal( isnan( y ), true, 'returns NaN' );
122+
t.equal( isnan( y ), true, 'returns expected value' );
111123

112124
y = logcdf( 2.0, NaN, NINF );
113-
t.equal( isnan( y ), true, 'returns NaN' );
125+
t.equal( isnan( y ), true, 'returns expected value' );
114126

115127
t.end();
116128
});
@@ -119,22 +131,22 @@ tape( 'if provided an `alpha` equal to `0` and `beta` is positive, the function
119131
var y;
120132

121133
y = logcdf( PINF, 0.0, 2.0 );
122-
t.equal( y, 0.0, 'returns 0 for x greater than 0' );
134+
t.equal( y, 0.0, 'returns expected value' );
123135

124136
y = logcdf( 2.5, 0.0, 2.0 );
125-
t.equal( y, 0.0, 'returns 0 for x greater than 0' );
137+
t.equal( y, 0.0, 'returns expected value' );
126138

127139
y = logcdf( 0.0, 0.0, 2.0 );
128-
t.equal( y, 0.0, 'returns 0 for x equal to 0' );
140+
t.equal( y, 0.0, 'returns expected value' );
129141

130142
y = logcdf( -2.0, 0.0, 2.0 );
131-
t.equal( y, NINF, 'returns -Infinity for x smaller than 0' );
143+
t.equal( y, NINF, 'returns expected value' );
132144

133145
y = logcdf( NINF, 0.0, 2.0 );
134-
t.equal( y, NINF, 'returns -Infinity for x smaller than 0' );
146+
t.equal( y, NINF, 'returns expected value' );
135147

136148
y = logcdf( NaN, 0.0, 2.0 );
137-
t.equal( isnan( y ), true, 'returns NaN' );
149+
t.equal( isnan( y ), true, 'returns expected value' );
138150

139151
t.end();
140152
});
@@ -145,21 +157,22 @@ tape( 'the function evaluates the logarithm of the CDF', opts, function test( t
145157
var alpha;
146158
var beta;
147159
var tol;
160+
var i;
148161
var x;
149162
var y;
150-
var i;
151163

152164
for ( i = 0; i < 1000; i++ ) {
153-
x = ( randu()*10.0 ) + EPS;
154-
alpha = ( randu()*10.0 ) + EPS;
155-
beta = ( randu()*10.0 ) + EPS;
165+
x = uniform( EPS, 10.0 );
166+
alpha = uniform( EPS, 10.0 );
167+
beta = uniform( EPS, 10.0 );
156168
y = logcdf( x, alpha, beta );
157169
expected = ln( cdf( x, alpha, beta ) );
158170
if ( y === expected ) {
159171
t.equal( y, expected, 'x: '+x+', alpha: '+alpha+', beta: '+beta+', y: '+y+', expected: '+expected );
160172
} else {
173+
// NOTE: increased test tolerance due to differences in accumulated error between JavaScript and C, especially as we are wrapping `cdf` which relies on `gammainc`, where compiler optimizations can result in different error propagation
161174
delta = abs( y - expected );
162-
tol = 150.0 * EPS * abs( expected );
175+
tol = 100.0 * EPS * abs( expected );
163176
t.ok( delta <= tol, 'within tolerance. x: '+x+'. alpha: '+alpha+'. beta: '+beta+'. y: '+y+'. E: '+expected+'. Δ: '+delta+'. tol: '+tol+'.' );
164177
}
165178
}

0 commit comments

Comments
 (0)