Skip to content
Astera Technology

Apply a supplied absolute tolerance once in an evaluator

Relative tolerance or display rounding is silently substituted for a declared absolute bound.

Download complete case notes and answer keys ↓

Define the local evaluation task

A synthetic numeric-answer grader uses nonnegative safe integer hundredths for hours, with a supplied nonnegative absolute tolerance in the same unit. Accept equality at either tolerance edge. Compare the original integer ticks without display rounding or relative percentages. The integer convention is local to this dataset.

  1. Validate integer unit and tolerance
  2. Calculate signed original deviation
  3. Compare absolute magnitude with inclusive limit

Invalid tick units or limits stop grading before a pass/fail judgement.

Use the filled cases

Original synthetic input and literal answer key
CaseSupplied inputExpected structured outputDecision and reason
Exact lower edge{"expectedTicks":1000,"answerTicks":990,"toleranceTicks":10}{"deviationTicks":-10,"pass":true}9.90 hours is exactly 0.10 below 10.00, within the inclusive limit.
Past upper limit{"expectedTicks":1000,"answerTicks":1011,"toleranceTicks":10}{"deviationTicks":11,"pass":false}10.11 exceeds the 0.10 tolerance; rounding its display must not change the grade.
Invalid negative tolerance{"expectedTicks":1000,"answerTicks":1000,"toleranceTicks":-1}{"error":"tick-contract"}A negative tolerance is an invalid evaluator definition, not a candidate failure.
Download editable CSV ↓

Work the negative-tolerance case. Which output is required, and why?

Show the worked answer

{"error":"tick-contract"} — A negative tolerance is an invalid evaluator definition, not a candidate failure.

Run the self-contained evaluator

Save as .mjs and run with Node.js; supplied fixtures only
import assert from 'node:assert/strict';

function evaluate(x){
 if(![x.expectedTicks,x.answerTicks,x.toleranceTicks].every(Number.isSafeInteger)||x.expectedTicks<0||x.answerTicks<0||x.toleranceTicks<0)return {error:'tick-contract'};
 const deviation=x.answerTicks-x.expectedTicks;return {deviationTicks:deviation,pass:Math.abs(deviation)<=x.toleranceTicks};
}

const cases = [
  {
    "id": "lower-edge",
    "input": {
      "expectedTicks": 1000,
      "answerTicks": 990,
      "toleranceTicks": 10
    },
    "expected": {
      "deviationTicks": -10,
      "pass": true
    }
  },
  {
    "id": "beyond-upper",
    "input": {
      "expectedTicks": 1000,
      "answerTicks": 1011,
      "toleranceTicks": 10
    },
    "expected": {
      "deviationTicks": 11,
      "pass": false
    }
  },
  {
    "id": "negative-tolerance",
    "input": {
      "expectedTicks": 1000,
      "answerTicks": 1000,
      "toleranceTicks": -1
    },
    "expected": {
      "error": "tick-contract"
    }
  }
];
for (const c of cases) assert.deepEqual(evaluate(c.input), c.expected, c.id);
console.log(JSON.stringify({checked:cases.length,caseIds:cases.map(c=>c.id)}));
Download runnable example ↓

Keep expected ticks, observed candidate ticks and tolerance together. Choosing the tolerance is a supplied acceptance decision; this code does not justify the tolerance or infer a measurement’s accuracy.

Related resources