<commit_before>'use strict';

// MODULES //

var tape = require( 'tape' );
var kstest = require( '@stdlib/math/generics/statistics/kstest' );
var round = require( '@stdlib/math/base/special/round' );
var isnan = require( '@stdlib/math/base/utils/is-nan' );
var factory = require( './../lib/factory.js' );


// VARIABLES //

var opts = {
	'skip': ( process.env.TEST_MODE === 'coverage' )
};


// TESTS //

tape( 'main export is a function', function test( t ) {
	t.ok( true, __filename );
	t.equal( typeof factory, 'function', 'main export is a function' );
	t.end();
});

tape( 'the function returns a pseudorandom number generator (no seed)', function test( t ) {
	var exponential;
	var r;
	var i;

	// When binding distribution parameter...
	exponential = factory( 2.0 );
	for ( i = 0; i < 100; i++ ) {
		r = exponential();
		t.equal( typeof r, 'number', 'returns a number' );
	}

	// Without binding distribution parameter...
	exponential = factory();
	for ( i = 0; i < 100; i++ ) {
		r = exponential( 100.0 );
		t.equal( typeof r, 'number', 'returns a number' );
	}

	t.end();
});

tape( 'the function returns a seeded pseudorandom number generator', function test( t ) {
	var exponential1;
	var exponential2;
	var seed;
	var r1;
	var r2;
	var i;

	seed = round( Date.now() / 1000 );

	exponential1 = factory( 35.0, {
		'seed': seed
	});
	exponential2 = factory( 35.0, {
		'seed': seed
	});

	t.notEqual( exponential1, exponential2, 'separate generators' );

	for ( i = 0; i < 100; i++ ) {
		r1 = exponential1();
		r2 = exponential2();
		t.equal( r1, r2, 'both return same number' );
	}
	t.end();
});

tape( 'attached to the returned function is the generator name', function test( t ) {
	var exponential = factory();
	t.equal( exponential.NAME, 'exponential', 'has `NAME` property' );
	t.end();
});

tape( 'attached to the returned function is the underlying PRNG', function test( t ) {
	var exponential = factory();
	t.equal( typeof exponential.PRNG, 'function', 'has `PRNG` property' );
	t.end();
});

tape( 'attached to the returned function is the generator seed', function test( t ) {
	var exponential = factory({
		'seed': 12345
	});
	t.equal( typeof exponential.SEED, 'number', 'has `SEED` property' );
	t.equal( exponential.SEED, 12345, 'equal to provided seed' );
	t.end();
});

tape( 'the function throws an error if provided a rate which is not a positive number (no options)', function test( t ) {
	var values;
	var i;

	values = [
		-2.0,
		0.0,
		NaN,
		'5',
		null,
		true,
		undefined,
		[],
		function(){}
	];

	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() {
			factory( value );
		};
	}
});

tape( 'the function throws an error if provided a rate which is not a positive number (options)', function test( t ) {
	var values;
	var i;

	values = [
		-2.0,
		0.0,
		NaN,
		'5',
		null,
		true,
		undefined,
		[],
		function(){}
	];

	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() {
			factory( value, {} );
		};
	}
});

tape( 'the function throws an error if provided an options argument which is not object (when `lambda` is not supplied)', function test( t ) {
	var values;
	var i;

	values = [
		'abc',
		null,
		true,
		undefined,
		NaN,
		[],
		function(){}
	];

	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() {
			factory( value );
		};
	}
});

tape( 'the function throws an error if provided an options argument which is not an object (when `lambda` is supplied)', function test( t ) {
	var values;
	var i;

	values = [
		'abc',
		5,
		null,
		true,
		undefined,
		NaN,
		[],
		function(){}
	];

	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() {
			factory( 10.0, value );
		};
	}
});

tape( 'when called without arguments, the function returns a PRNG that returns `NaN` when provided a rate equal to `NaN`', function test( t ) {
	var exponential;
	var r;

	exponential = factory();
	r = exponential( NaN );

	t.strictEqual( isnan( r ), true, 'returns NaN' );
	t.end();
});

tape( 'when called without arguments, the function returns a PRNG that returns `NaN` when provided a rate which is not a positive number', function test( t ) {
	var exponential;
	var r;

	exponential = factory();

	r = exponential( 0 );
	t.strictEqual( isnan( r ), true, 'returns NaN' );

	r = exponential( -1 );
	t.strictEqual( isnan( r ), true, 'returns NaN' );

	r = exponential( -3.14 );
	t.strictEqual( isnan( r ), true, 'returns NaN' );

	t.end();
});

tape( 'the function returns a PRNG for generating random numbers from an exponential distribution', opts, function test( t ) {
	var exponential;
	var rejected;
	var pValue;
	var lambda;
	var N;
	var i;
	var j;
	var x;

	lambda = 4.0;
	exponential = factory( lambda, {
		'seed': 675
	});

	x = new Array( 1e3 );
	rejected = 0;
	N = 300;
	for ( i = 0; i < N; i++ ) {
		for ( j = 0; j < x.length; j++ ) {
			x[ j ] = exponential();
		}
		// Test using Kolmogorov-Smirnov goodness-of-fit test:
		pValue = kstest( x, 'exponential', lambda ).pValue;
		t.equal( typeof pValue, 'number', 'returns a p-value' );
		if ( pValue < 0.05 ) {
			rejected += 1;
		}
	}
	// Account for small sample sizes and few repeats...
	t.ok( rejected / N < 0.10, 'null hypothesis (i.e., that numbers are drawn from Exponential('+lambda+') is rejected in less than 10% of cases ('+rejected+' of '+N+')' );
	t.end();
});<commit_msg>Run KS tests with different seeds<commit_after>'use strict';

// MODULES //

var tape = require( 'tape' );
var kstest = require( '@stdlib/math/generics/statistics/kstest' );
var round = require( '@stdlib/math/base/special/round' );
var isnan = require( '@stdlib/math/base/utils/is-nan' );
var factory = require( './../lib/factory.js' );


// VARIABLES //

var opts = {
	'skip': ( process.env.TEST_MODE === 'coverage' )
};


// TESTS //

tape( 'main export is a function', function test( t ) {
	t.ok( true, __filename );
	t.equal( typeof factory, 'function', 'main export is a function' );
	t.end();
});

tape( 'the function returns a pseudorandom number generator (no seed)', function test( t ) {
	var exponential;
	var r;
	var i;

	// When binding distribution parameter...
	exponential = factory( 2.0 );
	for ( i = 0; i < 100; i++ ) {
		r = exponential();
		t.equal( typeof r, 'number', 'returns a number' );
	}

	// Without binding distribution parameter...
	exponential = factory();
	for ( i = 0; i < 100; i++ ) {
		r = exponential( 100.0 );
		t.equal( typeof r, 'number', 'returns a number' );
	}

	t.end();
});

tape( 'the function returns a seeded pseudorandom number generator', function test( t ) {
	var exponential1;
	var exponential2;
	var seed;
	var r1;
	var r2;
	var i;

	seed = round( Date.now() / 1000 );

	exponential1 = factory( 35.0, {
		'seed': seed
	});
	exponential2 = factory( 35.0, {
		'seed': seed
	});

	t.notEqual( exponential1, exponential2, 'separate generators' );

	for ( i = 0; i < 100; i++ ) {
		r1 = exponential1();
		r2 = exponential2();
		t.equal( r1, r2, 'both return same number' );
	}
	t.end();
});

tape( 'attached to the returned function is the generator name', function test( t ) {
	var exponential = factory();
	t.equal( exponential.NAME, 'exponential', 'has `NAME` property' );
	t.end();
});

tape( 'attached to the returned function is the underlying PRNG', function test( t ) {
	var exponential = factory();
	t.equal( typeof exponential.PRNG, 'function', 'has `PRNG` property' );
	t.end();
});

tape( 'attached to the returned function is the generator seed', function test( t ) {
	var exponential = factory({
		'seed': 12345
	});
	t.equal( typeof exponential.SEED, 'number', 'has `SEED` property' );
	t.equal( exponential.SEED, 12345, 'equal to provided seed' );
	t.end();
});

tape( 'the function throws an error if provided a rate which is not a positive number (no options)', function test( t ) {
	var values;
	var i;

	values = [
		-2.0,
		0.0,
		NaN,
		'5',
		null,
		true,
		undefined,
		[],
		function(){}
	];

	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() {
			factory( value );
		};
	}
});

tape( 'the function throws an error if provided a rate which is not a positive number (options)', function test( t ) {
	var values;
	var i;

	values = [
		-2.0,
		0.0,
		NaN,
		'5',
		null,
		true,
		undefined,
		[],
		function(){}
	];

	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() {
			factory( value, {} );
		};
	}
});

tape( 'the function throws an error if provided an options argument which is not object (when `lambda` is not supplied)', function test( t ) {
	var values;
	var i;

	values = [
		'abc',
		null,
		true,
		undefined,
		NaN,
		[],
		function(){}
	];

	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() {
			factory( value );
		};
	}
});

tape( 'the function throws an error if provided an options argument which is not an object (when `lambda` is supplied)', function test( t ) {
	var values;
	var i;

	values = [
		'abc',
		5,
		null,
		true,
		undefined,
		NaN,
		[],
		function(){}
	];

	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() {
			factory( 10.0, value );
		};
	}
});

tape( 'when called without arguments, the function returns a PRNG that returns `NaN` when provided a rate equal to `NaN`', function test( t ) {
	var exponential;
	var r;

	exponential = factory();
	r = exponential( NaN );

	t.strictEqual( isnan( r ), true, 'returns NaN' );
	t.end();
});

tape( 'when called without arguments, the function returns a PRNG that returns `NaN` when provided a rate which is not a positive number', function test( t ) {
	var exponential;
	var r;

	exponential = factory();

	r = exponential( 0 );
	t.strictEqual( isnan( r ), true, 'returns NaN' );

	r = exponential( -1 );
	t.strictEqual( isnan( r ), true, 'returns NaN' );

	r = exponential( -3.14 );
	t.strictEqual( isnan( r ), true, 'returns NaN' );

	t.end();
});

tape( 'the function returns a PRNG for generating random numbers from an exponential distribution', opts, function test( t ) {
	var exponential;
	var rejected;
	var pValue;
	var lambda;
	var N;
	var i;
	var j;
	var x;

	lambda = 4.0;

	x = new Array( 1e3 );
	rejected = 0;
	N = 300;
	for ( i = 0; i < N; i++ ) {
		exponential = factory( lambda );
		t.ok( true, 'seed: '+exponential.SEED );
		for ( j = 0; j < x.length; j++ ) {
			x[ j ] = exponential();
		}
		// Test using Kolmogorov-Smirnov goodness-of-fit test:
		pValue = kstest( x, 'exponential', lambda ).pValue;
		t.equal( typeof pValue, 'number', 'returns a p-value: '+pValue );
		if ( pValue < 0.05 ) {
			rejected += 1;
		}
	}
	// Account for small sample sizes and few repeats...
	t.ok( rejected / N < 0.10, 'null hypothesis (i.e., that numbers are drawn from Exponential('+lambda+') is rejected in less than 10% of cases ('+rejected+' of '+N+')' );
	t.end();
});
{'fraction_non_alphanumeric': 0.16335540838852097, 'fraction_numerical': 0.016216675157072508, 'mean_word_length': 3.2786051580094444, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '141408', 'n_tokens_mistral': 4528, 'n_tokens_neox': 4126, 'n_words': 1426}