'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var ceil = require( '@stdlib/math/base/special/ceil' );
var randu = require( '@stdlib/math/base/random/randu' );
var isnan = require( '@stdlib/math/base/utils/is-nan' );
var isProbability = require( '@stdlib/math/base/utils/is-probability' );
var EPS = require( '@stdlib/math/constants/float64-eps' );
var pkg = require( './../package.json' ).name;
var cdf = require( './../lib' );


// MAIN //

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

	b.tic();
	for ( i = 0; i < b.iterations; i++ ) {
		x = randu() * 100.0;
		n = ceil( randu()*100.0 );
		p = ( randu()*1.0 ) + EPS;
		y = cdf( x, n, p );
		if ( isnan( y ) ) {
			b.fail( 'should not return NaN' );
		}
		if ( !isProbability( y ) ) {
			b.fail( 'should not return a number outside `[0,1]`' );
		}
	}
	b.toc();
	if ( isnan( y ) ) {
		b.fail( 'should not return NaN' );
	}
	else if ( isProbability( y ) ) {
		b.pass( 'benchmark finished' );
	}
	else {
		b.fail( 'should not return a number outside `[0,1]`' );
	}
	b.end();
});

bench( pkg+':factory', function benchmark( b ) {
	var mycdf;
	var n;
	var p;
	var x;
	var y;
	var i;

	n = 80;
	p = 0.4;
	mycdf = cdf.factory( n, p );

	b.tic();
	for ( i = 0; i < b.iterations; i++ ) {
		x = randu() * 80.0;
		y = mycdf( x );
		if ( isnan( y ) ) {
			b.fail( 'should not return NaN' );
		}
		if ( !isProbability( y ) ) {
			b.fail( 'should not return a number outside `[0,1]`' );
		}
	}
	b.toc();
	if ( isnan( y ) ) {
		b.fail( 'should not return NaN' );
	}
	else if ( isProbability( y ) ) {
		b.pass( 'benchmark finished' );
	}
	else {
		b.fail( 'should not return a number outside `[0,1]`' );
	}
	b.end();
});

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var ceil = require( '@stdlib/math/base/special/ceil' );
var randu = require( '@stdlib/math/base/random/randu' );
var isnan = require( '@stdlib/math/base/utils/is-nan' );
var EPS = require( '@stdlib/math/constants/float64-eps' );
var pkg = require( './../package.json' ).name;
var cdf = require( './../lib' );


// MAIN //

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

	b.tic();
	for ( i = 0; i < b.iterations; i++ ) {
		x = randu() * 100.0;
		n = ceil( randu()*100.0 );
		p = ( randu()*1.0 ) + EPS;
		y = cdf( x, n, p );
		if ( isnan( y ) ) {
			b.fail( 'should not return NaN' );
		}
	}
	b.toc();
	if ( isnan( y ) ) {
		b.fail( 'should not return NaN' );
	}
	b.pass( 'benchmark finished' );
	b.end();
});

bench( pkg+':factory', function benchmark( b ) {
	var mycdf;
	var n;
	var p;
	var x;
	var y;
	var i;

	n = 80;
	p = 0.4;
	mycdf = cdf.factory( n, p );

	b.tic();
	for ( i = 0; i < b.iterations; i++ ) {
		x = randu() * 80.0;
		y = mycdf( x );
		if ( isnan( y ) ) {
			b.fail( 'should not return NaN' );
		}
	}
	b.toc();
	if ( isnan( y ) ) {
		b.fail( 'should not return NaN' );
	}
	b.pass( 'benchmark finished' );
	b.end();
});

Remove probability checks