Skip to content

Commit d7624bd

Browse files
committed
Update validate function and fix tests
1 parent b5d1349 commit d7624bd

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

lib/node_modules/@stdlib/stats/kde2d/lib/validate.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' );
2727
var isPositiveNumberArray = require( '@stdlib/assert/is-positive-number-array' );
2828
var isFunction = require( '@stdlib/assert/is-function' );
2929
var isError = require( '@stdlib/assert/is-error' );
30-
var isNumber = require( '@stdlib/assert/is-number' );
30+
var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive;
31+
var isnan = require( '@stdlib/assert/is-nan' );
3132
var getKernel = require( './get_kernel.js' );
3233

3334

@@ -68,7 +69,7 @@ function validate( opts, options ) {
6869
if ( !isPositiveNumberArray( opts.h) ) {
6970
return new TypeError( 'invaild option. `h` must be an array of positive values. Option: `' + opts.n + '`.');
7071
}
71-
if ( opts.h.length !== 2) {
72+
if ( opts.h.length !== 2 ) {
7273
return new TypeError( 'invalid option. `h` must be an array of length two. Option: `' + opts.n + '`.');
7374
}
7475
}
@@ -80,25 +81,25 @@ function validate( opts, options ) {
8081
}
8182
if ( hasOwnProp( options, 'xMax' ) ) {
8283
opts.xMax = options.xMax;
83-
if (!isNumber(opts.xMax)) {
84+
if ( !isNumber( opts.xMax ) || isnan( opts.xMax ) ) {
8485
return new TypeError( 'invalid option. `xMax` must be a number. Option: `' + opts.xMax + '`.' );
8586
}
8687
}
8788
if ( hasOwnProp( options, 'xMin' ) ) {
8889
opts.xMin = options.xMin;
89-
if (!isNumber(opts.xMin)) {
90+
if ( !isNumber( opts.xMin ) || isnan( opts.xMin ) ) {
9091
return new TypeError( 'invalid option. `xMin` must be a number. Option: `' + opts.xMin + '`.' );
9192
}
9293
}
9394
if ( hasOwnProp( options, 'yMax' ) ) {
9495
opts.yMax = options.yMax;
95-
if (!isNumber(opts.yMax)) {
96+
if ( !isNumber( opts.yMax ) || isnan( opts.yMax ) ) {
9697
return new TypeError( 'invalid option. `yMax` must be a number. Option: `' + opts.yMax + '`.' );
9798
}
9899
}
99100
if ( hasOwnProp( options, 'yMin' ) ) {
100101
opts.yMin = options.yMin;
101-
if (!isNumber(opts.yMin)) {
102+
if ( !isNumber( opts.yMin ) || isnan( opts.yMin ) ) {
102103
return new TypeError( 'invalid option. `yMin` must be a number. Option: `' + opts.yMin + '`.' );
103104
}
104105
}

lib/node_modules/@stdlib/stats/kde2d/test/test.validate.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
// MODULES //
2222

2323
var tape = require( 'tape' );
24+
var gaussian = require( './../lib/gaussian.js' );
2425
var validate = require( './../lib/validate.js' );
2526

2627

@@ -93,7 +94,7 @@ tape( 'the function returns a type error if provided an `h` option which is not
9394
t.end();
9495
});
9596

96-
tape( 'the function returns a type error if provided an `h` option that is a positiveNumberArray not of length 2', function test( t ) {
97+
tape( 'the function returns a type error if provided an `h` option that is a positive number array not of length two', function test( t ) {
9798
var values;
9899
var err;
99100
var i;
@@ -321,7 +322,7 @@ tape( 'the function returns a type error if provided a `kernel` option that does
321322
t.end();
322323
});
323324

324-
tape( 'the function returns a type error if provided a `kernel` option not a string or function', function test( t ) {
325+
tape( 'the function returns a type error if provided a `kernel` option that is not a string or function', function test( t ) {
325326
var values;
326327
var err;
327328
var i;
@@ -349,7 +350,7 @@ tape( 'the function returns `null` if all options are valid', function test( t )
349350
var err;
350351

351352
options = {
352-
'h': [0.1, 0.1],
353+
'h': [ 0.1, 0.1 ],
353354
'n': 35,
354355
'xMin': 35,
355356
'xMax': 40,
@@ -360,10 +361,13 @@ tape( 'the function returns `null` if all options are valid', function test( t )
360361
opts = {};
361362

362363
expected = {
363-
'h': options.h,
364+
'h': [ 0.1, 0.1 ],
364365
'n': options.n,
365-
'xLim': options.xLim,
366-
'yLim': options.yLim
366+
'xMin': options.xMin,
367+
'xMax': options.xMax,
368+
'yMin': options.yMin,
369+
'yMax': options.yMax,
370+
'kernel': gaussian
367371
};
368372

369373
err = validate( opts, options );

0 commit comments

Comments
 (0)