diff --git a/lib/node_modules/@stdlib/random/tools/binary/test/test.js b/lib/node_modules/@stdlib/random/tools/binary/test/test.js index d13b7092da9e..06c81c61d7f6 100644 --- a/lib/node_modules/@stdlib/random/tools/binary/test/test.js +++ b/lib/node_modules/@stdlib/random/tools/binary/test/test.js @@ -21,6 +21,8 @@ // MODULES // var tape = require( 'tape' ); +var uniform = require( '@stdlib/random/base/uniform' ); +var dtypes = require( '@stdlib/ndarray/dtypes' ); var Random = require( './../lib' ); @@ -32,4 +34,397 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -// FIXME: add tests +tape( 'the function throws an error if the first argument is not a function', function test( t ) { + var values; + var idt; + var odt; + var i; + + idt = dtypes( 'real_and_generic' ); + odt = dtypes( 'real_floating_point_and_generic' ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Random( value, [ idt, idt ], odt, { + 'output': 'real_floating_point_and_generic' + }); + }; + } +}); + +tape( 'the function throws an error if the second argument is not an array-like object', function test( t ) { + var values; + var odt; + var i; + + odt = dtypes( 'real_floating_point_and_generic' ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + uniform + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Random( uniform, value, odt, { + 'output': 'real_floating_point_and_generic' + }); + }; + } +}); + +tape( 'the function throws an error if the second argument does not contain arrays of data types', function test( t ) { + var values; + var odt; + var i; + + odt = dtypes( 'real_floating_point_and_generic' ); + + values = [ + [ [] ], + [ [ 'foo' ] ], + [ [ 1, 2, 3 ] ], + [ [ 'float64', 1 ] ], + [ 'float64' ], + [ {}, {} ] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Random( uniform, value, odt, { + 'output': 'real_floating_point_and_generic' + }); + }; + } +}); + +tape( 'the function throws an error if the third argument is not an array of data types', function test( t ) { + var values; + var idt; + var i; + + idt = dtypes( 'real_and_generic' ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + uniform + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Random( uniform, [ idt, idt ], value, { + 'output': 'real_floating_point_and_generic' + }); + }; + } +}); + +tape( 'the function throws an error if the third argument is an empty array', function test( t ) { + var idt; + + idt = dtypes( 'real_and_generic' ); + + t.throws( badValue, TypeError, 'throws an error' ); + t.end(); + + function badValue() { + return new Random( uniform, [ idt, idt ], [], { + 'output': 'real_floating_point_and_generic' + }); + } +}); + +tape( 'the function throws an error if the third argument contains invalid data types', function test( t ) { + var values; + var idt; + var i; + + idt = dtypes( 'real_and_generic' ); + + values = [ + [ 'foo' ], + [ 1, 2, 3 ], + [ 'float64', 1 ], + 'float64' + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Random( uniform, [ idt, idt ], value, { + 'output': 'real_floating_point_and_generic' + }); + }; + } +}); + +tape( 'the function throws an error if the fourth argument is not an object', function test( t ) { + var values; + var idt; + var odt; + var i; + + idt = dtypes( 'real_and_generic' ); + odt = dtypes( 'real_floating_point_and_generic' ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + uniform + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Random( uniform, [ idt, idt ], odt, value ); + }; + } +}); + +tape( 'the function throws an error if the fourth argument does not have a supported output data type policy', function test( t ) { + var values; + var idt; + var odt; + var i; + + idt = dtypes( 'real_and_generic' ); + odt = dtypes( 'real_floating_point_and_generic' ); + + values = [ + 'foo', + 'bar', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + uniform + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Random( uniform, [ idt, idt ], odt, { + 'output': value + }); + }; + } +}); + +tape( 'the function throws an error if the options argument is not an object', function test( t ) { + var values; + var idt; + var odt; + var i; + + idt = dtypes( 'real_and_generic' ); + odt = dtypes( 'real_floating_point_and_generic' ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + [], + uniform + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Random( uniform, [ idt, idt ], odt, { + 'output': 'real_floating_point_and_generic' + }, value ); + }; + } +}); + +tape( 'the function throws an error if provided an invalid `order` option', function test( t ) { + var values; + var idt; + var odt; + var i; + + idt = dtypes( 'real_and_generic' ); + odt = dtypes( 'real_floating_point_and_generic' ); + + values = [ + 'foo', + 'bar', + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + uniform + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return new Random( uniform, [ idt, idt ], odt, { + 'output': 'real_floating_point_and_generic' + }, { + 'order': value + }); + }; + } +}); + +tape( 'the function returns an instance', function test( t ) { + var idt; + var odt; + var r; + + idt = dtypes( 'real_and_generic' ); + odt = dtypes( 'real_floating_point_and_generic' ); + + r = new Random( uniform, [ idt, idt ], odt, { + 'output': 'real_floating_point_and_generic' + }); + t.strictEqual( r instanceof Random, true, 'returns an instance' ); + t.end(); +}); + +tape( 'the function returns an instance (w/o new)', function test( t ) { + var idt; + var odt; + var r; + + idt = dtypes( 'real_and_generic' ); + odt = dtypes( 'real_floating_point_and_generic' ); + + r = Random( uniform, [ idt, idt ], odt, { // eslint-disable-line new-cap + 'output': 'real_floating_point_and_generic' + }); + t.strictEqual( r instanceof Random, true, 'returns an instance' ); + t.end(); +}); + +tape( 'the function returns an instance (options)', function test( t ) { + var idt; + var odt; + var r; + + idt = dtypes( 'real_and_generic' ); + odt = dtypes( 'real_floating_point_and_generic' ); + + r = new Random( uniform, [ idt, idt ], odt, { + 'output': 'real_floating_point_and_generic' + }, { + 'order': 'row-major' + }); + t.strictEqual( r instanceof Random, true, 'returns an instance' ); + t.end(); +}); + +tape( 'the instance has a `generate` method', function test( t ) { + var idt; + var odt; + var r; + + idt = dtypes( 'real_and_generic' ); + odt = dtypes( 'real_floating_point_and_generic' ); + + r = new Random( uniform, [ idt, idt ], odt, { + 'output': 'real_floating_point_and_generic' + }); + t.strictEqual( typeof r.generate, 'function', 'has a generate method' ); + t.end(); +}); + +tape( 'the instance has an `assign` method', function test( t ) { + var idt; + var odt; + var r; + + idt = dtypes( 'real_and_generic' ); + odt = dtypes( 'real_floating_point_and_generic' ); + + r = new Random( uniform, [ idt, idt ], odt, { + 'output': 'real_floating_point_and_generic' + }); + t.strictEqual( typeof r.assign, 'function', 'has an assign method' ); + t.end(); +});