Set the decision and its input
The original five-digit toy code uses its last digit as the first four digits’ sum modulo ten.12345 is framed correctly but requires check digit0, so it is held before lookup. This is a fictional grammar, not an industry barcode specification.
| Case | Input JSON |
|---|---|
| Base test | {"frame":"12345","catalogue":["12340"]} |
Run the supplied comparison
The code calculates the checksum and reports whether lookup happened. A valid checksum only admits the frame to the next check; it cannot establish item identity.
| Path | Output JSON |
|---|---|
| Faulty path | {"checksumValid":true,"catalogueLookedUp":true,"held":false,"found":false} |
| Required path | {"checksumValid":false,"catalogueLookedUp":false,"held":true,"reason":"check-digit"} |
import assert from 'node:assert/strict';
const run=function run(i,corrected=true){
if(!/^\d{5}$/.test(i.frame))return {held:true,reason:'frame-grammar'};
const valid=([...i.frame.slice(0,4)].reduce((s,c)=>s+Number(c),0)%10)===Number(i.frame[4]);
if(corrected&&!valid)return {checksumValid:false,catalogueLookedUp:false,held:true,reason:'check-digit'};
const found=i.catalogue.includes(i.frame);return {checksumValid:corrected?valid:true,catalogueLookedUp:true,held:corrected?!found:false,found};
};
const cases=[{"input":{"frame":"12345","catalogue":["12340"]},"corrected":false,"expected":{"checksumValid":true,"catalogueLookedUp":true,"held":false,"found":false}},{"input":{"frame":"12345","catalogue":["12340"]},"corrected":true,"expected":{"checksumValid":false,"catalogueLookedUp":false,"held":true,"reason":"check-digit"}},{"input":{"frame":"12340","catalogue":["12340"]},"corrected":true,"expected":{"checksumValid":true,"catalogueLookedUp":true,"held":false,"found":true}},{"input":{"frame":"22228","catalogue":["12340"]},"corrected":true,"expected":{"checksumValid":true,"catalogueLookedUp":true,"held":true,"found":false}}];
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
12340 passes and exists.22228 passes its checksum but is absent from the supplied catalogue, so remains held.
- Check the five-digit frame
- Calculate the toy checksum
- Look up admitted codes
The toy rule does not certify a real identifier standard.
| Condition | Input JSON | Expected output JSON |
|---|---|---|
| matching toy code | {"frame":"12340","catalogue":["12340"]} | {"checksumValid":true,"catalogueLookedUp":true,"held":false,"found":true} |
| valid checksum but unknown code | {"frame":"22228","catalogue":["12340"]} | {"checksumValid":true,"catalogueLookedUp":true,"held":true,"found":false} |
Should base12345 be labelled an unknown catalogue item?
Show the worked answer
Not yet. It failed checksum admission and no catalogue lookup occurred. Keep that precise failure.