Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
235 changes: 234 additions & 1 deletion lib/node_modules/@stdlib/math/tools/unary/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
// MODULES //

var tape = require( 'tape' );
var unary = require( '@stdlib/ndarray/base/unary' );
var factory = require( './../lib' );


Expand All @@ -32,4 +33,236 @@ 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 i;

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() {
factory( value, [ [ 'float64' ] ], [ 'float64' ], {
'output': 'real_and_generic',
'casting': 'none'
});
};
}
});

tape( 'the function throws an error if the second argument is not an array-like object', function test( t ) {
var values;
var i;

values = [
'5',
5,
NaN,
true,
false,
null,
void 0,
{},
unary
];

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() {
factory( unary, value, [ 'float64' ], {
'output': 'real_and_generic',
'casting': 'none'
});
};
}
});

tape( 'the function throws an error if the second argument does not contain arrays of data types', function test( t ) {
var values;
var i;

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() {
factory( unary, value, [ 'float64' ], {
'output': 'real_and_generic',
'casting': 'none'
});
};
}
});

tape( 'the function throws an error if the third argument is not an array of data types', function test( t ) {
var values;
var i;

values = [
'5',
5,
NaN,
true,
false,
null,
void 0,
{},
[],
[ 'foo' ],
[ 1, 2, 3 ],
[ 'float64', 1 ],
unary
];

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() {
factory( unary, [ [ 'float64' ] ], value, {
'output': 'real_and_generic',
'casting': 'none'
});
};
}
});

tape( 'the function throws an error if the fourth argument is not an object', function test( t ) {
var values;
var i;

values = [
'5',
5,
NaN,
true,
false,
null,
void 0,
[],
unary
];

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() {
factory( unary, [ [ 'float64' ] ], [ 'float64' ], value );
};
}
});

tape( 'the function throws an error if the fourth argument does not have a valid output data type policy', function test( t ) {
var values;
var i;

values = [
'foo',
5,
NaN,
true,
false,
null,
void 0,
[],
{},
unary
];

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() {
factory( unary, [ [ 'float64' ] ], [ 'float64' ], {
'output': value,
'casting': 'none'
});
};
}
});

tape( 'the function throws an error if the fourth argument does not have a valid casting policy', function test( t ) {
var values;
var i;

values = [
'foo',
5,
NaN,
true,
false,
null,
void 0,
[],
{},
unary
];

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() {
factory( unary, [ [ 'float64' ] ], [ 'float64' ], {
'output': 'real_and_generic',
'casting': value
});
};
}
});

tape( 'the function returns a function', function test( t ) {
var fcn = factory( unary, [ [ 'float64' ] ], [ 'float64' ], {
'output': 'real_and_generic',
'casting': 'none'
});
t.strictEqual( typeof fcn, 'function', 'returns a function' );
t.end();
});

tape( 'the returned function has an `assign` method', function test( t ) {
var fcn = factory( unary, [ [ 'float64' ] ], [ 'float64' ], {
'output': 'real_and_generic',
'casting': 'none'
});
t.strictEqual( typeof fcn.assign, 'function', 'has an assign method' );
t.end();
});
Loading