<commit_before>require('buster').spec.expose();
var expect = require('buster').expect;

var combine = require('../lib/combinator/combine').combine;
var map = require('../lib/combinator/transform').map;
var take = require('../lib/combinator/slice').take;
var delay = require('../lib/combinator/delay').delay;
var observe = require('../lib/combinator/observe').observe;
var periodic = require('../lib/source/periodic').periodic;
var streamOf = require('../lib/source/core').of;
var Stream = require('../lib/Stream');

var te = require('./helper/testEnv');

var sentinel = { value: 'sentinel' };

describe('combine', function() {
	it('should yield initial only after all inputs yield', function() {
		var s1 = streamOf(1);
		var s2 = streamOf(sentinel);

		var sc = combine(Array, s1, delay(1, s2));

		return te.collectEvents(sc, te.ticks(2)).then(function(events) {
			expect(events.length).toBe(1);
			expect(events[0].value).toEqual([1, sentinel]);
		});
	});

	it('should yield when any input stream yields', function() {
		var a1 = [0,1,2,3];
		var s1 = map(function() {
			return a1.shift();
		}, periodic(2));

		var a2 = ['a','b','c','d'];
		var s2 = delay(1, map(function() {
			return a2.shift();
		}, periodic(2)));

		var sc = combine(Array, take(a1.length, s1), take(a2.length, s2));

		return te.collectEvents(sc, te.ticks(a1.length+a2.length))
			.then(function(events) {
				expect(events).toEqual([
					{ time: 1, value: [ 0, 'a' ] },
					{ time: 2, value: [ 1, 'a' ] },
					{ time: 3, value: [ 1, 'b' ] },
					{ time: 4, value: [ 2, 'b' ] },
					{ time: 5, value: [ 2, 'c' ] },
					{ time: 6, value: [ 3, 'c' ] },
					{ time: 7, value: [ 3, 'd' ] }
				]);
			});
	});
});
<commit_msg>Add unit tests for combineArray<commit_after>require('buster').spec.expose();
var expect = require('buster').expect;

var combine = require('../lib/combinator/combine');
var map = require('../lib/combinator/transform').map;
var take = require('../lib/combinator/slice').take;
var delay = require('../lib/combinator/delay').delay;
var observe = require('../lib/combinator/observe').observe;
var periodic = require('../lib/source/periodic').periodic;
var streamOf = require('../lib/source/core').of;
var Stream = require('../lib/Stream');

var te = require('./helper/testEnv');

var sentinel = { value: 'sentinel' };

describe('combine', function() {
	it('should yield initial only after all inputs yield', function() {
		var s1 = streamOf(1);
		var s2 = streamOf(sentinel);

		var sc = combine.combine(Array, s1, delay(1, s2));

		return te.collectEvents(sc, te.ticks(2)).then(function(events) {
			expect(events.length).toBe(1);
			expect(events[0].value).toEqual([1, sentinel]);
		});
	});

	it('should yield when any input stream yields', function() {
		var a1 = [0,1,2,3];
		var s1 = map(function() {
			return a1.shift();
		}, periodic(2));

		var a2 = ['a','b','c','d'];
		var s2 = delay(1, map(function() {
			return a2.shift();
		}, periodic(2)));

		var sc = combine.combine(Array, take(a1.length, s1), take(a2.length, s2));

		return te.collectEvents(sc, te.ticks(a1.length+a2.length))
			.then(function(events) {
				expect(events).toEqual([
					{ time: 1, value: [ 0, 'a' ] },
					{ time: 2, value: [ 1, 'a' ] },
					{ time: 3, value: [ 1, 'b' ] },
					{ time: 4, value: [ 2, 'b' ] },
					{ time: 5, value: [ 2, 'c' ] },
					{ time: 6, value: [ 3, 'c' ] },
					{ time: 7, value: [ 3, 'd' ] }
				]);
			});
	});
});

describe('combineArray', function() {
	it('should yield initial only after all inputs yield', function() {
		var s1 = streamOf(1);
		var s2 = streamOf(sentinel);

		var sc = combine.combineArray(Array, [s1, delay(1, s2)]);

		return te.collectEvents(sc, te.ticks(2)).then(function(events) {
			expect(events.length).toBe(1);
			expect(events[0].value).toEqual([1, sentinel]);
		});
	});

	it('should yield when any input stream yields', function() {
		var a1 = [0,1,2,3];
		var s1 = map(function() {
			return a1.shift();
		}, periodic(2));

		var a2 = ['a','b','c','d'];
		var s2 = delay(1, map(function() {
			return a2.shift();
		}, periodic(2)));

		var sc = combine.combineArray(Array, [take(a1.length, s1), take(a2.length, s2)]);

		return te.collectEvents(sc, te.ticks(a1.length+a2.length))
			.then(function(events) {
				expect(events).toEqual([
					{ time: 1, value: [ 0, 'a' ] },
					{ time: 2, value: [ 1, 'a' ] },
					{ time: 3, value: [ 1, 'b' ] },
					{ time: 4, value: [ 2, 'b' ] },
					{ time: 5, value: [ 2, 'c' ] },
					{ time: 6, value: [ 3, 'c' ] },
					{ time: 7, value: [ 3, 'd' ] }
				]);
			});
	});
});

{'fraction_non_alphanumeric': 0.22292576419213975, 'fraction_numerical': 0.02816593886462882, 'mean_word_length': 3.486777668952008, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6137655', 'n_tokens_mistral': 1942, 'n_tokens_neox': 1683, 'n_words': 383}