UNPKG

covertable

Version:

Efficient TypeScript library for pairwise testing, generating minimal covering arrays with constraint support.

98 lines (97 loc) 2.31 kB
function a(t) { if (typeof t == "object" && t !== null) { if ("__val" in t) return { value: t.value }; if ("operator" in t) return { operand: t }; } return typeof t == "string" && t.startsWith("$") ? { operand: t.slice(1) } : { value: t }; } function l(t, r, e) { const n = a(r), u = a(e), i = "operand" in n ? n.operand : n.value; return "operand" in u ? { operator: t, left: i, right: u.operand } : { operator: t, left: i, value: u.value }; } function o(t, r, e) { const n = a(r), u = a(e), i = "operand" in n ? n.operand : n.value; return "operand" in u ? { operator: t, left: i, right: u.operand } : { operator: t, left: i, value: u.value }; } function d(t, r) { let e = o(t, r[0], r[1]); for (let n = 2; n < r.length; n++) { const u = a(r[n]); "operand" in u ? e = { operator: t, left: e, right: u.operand } : e = { operator: t, left: e, value: u.value }; } return e; } class f { // -- comparison -- eq(r, e) { return l("eq", r, e); } ne(r, e) { return l("ne", r, e); } gt(r, e) { return l("gt", r, e); } lt(r, e) { return l("lt", r, e); } gte(r, e) { return l("gte", r, e); } lte(r, e) { return l("lte", r, e); } in(r, e) { const n = a(r); return { operator: "in", left: "operand" in n ? n.operand : n.value, values: e }; } // -- logical -- and(...r) { return { operator: "and", conditions: r }; } or(...r) { return { operator: "or", conditions: r }; } not(r) { return { operator: "not", condition: r }; } // -- binary arithmetic -- add(r, e) { return o("add", r, e); } sub(r, e) { return o("sub", r, e); } mul(r, e) { return o("mul", r, e); } div(r, e) { return o("div", r, e); } mod(r, e) { return o("mod", r, e); } pow(r, e) { return o("pow", r, e); } // -- variadic arithmetic -- sum(...r) { if (r.length < 2) throw new Error("sum() requires at least 2 arguments"); return d("add", r); } product(...r) { if (r.length < 2) throw new Error("product() requires at least 2 arguments"); return d("mul", r); } // -- fn -- fn(r, e) { return { operator: "fn", requires: r, evaluate: e }; } // -- literal -- val(r) { return { __val: !0, value: r }; } } export { f as Constraint };