fast-check
Version:
Property based testing framework for JavaScript (like QuickCheck)
46 lines (45 loc) • 1.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.set = exports.buildCompareFilter = void 0;
const ArrayArbitrary_1 = require("./ArrayArbitrary");
function subArrayContains(tab, upperBound, includeValue) {
for (let idx = 0; idx < upperBound; ++idx) {
if (includeValue(tab[idx]))
return true;
}
return false;
}
function swap(tab, idx1, idx2) {
const temp = tab[idx1];
tab[idx1] = tab[idx2];
tab[idx2] = temp;
}
function buildCompareFilter(compare) {
return (tab) => {
let finalLength = tab.length;
for (let idx = tab.length - 1; idx !== -1; --idx) {
if (subArrayContains(tab, idx, (t) => compare(t.value_, tab[idx].value_))) {
--finalLength;
swap(tab, idx, finalLength);
}
}
return tab.slice(0, finalLength);
};
}
exports.buildCompareFilter = buildCompareFilter;
function set(arb, aLength, bLength, compareFn) {
const minLength = bLength == null || typeof bLength !== 'number' ? 0 : aLength;
const maxLength = aLength == null || typeof aLength !== 'number' ? 10 : typeof bLength === 'number' ? bLength : aLength;
const compare = compareFn != null
? compareFn
: typeof bLength === 'function'
? bLength
: typeof aLength === 'function'
? aLength
: (a, b) => a === b;
const arrayArb = new ArrayArbitrary_1.ArrayArbitrary(arb, minLength, maxLength, buildCompareFilter(compare));
if (minLength === 0)
return arrayArb;
return arrayArb.filter((tab) => tab.length >= minLength);
}
exports.set = set;