diff --git a/lib/node_modules/@stdlib/random/tools/binary-factory/test/test.js b/lib/node_modules/@stdlib/random/tools/binary-factory/test/test.js index 3ed7a2ed5067..1bc5b8ef2eda 100644 --- a/lib/node_modules/@stdlib/random/tools/binary-factory/test/test.js +++ b/lib/node_modules/@stdlib/random/tools/binary-factory/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 createFactory = require( './../lib' ); @@ -32,4 +34,409 @@ 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 createFactory( value, [ idt, idt ], odt, { + 'output': 'real_floating_point_and_generic' + }, { + 'order': 'row-major' + }); + }; + } +}); + +tape( 'the function throws an error if the first argument does not have a `factory` method', function test( t ) { + var idt; + var odt; + + idt = dtypes( 'real_and_generic' ); + odt = dtypes( 'real_floating_point_and_generic' ); + + t.throws( badValue, TypeError, 'throws an error' ); + t.end(); + + function badValue() { + function prng() { + return 0.0; + } + return createFactory( prng, [ idt, idt ], odt, { + 'output': 'real_floating_point_and_generic' + }, { + 'order': 'row-major' + }); + } +}); + +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 createFactory( uniform, value, odt, { + 'output': 'real_floating_point_and_generic' + }, { + 'order': 'row-major' + }); + }; + } +}); + +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 createFactory( uniform, value, odt, { + 'output': 'real_floating_point_and_generic' + }, { + 'order': 'row-major' + }); + }; + } +}); + +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 createFactory( uniform, [ idt, idt ], value, { + 'output': 'real_floating_point_and_generic' + }, { + 'order': 'row-major' + }); + }; + } +}); + +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 createFactory( uniform, [ idt, idt ], [], { + 'output': 'real_floating_point_and_generic' + }, { + 'order': 'row-major' + }); + } +}); + +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 createFactory( uniform, [ idt, idt ], value, { + 'output': 'real_floating_point_and_generic' + }, { + 'order': 'row-major' + }); + }; + } +}); + +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 createFactory( uniform, [ idt, idt ], odt, value, { + 'order': 'row-major' + }); + }; + } +}); + +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 createFactory( uniform, [ idt, idt ], odt, { + 'output': value + }, { + 'order': 'row-major' + }); + }; + } +}); + +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 createFactory( 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 createFactory( uniform, [ idt, idt ], odt, { + 'output': 'real_floating_point_and_generic' + }, { + 'order': value + }); + }; + } +}); + +tape( 'the function returns a function', function test( t ) { + var idt; + var odt; + var f; + + idt = dtypes( 'real_and_generic' ); + odt = dtypes( 'real_floating_point_and_generic' ); + + f = createFactory( uniform, [ idt, idt ], odt, { + 'output': 'real_floating_point_and_generic' + }, { + 'order': 'row-major' + }); + t.strictEqual( typeof f, 'function', 'returns a function' ); + t.end(); +}); + +tape( 'the function returns a function (no options)', function test( t ) { + var idt; + var odt; + var f; + + idt = dtypes( 'real_and_generic' ); + odt = dtypes( 'real_floating_point_and_generic' ); + + f = createFactory( uniform, [ idt, idt ], odt, { + 'output': 'real_floating_point_and_generic' + }); + t.strictEqual( typeof f, 'function', 'returns a function' ); + t.end(); +}); + +tape( 'the returned function returns a function', function test( t ) { + var factory; + var idt; + var odt; + var f; + + idt = dtypes( 'real_and_generic' ); + odt = dtypes( 'real_floating_point_and_generic' ); + + factory = createFactory( uniform, [ idt, idt ], odt, { + 'output': 'real_floating_point_and_generic' + }, { + 'order': 'row-major' + }); + f = factory(); + t.strictEqual( typeof f, 'function', 'returns a function' ); + t.end(); +});