Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
var tape = require( 'tape' );
var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive;
var dtypes = require( '@stdlib/ndarray/dtypes' );
var cartesianPower = require( '@stdlib/array/base/cartesian-power' );
var promoteDataTypes = require( '@stdlib/ndarray/base/promote-dtypes' );
var quinaryBlockSize = require( './../lib' );

Expand All @@ -37,21 +36,28 @@ tape( 'main export is a function', function test( t ) {
});

tape( 'the function returns a block size', function test( t ) {
var combo;
var dt;
var pt;
var v;
var i;
var j;

// NOTE: we don't test for exact block size values, as we shouldn't need to make guarantees regarding the block size for any particular set of dtypes. This function is meant to be opaque, and we want to reserve the right to silently update/change return values in the future.

// Generate dtype quintuplets:
dt = cartesianPower( dtypes(), 5 );
// Generate a list of dtypes:
dt = dtypes();

// NOTE: testing the full cartesian product of dtypes (i.e., `dt.length^5` combinations) is prohibitively expensive and exhausts available memory. Instead, cyclically rotate the dtype list to generate quintuplets, ensuring that every dtype is exercised in every argument position at least once:
for ( i = 0; i < dt.length; i++ ) {
pt = promoteDataTypes( dt[ i ] );
dt[ i ].push( ( pt === null ) ? 'generic' : pt );
v = quinaryBlockSize( dt[ i ][ 0 ], dt[ i ][ 1 ], dt[ i ][ 2 ], dt[ i ][ 3 ], dt[ i ][ 4 ], dt[ i ][ 5 ] ); // eslint-disable-line max-len
t.strictEqual( isPositiveInteger( v ), true, 'returns a positive integer when provided ('+dt[ i ].join( ', ' )+')' );
combo = [];
for ( j = 0; j < 5; j++ ) {
combo.push( dt[ ( i+j ) % dt.length ] );
}
pt = promoteDataTypes( combo );
combo.push( ( pt === null ) ? 'generic' : pt );
v = quinaryBlockSize( combo[ 0 ], combo[ 1 ], combo[ 2 ], combo[ 3 ], combo[ 4 ], combo[ 5 ] ); // eslint-disable-line max-len
t.strictEqual( isPositiveInteger( v ), true, 'returns a positive integer when provided ('+combo.join( ', ' )+')' );
}

// Sanity check that the block size for dtypes with wider bit widths is smaller than for dtypes with shorter bit widths...
Expand Down
Loading