Home Manual Reference Source

src/tester.js

import {increasing, decreasing} from '@total-order/primitive';
import {map} from '@iterable-iterator/map';
import {_chain as chain} from '@iterable-iterator/chain';
import {list} from '@iterable-iterator/list';
import {exhaust} from '@iterable-iterator/consume';
import {product} from '@set-theory/cartesian-product';
import {
	chain as fchain,
	partial,
	star,
} from '@functional-abstraction/functools';

const DEFAULT_LENGTHS = [
	[0],
	[1],
	[16],
	[17],
	[31],
	[32],
	[33],
	[63],
	[64],
	[65],
];

export function tester(method) {
	return function (_test, length, heaps, lengths) {
		if (lengths === undefined) lengths = DEFAULT_LENGTHS;

		exhaust(
			map(
				fchain([chain, list, partial(star, [method])]),
				product(
					[
						[[_test, length]],

						heaps,

						[
							['increasing', increasing],
							['decreasing', decreasing],
						],

						lengths,
					],
					1,
				),
			),
		);
	};
}

export function tester2(method) {
	return function (_test, length, heaps, lengths1, lengths2) {
		if (lengths1 === undefined) lengths1 = DEFAULT_LENGTHS;
		if (lengths2 === undefined) lengths2 = lengths1;

		exhaust(
			map(
				fchain([chain, list, partial(star, [method])]),
				product(
					[
						[[_test, length]],

						heaps,

						[
							['increasing', increasing],
							['decreasing', decreasing],
						],

						lengths1,
						lengths2,
					],
					1,
				),
			),
		);
	};
}