Set the decision and its input
The original filter is colour red and sizeM. The colour facet counts options among all sizeM records, temporarily excluding the colour filter itself. The supplied records give red2 and blue1. Keeping red active while counting colour choices misleadingly makes blue0.
| Case | Input JSON |
|---|---|
| Base test | {"facet":"colour","filters":{"colour":"red","size":"M"},"records":[{"colour":"red","size":"M"},{"colour":"red","size":"M"},{"colour":"blue","size":"M"},{"colour":"blue","size":"L"}]} |
Run the supplied comparison
The executed local function applies the declared facet context. These are counts of choices available under the other filters, not totals for the already-selected red result.
| Path | Output JSON |
|---|---|
| Faulty path | {"counts":{"red":2,"blue":0}} |
| Required path | {"counts":{"red":2,"blue":1}} |
import assert from 'node:assert/strict';
const run=function run(i,corrected=true){
if(i.facet!=='colour')return {held:true};
const eligible=i.records.filter(r=>r.size===i.filters.size&&(!corrected?r.colour===i.filters.colour:true));
return {counts:{red:eligible.filter(r=>r.colour==='red').length,blue:eligible.filter(r=>r.colour==='blue').length}};
};
const cases=[{"input":{"facet":"colour","filters":{"colour":"red","size":"M"},"records":[{"colour":"red","size":"M"},{"colour":"red","size":"M"},{"colour":"blue","size":"M"},{"colour":"blue","size":"L"}]},"corrected":false,"expected":{"counts":{"red":2,"blue":0}}},{"input":{"facet":"colour","filters":{"colour":"red","size":"M"},"records":[{"colour":"red","size":"M"},{"colour":"red","size":"M"},{"colour":"blue","size":"M"},{"colour":"blue","size":"L"}]},"corrected":true,"expected":{"counts":{"red":2,"blue":1}}},{"input":{"facet":"colour","filters":{"colour":"red","size":"L"},"records":[{"colour":"red","size":"M"},{"colour":"blue","size":"L"}]},"corrected":true,"expected":{"counts":{"red":0,"blue":1}}},{"input":{"facet":null,"filters":{"colour":"red","size":"M"},"records":[]},"corrected":true,"expected":{"held":true}}];
for(const test of cases){const actual=await run(test.input,test.corrected);assert.deepEqual(actual,test.expected);console.log(actual);}
Choose from the boundary evidence
SizeL retains that filter and yields red0/blue1. An unsupported requested facet is held rather than reusing a colour rule.
- Name the facet being counted
- Remove only its own filter
- Count under retained filters
Do not remove every filter to inflate option counts.
| Condition | Input JSON | Expected output JSON |
|---|---|---|
| retain the other facet filter | {"facet":"colour","filters":{"colour":"red","size":"L"},"records":[{"colour":"red","size":"M"},{"colour":"blue","size":"L"}]} | {"counts":{"red":0,"blue":1}} |
| unsupported requested facet | {"facet":null,"filters":{"colour":"red","size":"M"},"records":[]} | {"held":true} |
What colour counts should the base widget show?
Show the worked answer
Red2 and blue1, because all three sizeM rows remain eligible when only the colour filter is removed.