<commit_before>
// MODULES //

var // Expectation library:
	chai = require( 'chai' ),

	// Test utilities:
	utils = require( './utils' ),

	// Module to be tested:
	mStream = require( './../lib/stats/mean' );


// VARIABLES //

var expect = chai.expect,
	assert = chai.assert;


// TESTS //

describe( 'stats/mean', function tests() {
	'use strict';

	it( 'should export a factory function', function test() {
		expect( mStream ).to.be.a( 'function' );
	});

	it( 'should provide a method to get the initial accumulator value', function test() {
		var rStream = mStream();
		assert.strictEqual( rStream.value(), 0 );
	});

	it( 'should provide a method to get the initial accumulator value number', function test() {
		var rStream = mStream();
		assert.strictEqual( rStream.numValues(), 0 );
	});

	it( 'should provide a method to set the initial accumulator value', function test() {
		var rStream = mStream();
		rStream.value( 5 );
		assert.strictEqual( rStream.value(), 5 );
	});

	it( 'should not allow a non-numeric initial accumulator value', function test() {
		var rStream = mStream();
		
		expect( badValue( '5' ) ).to.throw( Error );
		expect( badValue( [] ) ).to.throw( Error );
		expect( badValue( {} ) ).to.throw( Error );
		expect( badValue( null ) ).to.throw( Error );
		expect( badValue( undefined ) ).to.throw( Error );
		expect( badValue( NaN ) ).to.throw( Error );

		function badValue( value ) {
			return function() {
				rStream.value( value );
			};
		}
	});

	it( 'should provide a method to set the initial accumulator value number', function test() {
		var rStream = mStream();
		rStream.numValues( 5 );
		assert.strictEqual( rStream.numValues(), 5 );
	});

	it( 'should not allow a non-numeric initial accumulator value number', function test() {
		var rStream = mStream();
		
		expect( badValue( '5' ) ).to.throw( Error );
		expect( badValue( [] ) ).to.throw( Error );
		expect( badValue( {} ) ).to.throw( Error );
		expect( badValue( null ) ).to.throw( Error );
		expect( badValue( undefined ) ).to.throw( Error );
		expect( badValue( NaN ) ).to.throw( Error );

		function badValue( value ) {
			return function() {
				rStream.numValues( value );
			};
		}
	});

	it( 'should calculate the mean of piped data', function test( done ) {
		var data, rStream, MEAN = 3.5;

		// Simulate some data...
		data = [ 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5 ];

		// Create a new mean stream:
		rStream = mStream().stream();

		// Mock reading from the stream:
		utils.readStream( rStream, onRead );

		// Mock piping a data to the stream:
		utils.writeStream( data, rStream );

		return;

		/**
		* FUNCTION: onRead( error, actual )
		*	Read event handler. Checks for errors and compares streamed data to expected data.
		*/
		function onRead( error, actual ) {
			expect( error ).to.not.exist;
			assert.closeTo( actual[ 0 ], MEAN, 0.001 );
			done();
		} // end FUNCTION onRead()
	});

	it( 'should calculate the mean of piped data using an arbitrary starting mean value and corresponding number of values the mean represents', function test( done ) {
		var data, reducer, rStream,
			MEAN = 10000,
			NUMVALUES = 100,
			INIT = MEAN,
			sum;

		// Simulate some data...
		data = [ 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5 ];
		
		sum = MEAN * NUMVALUES;
		for ( var i = 0; i < data.length; i++ ) {
			sum += data[ i ];
		}
		MEAN = sum / (data.length+NUMVALUES);
			
		// Create a new mean stream generator:
		reducer = mStream();

		// Set the initial mean and create a new stream:
		rStream = reducer
			.value( INIT )
			.numValues( NUMVALUES )
			.stream();

		// Mock reading from the stream:
		utils.readStream( rStream, onRead );

		// Mock piping a data to the stream:
		utils.writeStream( data, rStream );

		return;

		/**
		* FUNCTION: onRead( error, actual )
		*	Read event handler. Checks for errors and compares streamed data to expected data.
		*/
		function onRead( error, actual ) {
			expect( error ).to.not.exist;
			assert.closeTo( actual[ 0 ], MEAN, 0.0001 );
			done();
		} // end FUNCTION onRead()
	});

});<commit_msg>[UPDATE] do not assume default initial values.<commit_after>
// MODULES //

var // Expectation library:
	chai = require( 'chai' ),

	// Test utilities:
	utils = require( './utils' ),

	// Module to be tested:
	mStream = require( './../lib/stats/mean' );


// VARIABLES //

var expect = chai.expect,
	assert = chai.assert;


// TESTS //

describe( 'stats/mean', function tests() {
	'use strict';

	it( 'should export a factory function', function test() {
		expect( mStream ).to.be.a( 'function' );
	});

	it( 'should provide a method to get the initial accumulator value', function test() {
		var rStream = mStream();
		expect( rStream.value() ).to.be.a( 'number' );
	});

	it( 'should provide a method to get the initial accumulator value number', function test() {
		var rStream = mStream();
		expect( rStream.numValues() ).to.be.a( 'number' );
	});

	it( 'should provide a method to set the initial accumulator value', function test() {
		var rStream = mStream();
		rStream.value( 5 );
		assert.strictEqual( rStream.value(), 5 );
	});

	it( 'should not allow a non-numeric initial accumulator value', function test() {
		var rStream = mStream();
		
		expect( badValue( '5' ) ).to.throw( Error );
		expect( badValue( [] ) ).to.throw( Error );
		expect( badValue( {} ) ).to.throw( Error );
		expect( badValue( null ) ).to.throw( Error );
		expect( badValue( undefined ) ).to.throw( Error );
		expect( badValue( NaN ) ).to.throw( Error );

		function badValue( value ) {
			return function() {
				rStream.value( value );
			};
		}
	});

	it( 'should provide a method to set the initial accumulator value number', function test() {
		var rStream = mStream();
		rStream.numValues( 5 );
		assert.strictEqual( rStream.numValues(), 5 );
	});

	it( 'should not allow a non-numeric initial accumulator value number', function test() {
		var rStream = mStream();
		
		expect( badValue( '5' ) ).to.throw( Error );
		expect( badValue( [] ) ).to.throw( Error );
		expect( badValue( {} ) ).to.throw( Error );
		expect( badValue( null ) ).to.throw( Error );
		expect( badValue( undefined ) ).to.throw( Error );
		expect( badValue( NaN ) ).to.throw( Error );

		function badValue( value ) {
			return function() {
				rStream.numValues( value );
			};
		}
	});

	it( 'should calculate the mean of piped data', function test( done ) {
		var data, rStream, MEAN = 3.5;

		// Simulate some data...
		data = [ 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5 ];

		// Create a new mean stream:
		rStream = mStream().stream();

		// Mock reading from the stream:
		utils.readStream( rStream, onRead );

		// Mock piping a data to the stream:
		utils.writeStream( data, rStream );

		return;

		/**
		* FUNCTION: onRead( error, actual )
		*	Read event handler. Checks for errors and compares streamed data to expected data.
		*/
		function onRead( error, actual ) {
			expect( error ).to.not.exist;
			assert.closeTo( actual[ 0 ], MEAN, 0.001 );
			done();
		} // end FUNCTION onRead()
	});

	it( 'should calculate the mean of piped data using an arbitrary starting mean value and corresponding number of values the mean represents', function test( done ) {
		var data, reducer, rStream,
			MEAN = 10000,
			NUMVALUES = 100,
			INIT = MEAN,
			sum;

		// Simulate some data...
		data = [ 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5 ];
		
		sum = MEAN * NUMVALUES;
		for ( var i = 0; i < data.length; i++ ) {
			sum += data[ i ];
		}
		MEAN = sum / (data.length+NUMVALUES);
			
		// Create a new mean stream generator:
		reducer = mStream();

		// Set the initial mean and create a new stream:
		rStream = reducer
			.value( INIT )
			.numValues( NUMVALUES )
			.stream();

		// Mock reading from the stream:
		utils.readStream( rStream, onRead );

		// Mock piping a data to the stream:
		utils.writeStream( data, rStream );

		return;

		/**
		* FUNCTION: onRead( error, actual )
		*	Read event handler. Checks for errors and compares streamed data to expected data.
		*/
		function onRead( error, actual ) {
			expect( error ).to.not.exist;
			assert.closeTo( actual[ 0 ], MEAN, 0.0001 );
			done();
		} // end FUNCTION onRead()
	});

});
{'fraction_non_alphanumeric': 0.1509873666135165, 'fraction_numerical': 0.013001349196614742, 'mean_word_length': 3.0088495575221237, 'pattern_counts': {'":': 0, '<': 5, '<?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': '7213786', 'n_tokens_mistral': 3053, 'n_tokens_neox': 2645, 'n_words': 930}