Set the decision and its input
The original grid uses eight dots per millimetre. A supplied 12.3mm dimension maps to 98.4 dots, which is not an executable whole-dot setting. Nearest rounding gives98; ceiling gives99. Neither rule is assumed to be a real printer default.
| Case | Input JSON |
|---|---|
| Base test | {"tenthsMillimetre":123,"dotsPerMillimetre":8,"rounding":"nearest"} |
Run the supplied comparison
The code multiplies the declared tenths-of-millimetre quantity before rounding at the device grid. A geometric dimension and its selected dot count remain different records for review.
| Path | Output JSON |
|---|---|
| Faulty path | {"dots":98.4,"executableInteger":false} |
| Required path | {"dots":98,"executableInteger":true} |
import assert from 'node:assert/strict';
const smallWhole=(x,max)=>Number.isSafeInteger(x)&&x>=0&&x<=max;
const run=function run(i,corrected=true){
if(!['nearest','ceil'].includes(i.rounding)||!smallWhole(i.tenthsMillimetre,1000000)||!smallWhole(i.dotsPerMillimetre,100)||i.dotsPerMillimetre===0)return {held:true};
const numerator=i.tenthsMillimetre*i.dotsPerMillimetre;
const dots=corrected?(i.rounding==='ceil'?Math.ceil(numerator/10):Math.floor((numerator+5)/10)):numerator/10;
return {dots,executableInteger:Number.isInteger(dots)};
};
const cases=[{"input":{"tenthsMillimetre":123,"dotsPerMillimetre":8,"rounding":"nearest"},"corrected":false,"expected":{"dots":98.4,"executableInteger":false}},{"input":{"tenthsMillimetre":123,"dotsPerMillimetre":8,"rounding":"nearest"},"corrected":true,"expected":{"dots":98,"executableInteger":true}},{"input":{"tenthsMillimetre":123,"dotsPerMillimetre":8,"rounding":"ceil"},"corrected":true,"expected":{"dots":99,"executableInteger":true}},{"input":{"tenthsMillimetre":125,"dotsPerMillimetre":8,"rounding":"nearest"},"corrected":true,"expected":{"dots":100,"executableInteger":true}},{"input":{"tenthsMillimetre":123,"dotsPerMillimetre":8,"rounding":null},"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
The exact 12.5mm boundary gives100 dots without rounding ambiguity. Missing rounding choice is held.
- Read the supplied grid density
- Convert before rounding
- Retain dimension and chosen dots
Hold an unstated rounding rule rather than silently selecting one.
| Condition | Input JSON | Expected output JSON |
|---|---|---|
| declared ceiling | {"tenthsMillimetre":123,"dotsPerMillimetre":8,"rounding":"ceil"} | {"dots":99,"executableInteger":true} |
| exact integer grid | {"tenthsMillimetre":125,"dotsPerMillimetre":8,"rounding":"nearest"} | {"dots":100,"executableInteger":true} |
| rounding choice unknown | {"tenthsMillimetre":123,"dotsPerMillimetre":8,"rounding":null} | {"held":true} |
What setting belongs to the base nearest-grid rule?
Show the worked answer
98 whole dots. Keep the original12.3mm dimension; the fractional98.4 is a conversion result, not an executable dot count.