Skip to content

Commit 36d236e

Browse files
committed
test: guard against edge case
This commit guards against the scenario where a PRNG generates a zero during random value generation. This happened during a test run of `discrete-uniform`. While not likely for continuous distributions, we go ahead and set the original array element to `NaN`, which should never be generated unless a PRNG is misconfigured. --- 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: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent e98a1fd commit 36d236e

File tree

21 files changed

+399
-0
lines changed

21 files changed

+399
-0
lines changed

lib/node_modules/@stdlib/random/arcsine/test/test.assign.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,13 @@ tape( 'the `assign` method fills an ndarray with pseudorandom numbers (scalar)',
134134
out = zeros( [ 3, 3 ], {
135135
'dtype': 'float64'
136136
});
137+
out.set( 0, 0, NaN );
138+
137139
original = zeros( [ 3, 3 ], {
138140
'dtype': 'float64'
139141
});
142+
original.set( 0, 0, NaN );
143+
140144
actual = random.assign( PARAM1, PARAM2, out );
141145

142146
t.strictEqual( out, actual, 'returns expected value' );
@@ -157,9 +161,12 @@ tape( 'the `assign` method fills an ndarray with pseudorandom numbers (zero-dime
157161
out = zeros( [ 3, 3 ], {
158162
'dtype': 'float64'
159163
});
164+
out.set( 0, 0, NaN );
165+
160166
original = zeros( [ 3, 3 ], {
161167
'dtype': 'float64'
162168
});
169+
original.set( 0, 0, NaN );
163170

164171
actual = random.assign( param1, param2, out );
165172

@@ -182,9 +189,12 @@ tape( 'the `assign` method fills an ndarray with pseudorandom numbers (ndarray)'
182189
out = zeros( [ 2, 2 ], {
183190
'dtype': 'float64'
184191
});
192+
out.set( 0, 0, NaN );
193+
185194
original = zeros( [ 2, 2 ], {
186195
'dtype': 'float64'
187196
});
197+
original.set( 0, 0, NaN );
188198

189199
actual = random.assign( param1, param2, out );
190200

@@ -207,9 +217,12 @@ tape( 'the `assign` method fills an ndarray with pseudorandom numbers (broadcast
207217
out = zeros( [ 2, 2 ], {
208218
'dtype': 'float64'
209219
});
220+
out.set( 0, 0, NaN );
221+
210222
original = zeros( [ 2, 2 ], {
211223
'dtype': 'float64'
212224
});
225+
original.set( 0, 0, NaN );
213226

214227
actual = random.assign( param1, param2, out );
215228

@@ -227,9 +240,12 @@ tape( 'the `assign` method supports filling a zero-dimensional ndarray (scalar)'
227240
out = zeros( [], {
228241
'dtype': 'float64'
229242
});
243+
out.set( NaN );
244+
230245
original = zeros( [], {
231246
'dtype': 'float64'
232247
});
248+
original.set( NaN );
233249

234250
actual = random.assign( PARAM1, PARAM2, out );
235251

@@ -251,9 +267,12 @@ tape( 'the `assign` method supports filling a zero-dimensional ndarray (ndarray)
251267
out = zeros( [], {
252268
'dtype': 'float64'
253269
});
270+
out.set( NaN );
271+
254272
original = zeros( [], {
255273
'dtype': 'float64'
256274
});
275+
original.set( NaN );
257276

258277
actual = random.assign( param1, param2, out );
259278

lib/node_modules/@stdlib/random/beta/test/test.assign.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,13 @@ tape( 'the `assign` method fills an ndarray with pseudorandom numbers (scalar)',
134134
out = zeros( [ 3, 3 ], {
135135
'dtype': 'float64'
136136
});
137+
out.set( 0, 0, NaN );
138+
137139
original = zeros( [ 3, 3 ], {
138140
'dtype': 'float64'
139141
});
142+
original.set( 0, 0, NaN );
143+
140144
actual = random.assign( PARAM1, PARAM2, out );
141145

142146
t.strictEqual( out, actual, 'returns expected value' );
@@ -157,9 +161,12 @@ tape( 'the `assign` method fills an ndarray with pseudorandom numbers (zero-dime
157161
out = zeros( [ 3, 3 ], {
158162
'dtype': 'float64'
159163
});
164+
out.set( 0, 0, NaN );
165+
160166
original = zeros( [ 3, 3 ], {
161167
'dtype': 'float64'
162168
});
169+
original.set( 0, 0, NaN );
163170

164171
actual = random.assign( param1, param2, out );
165172

@@ -182,9 +189,12 @@ tape( 'the `assign` method fills an ndarray with pseudorandom numbers (ndarray)'
182189
out = zeros( [ 2, 2 ], {
183190
'dtype': 'float64'
184191
});
192+
out.set( 0, 0, NaN );
193+
185194
original = zeros( [ 2, 2 ], {
186195
'dtype': 'float64'
187196
});
197+
original.set( 0, 0, NaN );
188198

189199
actual = random.assign( param1, param2, out );
190200

@@ -207,9 +217,12 @@ tape( 'the `assign` method fills an ndarray with pseudorandom numbers (broadcast
207217
out = zeros( [ 2, 2 ], {
208218
'dtype': 'float64'
209219
});
220+
out.set( 0, 0, NaN );
221+
210222
original = zeros( [ 2, 2 ], {
211223
'dtype': 'float64'
212224
});
225+
original.set( 0, 0, NaN );
213226

214227
actual = random.assign( param1, param2, out );
215228

@@ -227,9 +240,12 @@ tape( 'the `assign` method supports filling a zero-dimensional ndarray (scalar)'
227240
out = zeros( [], {
228241
'dtype': 'float64'
229242
});
243+
out.set( NaN );
244+
230245
original = zeros( [], {
231246
'dtype': 'float64'
232247
});
248+
original.set( NaN );
233249

234250
actual = random.assign( PARAM1, PARAM2, out );
235251

@@ -251,9 +267,12 @@ tape( 'the `assign` method supports filling a zero-dimensional ndarray (ndarray)
251267
out = zeros( [], {
252268
'dtype': 'float64'
253269
});
270+
out.set( NaN );
271+
254272
original = zeros( [], {
255273
'dtype': 'float64'
256274
});
275+
original.set( NaN );
257276

258277
actual = random.assign( param1, param2, out );
259278

lib/node_modules/@stdlib/random/betaprime/test/test.assign.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,13 @@ tape( 'the `assign` method fills an ndarray with pseudorandom numbers (scalar)',
134134
out = zeros( [ 3, 3 ], {
135135
'dtype': 'float64'
136136
});
137+
out.set( 0, 0, NaN );
138+
137139
original = zeros( [ 3, 3 ], {
138140
'dtype': 'float64'
139141
});
142+
original.set( 0, 0, NaN );
143+
140144
actual = random.assign( PARAM1, PARAM2, out );
141145

142146
t.strictEqual( out, actual, 'returns expected value' );
@@ -157,9 +161,12 @@ tape( 'the `assign` method fills an ndarray with pseudorandom numbers (zero-dime
157161
out = zeros( [ 3, 3 ], {
158162
'dtype': 'float64'
159163
});
164+
out.set( 0, 0, NaN );
165+
160166
original = zeros( [ 3, 3 ], {
161167
'dtype': 'float64'
162168
});
169+
original.set( 0, 0, NaN );
163170

164171
actual = random.assign( param1, param2, out );
165172

@@ -182,9 +189,12 @@ tape( 'the `assign` method fills an ndarray with pseudorandom numbers (ndarray)'
182189
out = zeros( [ 2, 2 ], {
183190
'dtype': 'float64'
184191
});
192+
out.set( 0, 0, NaN );
193+
185194
original = zeros( [ 2, 2 ], {
186195
'dtype': 'float64'
187196
});
197+
original.set( 0, 0, NaN );
188198

189199
actual = random.assign( param1, param2, out );
190200

@@ -207,9 +217,12 @@ tape( 'the `assign` method fills an ndarray with pseudorandom numbers (broadcast
207217
out = zeros( [ 2, 2 ], {
208218
'dtype': 'float64'
209219
});
220+
out.set( 0, 0, NaN );
221+
210222
original = zeros( [ 2, 2 ], {
211223
'dtype': 'float64'
212224
});
225+
original.set( 0, 0, NaN );
213226

214227
actual = random.assign( param1, param2, out );
215228

@@ -227,9 +240,12 @@ tape( 'the `assign` method supports filling a zero-dimensional ndarray (scalar)'
227240
out = zeros( [], {
228241
'dtype': 'float64'
229242
});
243+
out.set( NaN );
244+
230245
original = zeros( [], {
231246
'dtype': 'float64'
232247
});
248+
original.set( NaN );
233249

234250
actual = random.assign( PARAM1, PARAM2, out );
235251

@@ -251,9 +267,12 @@ tape( 'the `assign` method supports filling a zero-dimensional ndarray (ndarray)
251267
out = zeros( [], {
252268
'dtype': 'float64'
253269
});
270+
out.set( NaN );
271+
254272
original = zeros( [], {
255273
'dtype': 'float64'
256274
});
275+
original.set( NaN );
257276

258277
actual = random.assign( param1, param2, out );
259278

lib/node_modules/@stdlib/random/binomial/test/test.assign.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,13 @@ tape( 'the `assign` method fills an ndarray with pseudorandom numbers (scalar)',
134134
out = zeros( [ 3, 3 ], {
135135
'dtype': 'float64'
136136
});
137+
out.set( 0, 0, NaN );
138+
137139
original = zeros( [ 3, 3 ], {
138140
'dtype': 'float64'
139141
});
142+
original.set( 0, 0, NaN );
143+
140144
actual = random.assign( PARAM1, PARAM2, out );
141145

142146
t.strictEqual( out, actual, 'returns expected value' );
@@ -157,9 +161,12 @@ tape( 'the `assign` method fills an ndarray with pseudorandom numbers (zero-dime
157161
out = zeros( [ 3, 3 ], {
158162
'dtype': 'float64'
159163
});
164+
out.set( 0, 0, NaN );
165+
160166
original = zeros( [ 3, 3 ], {
161167
'dtype': 'float64'
162168
});
169+
original.set( 0, 0, NaN );
163170

164171
actual = random.assign( param1, param2, out );
165172

@@ -182,9 +189,12 @@ tape( 'the `assign` method fills an ndarray with pseudorandom numbers (ndarray)'
182189
out = zeros( [ 2, 2 ], {
183190
'dtype': 'float64'
184191
});
192+
out.set( 0, 0, NaN );
193+
185194
original = zeros( [ 2, 2 ], {
186195
'dtype': 'float64'
187196
});
197+
original.set( 0, 0, NaN );
188198

189199
actual = random.assign( param1, param2, out );
190200

@@ -207,9 +217,12 @@ tape( 'the `assign` method fills an ndarray with pseudorandom numbers (broadcast
207217
out = zeros( [ 2, 2 ], {
208218
'dtype': 'float64'
209219
});
220+
out.set( 0, 0, NaN );
221+
210222
original = zeros( [ 2, 2 ], {
211223
'dtype': 'float64'
212224
});
225+
original.set( 0, 0, NaN );
213226

214227
actual = random.assign( param1, param2, out );
215228

@@ -227,9 +240,12 @@ tape( 'the `assign` method supports filling a zero-dimensional ndarray (scalar)'
227240
out = zeros( [], {
228241
'dtype': 'float64'
229242
});
243+
out.set( NaN );
244+
230245
original = zeros( [], {
231246
'dtype': 'float64'
232247
});
248+
original.set( NaN );
233249

234250
actual = random.assign( PARAM1, PARAM2, out );
235251

@@ -251,9 +267,12 @@ tape( 'the `assign` method supports filling a zero-dimensional ndarray (ndarray)
251267
out = zeros( [], {
252268
'dtype': 'float64'
253269
});
270+
out.set( NaN );
271+
254272
original = zeros( [], {
255273
'dtype': 'float64'
256274
});
275+
original.set( NaN );
257276

258277
actual = random.assign( param1, param2, out );
259278

lib/node_modules/@stdlib/random/cauchy/test/test.assign.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,13 @@ tape( 'the `assign` method fills an ndarray with pseudorandom numbers (scalar)',
134134
out = zeros( [ 3, 3 ], {
135135
'dtype': 'float64'
136136
});
137+
out.set( 0, 0, NaN );
138+
137139
original = zeros( [ 3, 3 ], {
138140
'dtype': 'float64'
139141
});
142+
original.set( 0, 0, NaN );
143+
140144
actual = random.assign( PARAM1, PARAM2, out );
141145

142146
t.strictEqual( out, actual, 'returns expected value' );
@@ -157,9 +161,12 @@ tape( 'the `assign` method fills an ndarray with pseudorandom numbers (zero-dime
157161
out = zeros( [ 3, 3 ], {
158162
'dtype': 'float64'
159163
});
164+
out.set( 0, 0, NaN );
165+
160166
original = zeros( [ 3, 3 ], {
161167
'dtype': 'float64'
162168
});
169+
original.set( 0, 0, NaN );
163170

164171
actual = random.assign( param1, param2, out );
165172

@@ -182,9 +189,12 @@ tape( 'the `assign` method fills an ndarray with pseudorandom numbers (ndarray)'
182189
out = zeros( [ 2, 2 ], {
183190
'dtype': 'float64'
184191
});
192+
out.set( 0, 0, NaN );
193+
185194
original = zeros( [ 2, 2 ], {
186195
'dtype': 'float64'
187196
});
197+
original.set( 0, 0, NaN );
188198

189199
actual = random.assign( param1, param2, out );
190200

@@ -207,9 +217,12 @@ tape( 'the `assign` method fills an ndarray with pseudorandom numbers (broadcast
207217
out = zeros( [ 2, 2 ], {
208218
'dtype': 'float64'
209219
});
220+
out.set( 0, 0, NaN );
221+
210222
original = zeros( [ 2, 2 ], {
211223
'dtype': 'float64'
212224
});
225+
original.set( 0, 0, NaN );
213226

214227
actual = random.assign( param1, param2, out );
215228

@@ -227,9 +240,12 @@ tape( 'the `assign` method supports filling a zero-dimensional ndarray (scalar)'
227240
out = zeros( [], {
228241
'dtype': 'float64'
229242
});
243+
out.set( NaN );
244+
230245
original = zeros( [], {
231246
'dtype': 'float64'
232247
});
248+
original.set( NaN );
233249

234250
actual = random.assign( PARAM1, PARAM2, out );
235251

@@ -251,9 +267,12 @@ tape( 'the `assign` method supports filling a zero-dimensional ndarray (ndarray)
251267
out = zeros( [], {
252268
'dtype': 'float64'
253269
});
270+
out.set( NaN );
271+
254272
original = zeros( [], {
255273
'dtype': 'float64'
256274
});
275+
original.set( NaN );
257276

258277
actual = random.assign( param1, param2, out );
259278

0 commit comments

Comments
 (0)