Skip to content
Astera Technology

Check a toy device checksum before code lookup

Keep framing, checksum and catalogue presence separate.

Download complete case notes and answer keys ↓

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.

Filled local test worksheet
CaseInput JSON
Base test{"frame":"12345","catalogue":["12340"]}
Download editable CSV ↓

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.

Faulty and required outputs
PathOutput JSON
Faulty path{"checksumValid":true,"catalogueLookedUp":true,"held":false,"found":false}
Required path{"checksumValid":false,"catalogueLookedUp":false,"held":true,"reason":"check-digit"}
Download editable CSV ↓
Complete local Node24.14.1 programme
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);}
Download runnable example ↓

Choose from the boundary evidence

12340 passes and exists.22228 passes its checksum but is absent from the supplied catalogue, so remains held.

  1. Check the five-digit frame
  2. Calculate the toy checksum
  3. Look up admitted codes

The toy rule does not certify a real identifier standard.

Editable boundary inputs and outputs
ConditionInput JSONExpected 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}
Download editable CSV ↓

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.

Related resources