Skip to content
Merged
Show file tree
Hide file tree
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 @@ -49,14 +49,14 @@ tape( 'the function returns `false` if provided a prime number', function test(
M = 2e4;
for ( i = 0; i < M; i++ ) {
v = PRIMES[ i ];
t.equal( isComposite( v ), false, 'returns false when provided '+v );
t.equal( isComposite( v ), false, 'returns expected value when provided '+v );
}
// Randomly test prime numbers chosen from the remainder of the list of known prime numbers...
N = PRIMES.length - 1;
for ( i = 0; i < 1e3; i++ ) {
j = discreteUniform( M, N );
v = PRIMES[ j ];
t.equal( isComposite( v ), false, 'returns false when provided '+v );
t.equal( isComposite( v ), false, 'returns expected value when provided '+v );
}
t.end();
});
Expand All @@ -79,7 +79,7 @@ tape( 'the function returns `true` if provided a composite number', function tes
if ( hash[ i ] ) {
continue;
}
t.equal( isComposite( i ), true, 'returns true when provided '+i );
t.equal( isComposite( i ), true, 'returns expected value when provided '+i );
}
// Generate random composite integers among the list of primes...
MAX = PRIMES[ N-1 ];
Expand All @@ -92,7 +92,7 @@ tape( 'the function returns `true` if provided a composite number', function tes
i -= 1;
continue;
}
t.equal( isComposite( j ), true, 'returns true when provided '+j );
t.equal( isComposite( j ), true, 'returns expected value when provided '+j );
}
t.end();
});
Expand All @@ -103,7 +103,7 @@ tape( 'the function returns `false` if not provided a positive integer', functio
for ( i = 0; i < 100; i++ ) {
v = ( randu()*100.0 ) - 50.0;
if ( trunc(v) !== v ) {
t.equal( isComposite( v ), false, 'returns false when provided '+v );
t.equal( isComposite( v ), false, 'returns expected value when provided '+v );
}
}
t.end();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ tape( 'the function returns `false` if provided a prime number', opts, function
M = 2e4;
for ( i = 0; i < M; i++ ) {
v = PRIMES[ i ];
t.equal( isComposite( v ), false, 'returns false when provided ' + v );
t.equal( isComposite( v ), false, 'returns expected value when provided ' + v );
}
// Randomly test prime numbers chosen from the remainder of the list of known prime numbers...
N = PRIMES.length - 1;
for ( i = 0; i < 1e3; i++ ) {
j = discreteUniform( M, N );
v = PRIMES[ j ];
t.equal( isComposite( v ), false, 'returns false when provided ' + v );
t.equal( isComposite( v ), false, 'returns expected value when provided ' + v );
}
t.end();
});
Expand All @@ -92,7 +92,7 @@ tape( 'the function returns `true` if provided a composite number', opts, functi
if ( hash[ i ] ) {
continue;
}
t.equal( isComposite( i ), true, 'returns true when provided ' + i );
t.equal( isComposite( i ), true, 'returns expected value when provided ' + i );
}
// Generate random composite integers among the list of primes...
MAX = PRIMES[ N-1 ];
Expand All @@ -105,7 +105,7 @@ tape( 'the function returns `true` if provided a composite number', opts, functi
i -= 1;
continue;
}
t.equal( isComposite( j ), true, 'returns true when provided ' + j );
t.equal( isComposite( j ), true, 'returns expected value when provided ' + j );
}
t.end();
});
Expand All @@ -116,7 +116,7 @@ tape( 'the function returns `false` if not provided a positive integer', opts, f
for ( i = 0; i < 100; i++ ) {
v = ( randu()*100.0 ) - 50.0;
if ( trunc( v ) !== v ) {
t.equal( isComposite( v ), false, 'returns false when provided ' + v );
t.equal( isComposite( v ), false, 'returns expected value when provided ' + v );
}
}
t.end();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/array/uniform' );
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
var pkg = require( './../package.json' ).name;
var isNegativeFinite = require( './../lib' );
Expand All @@ -30,14 +30,19 @@ var isNegativeFinite = require( './../lib' );
// MAIN //

bench( pkg, function benchmark( b ) {
var opts;
var x;
var y;
var i;

opts = {
'dtype': 'float64'
};
x = uniform( 100, -100.0, 100.0, opts );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = (randu()*200.0) - 100.0;
y = isNegativeFinite( x );
y = isNegativeFinite( x[ i%x.length ] );
if ( typeof y !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/array/uniform' );
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;
Expand All @@ -39,14 +39,19 @@ var opts = {
// MAIN //

bench( pkg+'::native', opts, function benchmark( b ) {
var opts;
var x;
var y;
var i;

opts = {
'dtype': 'float64'
};
x = uniform( 100, -100.0, 100.0, opts );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = ( randu()*200.0 ) - 100.0;
y = isNegativeFinite( x );
y = isNegativeFinite( x[ i%x.length ] );
if ( typeof y !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,18 @@ static double rand_double( void ) {
*/
static double benchmark( void ) {
double elapsed;
double x;
double x[ 100 ];
double t;
bool b;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = ( rand_double() * 200.0 ) - 100.0;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( rand_double() * 200.0 ) - 100.0;
b = stdlib_base_is_negative_finite( x );
b = stdlib_base_is_negative_finite( x[ i%100 ] );
if ( b != true && b != false ) {
printf( "should return either true or false\n" );
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,24 @@ tape( 'main export is a function', function test( t ) {
});

tape( 'the function returns `true` if provided a negative finite number', function test( t ) {
t.equal( isNegativeFinite( -3.14 ), true, 'returns true' );
t.equal( isNegativeFinite( -1.0e308 ), true, 'returns true' );
t.equal( isNegativeFinite( -3.14 ), true, 'returns expected value' );
t.equal( isNegativeFinite( -1.0e308 ), true, 'returns expected value' );
t.end();
});

tape( 'the function returns `false` if not provided a negative finite number', function test( t ) {
t.equal( isNegativeFinite( 2.0 ), false, 'returns false' );
t.equal( isNegativeFinite( 0.0 ), false, 'returns false' );
t.equal( isNegativeFinite( -0.0 ), false, 'returns false' );
t.equal( isNegativeFinite( 2.0 ), false, 'returns expected value' );
t.equal( isNegativeFinite( 0.0 ), false, 'returns expected value' );
t.equal( isNegativeFinite( -0.0 ), false, 'returns expected value' );
t.end();
});

tape( 'the function returns `false` if provided `-infinity`', function test( t ) {
t.equal( isNegativeFinite( NINF ), false, 'returns false' );
t.equal( isNegativeFinite( NINF ), false, 'returns expected value' );
t.end();
});

tape( 'the function returns `false` if provided `NaN`', function test( t ) {
t.equal( isNegativeFinite( NaN ), false, 'returns false' );
t.equal( isNegativeFinite( NaN ), false, 'returns expected value' );
t.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,24 @@ tape( 'main export is a function', opts, function test( t ) {
});

tape( 'the function returns `true` if provided a negative finite number', opts, function test( t ) {
t.equal( isNegativeFinite( -3.14 ), true, 'returns true' );
t.equal( isNegativeFinite( -1.0e308 ), true, 'returns true' );
t.equal( isNegativeFinite( -3.14 ), true, 'returns expected value' );
t.equal( isNegativeFinite( -1.0e308 ), true, 'returns expected value' );
t.end();
});

tape( 'the function returns `false` if not provided a negative finite number', opts, function test( t ) {
t.equal( isNegativeFinite( 2.0 ), false, 'returns false' );
t.equal( isNegativeFinite( 0.0 ), false, 'returns false' );
t.equal( isNegativeFinite( -0.0 ), false, 'returns false' );
t.equal( isNegativeFinite( 2.0 ), false, 'returns expected value' );
t.equal( isNegativeFinite( 0.0 ), false, 'returns expected value' );
t.equal( isNegativeFinite( -0.0 ), false, 'returns expected value' );
t.end();
});

tape( 'the function returns `false` if provided `-infinity`', opts, function test( t ) {
t.equal( isNegativeFinite( NINF ), false, 'returns false' );
t.equal( isNegativeFinite( NINF ), false, 'returns expected value' );
t.end();
});

tape( 'the function returns `false` if provided `NaN`', opts, function test( t ) {
t.equal( isNegativeFinite( NaN ), false, 'returns false' );
t.equal( isNegativeFinite( NaN ), false, 'returns expected value' );
t.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var round = require( '@stdlib/math/base/special/round' );
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
var pkg = require( './../package.json' ).name;
var isNegativeInteger = require( './../lib' );
Expand All @@ -31,14 +30,19 @@ var isNegativeInteger = require( './../lib' );
// MAIN //

bench( pkg, function benchmark( b ) {
var opts;
var x;
var y;
var i;

opts = {
'dtype': 'float64'
};
x = discreteUniform( 100, -5.0e6, 5.0e6, opts );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = round( (randu()*1.0e7) - 5.0e6 );
y = isNegativeInteger( x );
y = isNegativeInteger( x[ i%x.length ] );
if ( typeof y !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var round = require( '@stdlib/math/base/special/round' );
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;
Expand All @@ -40,14 +39,19 @@ var opts = {
// MAIN //

bench( pkg+'::native', opts, function benchmark( b ) {
var opts;
var x;
var y;
var i;

opts = {
'dtype': 'float64'
};
x = discreteUniform( 100, -5.0e6, 5.0e6, opts );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = round( (randu()*1.0e7) - 5.0e6 );
y = isNegativeInteger( x );
y = isNegativeInteger( x[ i%x.length ] );
if ( typeof y !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,18 @@ static double rand_double( void ) {
*/
static double benchmark( void ) {
double elapsed;
double x;
double x[ 100 ];
double t;
bool b;
int i;

for ( i = 0; i < 100; i++ ) {
x[ i ] = ( rand_double() * 200.0 ) - 100.0;
}

t = tic();
for ( i = 0; i < ITERATIONS; i++ ) {
x = ( rand_double() * 200.0 ) - 100.0;
b = stdlib_base_is_negative_integer( x );
b = stdlib_base_is_negative_integer( x[ i%100 ] );
if ( b != true && b != false ) {
printf( "should return either true or false\n" );
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ tape( 'main export is a function', function test( t ) {
tape( 'the function returns `false` if provided a nonnegative integer', function test( t ) {
var i;
for ( i = 0; i < 101; i++ ) {
t.equal( isNegativeInteger( i ), false, 'returns false when provided '+i );
t.equal( isNegativeInteger( i ), false, 'returns expected value when provided '+i );
}
t.end();
});

tape( 'the function returns `true` if provided a negative integer', function test( t ) {
var i;
for ( i = -1; i > -101; i-- ) {
t.equal( isNegativeInteger( i ), true, 'returns true when provided '+i );
t.equal( isNegativeInteger( i ), true, 'returns expected value when provided '+i );
}
t.end();
});
Expand All @@ -58,23 +58,23 @@ tape( 'the function returns `false` if not provided an integer', function test(
for ( i = 0; i < 100; i++ ) {
v = ( randu()*100.0 ) - 50.0;
if ( trunc(v) !== v ) {
t.equal( isNegativeInteger( v ), false, 'returns false when provided '+v );
t.equal( isNegativeInteger( v ), false, 'returns expected value when provided '+v );
}
}
t.end();
});

tape( 'the function returns `false` if provided `NaN`', function test( t ) {
t.equal( isNegativeInteger( NaN ), false, 'returns false' );
t.equal( isNegativeInteger( NaN ), false, 'returns expected value' );
t.end();
});

tape( 'WARNING: the function returns `true` if provided `-infinity`', function test( t ) {
t.equal( isNegativeInteger( NINF ), true, 'returns true' );
t.equal( isNegativeInteger( NINF ), true, 'returns expected value' );
t.end();
});

tape( 'the function returns `false` if provided `+infinity`', function test( t ) {
t.equal( isNegativeInteger( PINF ), false, 'returns false' );
t.equal( isNegativeInteger( PINF ), false, 'returns expected value' );
t.end();
});
Loading