<commit_before>'use strict';

// MODULES //

var tape = require( 'tape' );
var round = require( '@stdlib/math/base/special/round' );
var kstest = require( '@stdlib/math/generics/statistics/kstest' );
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( 'if provided a value which is not an object, the factory function throws an error', function test( t ) {
	var values;
	var i;

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

	for ( i = 0; i < values.length; i++ ) {
		t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] );
	}
	t.end();

	function badValue( value ) {
		return function badValue() {
			factory( value );
		};
	}
});

tape( 'the function throws an error if provided an unrecognized/unsupported PRNG name', function test( t ) {
	var values;
	var i;

	values = [
		'beep',
		'boop',
		'foo',
		'bar'
	];

	for ( i = 0; i < values.length; i++ ) {
		t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] );
	}
	t.end();

	function badValue( value ) {
		return function badValue() {
			factory({
				'name': value
			});
		};
	}
});

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

	randn = factory();
	for ( i = 0; i < 1e3; i++ ) {
		v = randn();
		t.equal( typeof v, 'number', 'returns a number' );
	}
	t.end();
});

tape( 'the function returns a seeded pseudorandom number generator', function test( t ) {
	var randu1;
	var randu2;
	var seed;
	var v1;
	var v2;
	var i;

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

	randu1 = factory({
		'seed': seed
	});
	randu2 = factory({
		'seed': seed
	});

	t.notEqual( randu1, randu2, 'separate generators' );

	for ( i = 0; i < 1e3; i++ ) {
		v1 = randu1();
		v2 = randu2();
		t.equal( v1, v2, 'both return same number' );
	}
	t.end();
});

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

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

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

tape( 'the function supports specifying the underlying PRNG', function test( t ) {
	var randn;
	var v;
	var i;

	randn = factory({
		'name': 'box-muller'
	});

	t.equal( randn.PRNG.NAME, 'box-muller', 'expected `PRNG` value' );

	for ( i = 0; i < 1e3; i++ ) {
		v = randn();
		t.equal( typeof v, 'number', 'returns a number' );
	}
	t.end();
});

tape( 'the function returns a PRNG for generating pseudorandom numbers from the specified normal distribution', opts, function test( t ) {
	var rejected;
	var pValue;
	var randn;
	var N;
	var i;
	var j;
	var x;

	rejected = 0;
	x = new Array( 1e3 );
	N = 300;
	for ( i = 0; i < N; i++ ) {
		randn = factory();
		t.ok( true, 'seed: '+randn.SEED );
		for ( j = 0; j < x.length; j++ ) {
			x[ j ] = randn();
		}
		// Test using Kolmogorov-Smirnov goodness-of-fit test:
		pValue = kstest( x, 'normal', 0.0, 1.0 ).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 Normal(0,1)) is rejected in less than 10% of cases ('+rejected+' of '+N+')' );
	t.end();
});
<commit_msg>Update test description<commit_after>'use strict';

// MODULES //

var tape = require( 'tape' );
var round = require( '@stdlib/math/base/special/round' );
var kstest = require( '@stdlib/math/generics/statistics/kstest' );
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( 'if provided a value which is not an object, the factory function throws an error', function test( t ) {
	var values;
	var i;

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

	for ( i = 0; i < values.length; i++ ) {
		t.throws( badValue( values[i] ), TypeError, 'throws a type error when provided '+values[i] );
	}
	t.end();

	function badValue( value ) {
		return function badValue() {
			factory( value );
		};
	}
});

tape( 'the function throws an error if provided an unrecognized/unsupported PRNG name', function test( t ) {
	var values;
	var i;

	values = [
		'beep',
		'boop',
		'foo',
		'bar'
	];

	for ( i = 0; i < values.length; i++ ) {
		t.throws( badValue( values[i] ), Error, 'throws an error when provided '+values[i] );
	}
	t.end();

	function badValue( value ) {
		return function badValue() {
			factory({
				'name': value
			});
		};
	}
});

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

	randn = factory();
	for ( i = 0; i < 1e3; i++ ) {
		v = randn();
		t.equal( typeof v, 'number', 'returns a number' );
	}
	t.end();
});

tape( 'the function returns a seeded pseudorandom number generator', function test( t ) {
	var randu1;
	var randu2;
	var seed;
	var v1;
	var v2;
	var i;

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

	randu1 = factory({
		'seed': seed
	});
	randu2 = factory({
		'seed': seed
	});

	t.notEqual( randu1, randu2, 'separate generators' );

	for ( i = 0; i < 1e3; i++ ) {
		v1 = randu1();
		v2 = randu2();
		t.equal( v1, v2, 'both return same number' );
	}
	t.end();
});

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

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

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

tape( 'the function supports specifying the underlying PRNG', function test( t ) {
	var randn;
	var v;
	var i;

	randn = factory({
		'name': 'box-muller'
	});

	t.equal( randn.PRNG.NAME, 'box-muller', 'expected `PRNG` value' );

	for ( i = 0; i < 1e3; i++ ) {
		v = randn();
		t.equal( typeof v, 'number', 'returns a number' );
	}
	t.end();
});

tape( 'the function returns a PRNG for generating pseudorandom numbers from a standard normal distribution', opts, function test( t ) {
	var rejected;
	var pValue;
	var randn;
	var N;
	var i;
	var j;
	var x;

	rejected = 0;
	x = new Array( 1e3 );
	N = 300;
	for ( i = 0; i < N; i++ ) {
		randn = factory();
		t.ok( true, 'seed: '+randn.SEED );
		for ( j = 0; j < x.length; j++ ) {
			x[ j ] = randn();
		}
		// Test using Kolmogorov-Smirnov goodness-of-fit test:
		pValue = kstest( x, 'normal', 0.0, 1.0 ).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 Normal(0,1)) is rejected in less than 10% of cases ('+rejected+' of '+N+')' );
	t.end();
});

{'fraction_non_alphanumeric': 0.17515883891864956, 'fraction_numerical': 0.016444499813130686, 'mean_word_length': 3.192167101827676, 'pattern_counts': {'":': 0, '<': 21, '<?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': '2277192', 'n_tokens_mistral': 3263, 'n_tokens_neox': 3030, 'n_words': 990}