FAILURE MAP
← Case archive

FA-96891 / Recipe scaling and nutrition / Open access

Nutrition label rounding: cholesterol less-than band · case 01

3 mg cholesterol prints "5 mg" instead of "less than 5 mg".

Verified by executionVariant 1 · 8 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

The 2-5 mg band has no "less than 5 mg" wording and is rounded numerically.

VERIFIED REPAIR

Emit "less than 5 mg" for raw values from 2 up to 5 mg.

Unsuccessful approach: Deciding the band from the rounded value only catches 2-2.5 mg; 2.5-4.9 mg still prints 5 mg.

Case contract

Round a panel dict to displayed strings (toy label rules, half-up): calories <5 -> 0, <=50 -> nearest 5, else nearest 10; fat g <0.5 -> 0, <5 -> nearest 0.5, else nearest 1; sodium mg <5 -> 0, <=140 -> nearest 5, else nearest 10; cholesterol mg <2 -> "0 mg", <5 -> "less than 5 mg", else nearest 5; carbs g <0.5 -> "0 g", <1 -> "less than 1 g", else nearest 1. Absent keys are omitted. Values print with %g formatting.

Why this case matters

Packaged food and meal-kit labels are generated from recipe nutrition totals with banded rounding rules that differ per nutrient.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(panel):
    def near(x, step):
        return math.floor(x / step + Fraction(1, 2)) * step
    def show(v, unit):
        t = format(float(v), 'g')
        return t + ' ' + unit if unit else t
    out = {}
    if 'calories' in panel:
        c = Fraction(str(panel['calories']))
        out['calories'] = show(0 if c < 5 else near(c, 5) if c <= 50 else near(c, 10), '')
    if 'fat' in panel:
        x = Fraction(str(panel['fat']))
        out['fat'] = show(0 if x < Fraction(1, 2) else near(x, Fraction(1, 2)) if x < 5 else near(x, 1), 'g')
    if 'sodium' in panel:
        x = Fraction(str(panel['sodium']))
        out['sodium'] = show(0 if x < 5 else near(x, 5) if x <= 140 else near(x, 10), 'mg')
    if 'cholesterol' in panel:
        x = Fraction(str(panel['cholesterol']))
        out['cholesterol'] = '0 mg' if x < 2 else show(near(x, 5), 'mg')
    if 'carbs' in panel:
        x = Fraction(str(panel['carbs']))
        out['carbs'] = '0 g' if x < Fraction(1, 2) else 'less than 1 g' if x < 1 else show(near(x, 1), 'g')
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['empty panel', [{}], {}],
  ['insignificant calories', [{'calories': 4.9, 'fat': 0.4}], {'calories': '0', 'fat': '0 g'}],
  ['mid-band sodium', [{'carbs': 0.9, 'sodium': 137.5}], {'carbs': 'less than 1 g', 'sodium': '140 mg'}],
  ['regression: cholesterol less-than band',
   [{'calories': 4.6, 'cholesterol': 4.9, 'fat': 1, 'sodium': 7.75}],
   {'calories': '0', 'cholesterol': 'less than 5 mg', 'fat': '1 g', 'sodium': '10 mg'}],
  ['repair check: cholesterol less-than band',
   [{'calories': 56.25, 'carbs': 12.5, 'cholesterol': 4.9, 'fat': 0.5, 'sodium': 7}],
   {'calories': '60', 'carbs': '13 g', 'cholesterol': 'less than 5 mg', 'fat': '0.5 g', 'sodium': '5 mg'}],
  ['generated control 1', [{'calories': 57.25, 'carbs': 0.5, 'fat': 17.5, 'sodium': 2.75}],
   {'calories': '60', 'carbs': 'less than 1 g', 'fat': '18 g', 'sodium': '0 mg'}],
  ['generated control 2', [{'calories': 371.5, 'carbs': 1.5, 'fat': 2.25, 'sodium': 8.25}],
   {'calories': '370', 'carbs': '2 g', 'fat': '2.5 g', 'sodium': '10 mg'}],
  ['generated control 3', [{'calories': 7, 'fat': 1.25}], {'calories': '5', 'fat': '1.5 g'}]],
 [['insignificant calories', [{'calories': 4.9, 'fat': 0.4}], {'calories': '0', 'fat': '0 g'}],
  ['mid-band sodium', [{'carbs': 0.9, 'sodium': 137.5}], {'carbs': 'less than 1 g', 'sodium': '140 mg'}],
  ['large values', [{'calories': 245, 'cholesterol': 22.5, 'fat': 12.5, 'sodium': 455}],
   {'calories': '250', 'cholesterol': '25 mg', 'fat': '13 g', 'sodium': '460 mg'}],
  ['regression: cholesterol less-than band',
   [{'calories': 9.75, 'cholesterol': 2, 'fat': 2.75, 'sodium': 120.5}],
   {'calories': '10', 'cholesterol': 'less than 5 mg', 'fat': '3 g', 'sodium': '120 mg'}],
  ['repair check: cholesterol less-than band', [{'calories': 55, 'cholesterol': 3, 'fat': 1.25}],
   {'calories': '60', 'cholesterol': 'less than 5 mg', 'fat': '1.5 g'}],
  ['generated control 1', [{'calories': 233.5, 'fat': 3.5, 'sodium': 1.75}],
   {'calories': '230', 'fat': '3.5 g', 'sodium': '0 mg'}],
  ['generated control 2', [{'calories': 7.25, 'cholesterol': 7.5, 'fat': 3, 'sodium': 7.5}],
   {'calories': '5', 'cholesterol': '10 mg', 'fat': '3 g', 'sodium': '10 mg'}],
  ['generated control 3', [{'calories': 41.75, 'carbs': 0.5, 'cholesterol': 12, 'fat': 0.75, 'sodium': 7.5}],
   {'calories': '40', 'carbs': 'less than 1 g', 'cholesterol': '10 mg', 'fat': '1 g', 'sodium': '10 mg'}]],
 [['mid-band sodium', [{'carbs': 0.9, 'sodium': 137.5}], {'carbs': 'less than 1 g', 'sodium': '140 mg'}],
  ['large values', [{'calories': 245, 'cholesterol': 22.5, 'fat': 12.5, 'sodium': 455}],
   {'calories': '250', 'cholesterol': '25 mg', 'fat': '13 g', 'sodium': '460 mg'}],
  ['small cholesterol', [{'carbs': 12.5, 'cholesterol': 3}],
   {'carbs': '13 g', 'cholesterol': 'less than 5 mg'}],
  ['regression: cholesterol less-than band',
   [{'calories': 0, 'carbs': 0.2, 'cholesterol': 4.9, 'fat': 0.4, 'sodium': 1.75}],
   {'calories': '0', 'carbs': '0 g', 'cholesterol': 'less than 5 mg', 'fat': '0 g', 'sodium': '0 mg'}],
  ['repair check: cholesterol less-than band',
   [{'calories': 2.5, 'carbs': 0.2, 'cholesterol': 3, 'fat': 2.25, 'sodium': 10.25}],
   {'calories': '0', 'carbs': '0 g', 'cholesterol': 'less than 5 mg', 'fat': '2.5 g', 'sodium': '10 mg'}],
  ['generated control 1', [{'calories': 6, 'cholesterol': 5, 'sodium': 137.5}],
   {'calories': '5', 'cholesterol': '5 mg', 'sodium': '140 mg'}],
  ['generated control 2', [{'calories': 359.5, 'carbs': 0.2, 'cholesterol': 7.5, 'sodium': 12.5}],
   {'calories': '360', 'carbs': '0 g', 'cholesterol': '10 mg', 'sodium': '15 mg'}],
  ['generated control 3', [{'calories': 41.5, 'cholesterol': 5, 'fat': 9.25, 'sodium': 181}],
   {'calories': '40', 'cholesterol': '5 mg', 'fat': '9 g', 'sodium': '180 mg'}]],
 [['large values', [{'calories': 245, 'cholesterol': 22.5, 'fat': 12.5, 'sodium': 455}],
   {'calories': '250', 'cholesterol': '25 mg', 'fat': '13 g', 'sodium': '460 mg'}],
  ['small cholesterol', [{'carbs': 12.5, 'cholesterol': 3}],
   {'carbs': '13 g', 'cholesterol': 'less than 5 mg'}],
  ['empty panel', [{}], {}],
  ['regression: cholesterol less-than band',
   [{'calories': 55.75, 'carbs': 0.5, 'cholesterol': 4.9, 'fat': 2.75, 'sodium': 145}],
   {'calories': '60',
    'carbs': 'less than 1 g',
    'cholesterol': 'less than 5 mg',
    'fat': '3 g',
    'sodium': '150 mg'}],
  ['repair check: cholesterol less-than band', [{'calories': 40.5, 'cholesterol': 4.9, 'fat': 2.75}],
   {'calories': '40', 'cholesterol': 'less than 5 mg', 'fat': '3 g'}],
  ['generated control 1', [{'calories': 2.5, 'fat': 0.4}], {'calories': '0', 'fat': '0 g'}],
  ['generated control 2', [{'calories': 4.6, 'cholesterol': 7.5, 'fat': 1}],
   {'calories': '0', 'cholesterol': '10 mg', 'fat': '1 g'}],
  ['generated control 3', [{'calories': 2.5, 'fat': 4.5, 'sodium': 142.5}],
   {'calories': '0', 'fat': '4.5 g', 'sodium': '140 mg'}]],
 [['small cholesterol', [{'carbs': 12.5, 'cholesterol': 3}],
   {'carbs': '13 g', 'cholesterol': 'less than 5 mg'}],
  ['empty panel', [{}], {}],
  ['insignificant calories', [{'calories': 4.9, 'fat': 0.4}], {'calories': '0', 'fat': '0 g'}],
  ['regression: cholesterol less-than band',
   [{'calories': 4.6, 'cholesterol': 3, 'fat': 11.75, 'sodium': 12.5}],
   {'calories': '0', 'cholesterol': 'less than 5 mg', 'fat': '12 g', 'sodium': '15 mg'}],
  ['repair check: cholesterol less-than band', [{'calories': 6.75, 'cholesterol': 3, 'fat': 15.75}],
   {'calories': '5', 'cholesterol': 'less than 5 mg', 'fat': '16 g'}],
  ['generated control 1', [{'calories': 47.5, 'cholesterol': 1.5, 'fat': 0.4, 'sodium': 185.5}],
   {'calories': '50', 'cholesterol': '0 mg', 'fat': '0 g', 'sodium': '190 mg'}],
  ['generated control 2', [{'calories': 194.5, 'carbs': 0.9, 'cholesterol': 1.5, 'fat': 4.75, 'sodium': 100}],
   {'calories': '190', 'carbs': 'less than 1 g', 'cholesterol': '0 mg', 'fat': '5 g', 'sodium': '100 mg'}],
  ['generated control 3', [{'calories': 41.75, 'cholesterol': 5, 'fat': 1.25, 'sodium': 10.5}],
   {'calories': '40', 'cholesterol': '5 mg', 'fat': '1.5 g', 'sodium': '10 mg'}]]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
empty panel{}{}Passed
insignificant calories{'calories': '0', 'fat': '0 g'}{'calories': '0', 'fat': '0 g'}Passed
mid-band sodium{'carbs': 'less than 1 g', 'sodium': '140 mg'}{'carbs': 'less than 1 g', 'sodium': '140 mg'}Passed
regression: cholesterol less-than band{'calories': '0', 'cholesterol': '5 mg', 'fat': '1 g', 'sodium': '10 mg'}{'calories': '0', 'cholesterol': 'less than 5 mg', 'fat': '1 g', 'sodium': '10 mg'}Failed
repair check: cholesterol less-than band{'calories': '60', 'carbs': '13 g', 'cholesterol': '5 mg', 'fat': '0.5 g', 'sodium': '5 mg'}{'calories': '60', 'carbs': '13 g', 'cholesterol': 'less than 5 mg', 'fat': '0.5 g', 'sodium': '5 mg'}Failed
generated control 1{'calories': '60', 'carbs': 'less than 1 g', 'fat': '18 g', 'sodium': '0 mg'}{'calories': '60', 'carbs': 'less than 1 g', 'fat': '18 g', 'sodium': '0 mg'}Passed
generated control 2{'calories': '370', 'carbs': '2 g', 'fat': '2.5 g', 'sodium': '10 mg'}{'calories': '370', 'carbs': '2 g', 'fat': '2.5 g', 'sodium': '10 mg'}Passed
generated control 3{'calories': '5', 'fat': '1.5 g'}{'calories': '5', 'fat': '1.5 g'}Passed

SHA-256 / 4b2904de7f8712f6ca6db07dc2a3b74c2c26946ad121b2c37b4d5c02de7780af

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(panel):
    def near(x, step):
        return math.floor(x / step + Fraction(1, 2)) * step
    def show(v, unit):
        t = format(float(v), 'g')
        return t + ' ' + unit if unit else t
    out = {}
    if 'calories' in panel:
        c = Fraction(str(panel['calories']))
        out['calories'] = show(0 if c < 5 else near(c, 5) if c <= 50 else near(c, 10), '')
    if 'fat' in panel:
        x = Fraction(str(panel['fat']))
        out['fat'] = show(0 if x < Fraction(1, 2) else near(x, Fraction(1, 2)) if x < 5 else near(x, 1), 'g')
    if 'sodium' in panel:
        x = Fraction(str(panel['sodium']))
        out['sodium'] = show(0 if x < 5 else near(x, 5) if x <= 140 else near(x, 10), 'mg')
    if 'cholesterol' in panel:
        x = Fraction(str(panel['cholesterol']))
        out['cholesterol'] = '0 mg' if x < 2 else 'less than 5 mg' if near(x, 5) < 5 else show(near(x, 5), 'mg')
    if 'carbs' in panel:
        x = Fraction(str(panel['carbs']))
        out['carbs'] = '0 g' if x < Fraction(1, 2) else 'less than 1 g' if x < 1 else show(near(x, 1), 'g')
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['empty panel', [{}], {}],
  ['insignificant calories', [{'calories': 4.9, 'fat': 0.4}], {'calories': '0', 'fat': '0 g'}],
  ['mid-band sodium', [{'carbs': 0.9, 'sodium': 137.5}], {'carbs': 'less than 1 g', 'sodium': '140 mg'}],
  ['regression: cholesterol less-than band',
   [{'calories': 4.6, 'cholesterol': 4.9, 'fat': 1, 'sodium': 7.75}],
   {'calories': '0', 'cholesterol': 'less than 5 mg', 'fat': '1 g', 'sodium': '10 mg'}],
  ['repair check: cholesterol less-than band',
   [{'calories': 56.25, 'carbs': 12.5, 'cholesterol': 4.9, 'fat': 0.5, 'sodium': 7}],
   {'calories': '60', 'carbs': '13 g', 'cholesterol': 'less than 5 mg', 'fat': '0.5 g', 'sodium': '5 mg'}],
  ['generated control 1', [{'calories': 57.25, 'carbs': 0.5, 'fat': 17.5, 'sodium': 2.75}],
   {'calories': '60', 'carbs': 'less than 1 g', 'fat': '18 g', 'sodium': '0 mg'}],
  ['generated control 2', [{'calories': 371.5, 'carbs': 1.5, 'fat': 2.25, 'sodium': 8.25}],
   {'calories': '370', 'carbs': '2 g', 'fat': '2.5 g', 'sodium': '10 mg'}],
  ['generated control 3', [{'calories': 7, 'fat': 1.25}], {'calories': '5', 'fat': '1.5 g'}]],
 [['insignificant calories', [{'calories': 4.9, 'fat': 0.4}], {'calories': '0', 'fat': '0 g'}],
  ['mid-band sodium', [{'carbs': 0.9, 'sodium': 137.5}], {'carbs': 'less than 1 g', 'sodium': '140 mg'}],
  ['large values', [{'calories': 245, 'cholesterol': 22.5, 'fat': 12.5, 'sodium': 455}],
   {'calories': '250', 'cholesterol': '25 mg', 'fat': '13 g', 'sodium': '460 mg'}],
  ['regression: cholesterol less-than band',
   [{'calories': 9.75, 'cholesterol': 2, 'fat': 2.75, 'sodium': 120.5}],
   {'calories': '10', 'cholesterol': 'less than 5 mg', 'fat': '3 g', 'sodium': '120 mg'}],
  ['repair check: cholesterol less-than band', [{'calories': 55, 'cholesterol': 3, 'fat': 1.25}],
   {'calories': '60', 'cholesterol': 'less than 5 mg', 'fat': '1.5 g'}],
  ['generated control 1', [{'calories': 233.5, 'fat': 3.5, 'sodium': 1.75}],
   {'calories': '230', 'fat': '3.5 g', 'sodium': '0 mg'}],
  ['generated control 2', [{'calories': 7.25, 'cholesterol': 7.5, 'fat': 3, 'sodium': 7.5}],
   {'calories': '5', 'cholesterol': '10 mg', 'fat': '3 g', 'sodium': '10 mg'}],
  ['generated control 3', [{'calories': 41.75, 'carbs': 0.5, 'cholesterol': 12, 'fat': 0.75, 'sodium': 7.5}],
   {'calories': '40', 'carbs': 'less than 1 g', 'cholesterol': '10 mg', 'fat': '1 g', 'sodium': '10 mg'}]],
 [['mid-band sodium', [{'carbs': 0.9, 'sodium': 137.5}], {'carbs': 'less than 1 g', 'sodium': '140 mg'}],
  ['large values', [{'calories': 245, 'cholesterol': 22.5, 'fat': 12.5, 'sodium': 455}],
   {'calories': '250', 'cholesterol': '25 mg', 'fat': '13 g', 'sodium': '460 mg'}],
  ['small cholesterol', [{'carbs': 12.5, 'cholesterol': 3}],
   {'carbs': '13 g', 'cholesterol': 'less than 5 mg'}],
  ['regression: cholesterol less-than band',
   [{'calories': 0, 'carbs': 0.2, 'cholesterol': 4.9, 'fat': 0.4, 'sodium': 1.75}],
   {'calories': '0', 'carbs': '0 g', 'cholesterol': 'less than 5 mg', 'fat': '0 g', 'sodium': '0 mg'}],
  ['repair check: cholesterol less-than band',
   [{'calories': 2.5, 'carbs': 0.2, 'cholesterol': 3, 'fat': 2.25, 'sodium': 10.25}],
   {'calories': '0', 'carbs': '0 g', 'cholesterol': 'less than 5 mg', 'fat': '2.5 g', 'sodium': '10 mg'}],
  ['generated control 1', [{'calories': 6, 'cholesterol': 5, 'sodium': 137.5}],
   {'calories': '5', 'cholesterol': '5 mg', 'sodium': '140 mg'}],
  ['generated control 2', [{'calories': 359.5, 'carbs': 0.2, 'cholesterol': 7.5, 'sodium': 12.5}],
   {'calories': '360', 'carbs': '0 g', 'cholesterol': '10 mg', 'sodium': '15 mg'}],
  ['generated control 3', [{'calories': 41.5, 'cholesterol': 5, 'fat': 9.25, 'sodium': 181}],
   {'calories': '40', 'cholesterol': '5 mg', 'fat': '9 g', 'sodium': '180 mg'}]],
 [['large values', [{'calories': 245, 'cholesterol': 22.5, 'fat': 12.5, 'sodium': 455}],
   {'calories': '250', 'cholesterol': '25 mg', 'fat': '13 g', 'sodium': '460 mg'}],
  ['small cholesterol', [{'carbs': 12.5, 'cholesterol': 3}],
   {'carbs': '13 g', 'cholesterol': 'less than 5 mg'}],
  ['empty panel', [{}], {}],
  ['regression: cholesterol less-than band',
   [{'calories': 55.75, 'carbs': 0.5, 'cholesterol': 4.9, 'fat': 2.75, 'sodium': 145}],
   {'calories': '60',
    'carbs': 'less than 1 g',
    'cholesterol': 'less than 5 mg',
    'fat': '3 g',
    'sodium': '150 mg'}],
  ['repair check: cholesterol less-than band', [{'calories': 40.5, 'cholesterol': 4.9, 'fat': 2.75}],
   {'calories': '40', 'cholesterol': 'less than 5 mg', 'fat': '3 g'}],
  ['generated control 1', [{'calories': 2.5, 'fat': 0.4}], {'calories': '0', 'fat': '0 g'}],
  ['generated control 2', [{'calories': 4.6, 'cholesterol': 7.5, 'fat': 1}],
   {'calories': '0', 'cholesterol': '10 mg', 'fat': '1 g'}],
  ['generated control 3', [{'calories': 2.5, 'fat': 4.5, 'sodium': 142.5}],
   {'calories': '0', 'fat': '4.5 g', 'sodium': '140 mg'}]],
 [['small cholesterol', [{'carbs': 12.5, 'cholesterol': 3}],
   {'carbs': '13 g', 'cholesterol': 'less than 5 mg'}],
  ['empty panel', [{}], {}],
  ['insignificant calories', [{'calories': 4.9, 'fat': 0.4}], {'calories': '0', 'fat': '0 g'}],
  ['regression: cholesterol less-than band',
   [{'calories': 4.6, 'cholesterol': 3, 'fat': 11.75, 'sodium': 12.5}],
   {'calories': '0', 'cholesterol': 'less than 5 mg', 'fat': '12 g', 'sodium': '15 mg'}],
  ['repair check: cholesterol less-than band', [{'calories': 6.75, 'cholesterol': 3, 'fat': 15.75}],
   {'calories': '5', 'cholesterol': 'less than 5 mg', 'fat': '16 g'}],
  ['generated control 1', [{'calories': 47.5, 'cholesterol': 1.5, 'fat': 0.4, 'sodium': 185.5}],
   {'calories': '50', 'cholesterol': '0 mg', 'fat': '0 g', 'sodium': '190 mg'}],
  ['generated control 2', [{'calories': 194.5, 'carbs': 0.9, 'cholesterol': 1.5, 'fat': 4.75, 'sodium': 100}],
   {'calories': '190', 'carbs': 'less than 1 g', 'cholesterol': '0 mg', 'fat': '5 g', 'sodium': '100 mg'}],
  ['generated control 3', [{'calories': 41.75, 'cholesterol': 5, 'fat': 1.25, 'sodium': 10.5}],
   {'calories': '40', 'cholesterol': '5 mg', 'fat': '1.5 g', 'sodium': '10 mg'}]]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
empty panel{}{}Passed
insignificant calories{'calories': '0', 'fat': '0 g'}{'calories': '0', 'fat': '0 g'}Passed
mid-band sodium{'carbs': 'less than 1 g', 'sodium': '140 mg'}{'carbs': 'less than 1 g', 'sodium': '140 mg'}Passed
regression: cholesterol less-than band{'calories': '0', 'cholesterol': '5 mg', 'fat': '1 g', 'sodium': '10 mg'}{'calories': '0', 'cholesterol': 'less than 5 mg', 'fat': '1 g', 'sodium': '10 mg'}Failed
repair check: cholesterol less-than band{'calories': '60', 'carbs': '13 g', 'cholesterol': '5 mg', 'fat': '0.5 g', 'sodium': '5 mg'}{'calories': '60', 'carbs': '13 g', 'cholesterol': 'less than 5 mg', 'fat': '0.5 g', 'sodium': '5 mg'}Failed
generated control 1{'calories': '60', 'carbs': 'less than 1 g', 'fat': '18 g', 'sodium': '0 mg'}{'calories': '60', 'carbs': 'less than 1 g', 'fat': '18 g', 'sodium': '0 mg'}Passed
generated control 2{'calories': '370', 'carbs': '2 g', 'fat': '2.5 g', 'sodium': '10 mg'}{'calories': '370', 'carbs': '2 g', 'fat': '2.5 g', 'sodium': '10 mg'}Passed
generated control 3{'calories': '5', 'fat': '1.5 g'}{'calories': '5', 'fat': '1.5 g'}Passed

SHA-256 / 2ad324e64c12ef96af9a63cc3f6534e4291f793d5dc1f02b9626d5a42558bc4c

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(panel):
    def near(x, step):
        return math.floor(x / step + Fraction(1, 2)) * step
    def show(v, unit):
        t = format(float(v), 'g')
        return t + ' ' + unit if unit else t
    out = {}
    if 'calories' in panel:
        c = Fraction(str(panel['calories']))
        out['calories'] = show(0 if c < 5 else near(c, 5) if c <= 50 else near(c, 10), '')
    if 'fat' in panel:
        x = Fraction(str(panel['fat']))
        out['fat'] = show(0 if x < Fraction(1, 2) else near(x, Fraction(1, 2)) if x < 5 else near(x, 1), 'g')
    if 'sodium' in panel:
        x = Fraction(str(panel['sodium']))
        out['sodium'] = show(0 if x < 5 else near(x, 5) if x <= 140 else near(x, 10), 'mg')
    if 'cholesterol' in panel:
        x = Fraction(str(panel['cholesterol']))
        out['cholesterol'] = '0 mg' if x < 2 else 'less than 5 mg' if x < 5 else show(near(x, 5), 'mg')
    if 'carbs' in panel:
        x = Fraction(str(panel['carbs']))
        out['carbs'] = '0 g' if x < Fraction(1, 2) else 'less than 1 g' if x < 1 else show(near(x, 1), 'g')
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['empty panel', [{}], {}],
  ['insignificant calories', [{'calories': 4.9, 'fat': 0.4}], {'calories': '0', 'fat': '0 g'}],
  ['mid-band sodium', [{'carbs': 0.9, 'sodium': 137.5}], {'carbs': 'less than 1 g', 'sodium': '140 mg'}],
  ['regression: cholesterol less-than band',
   [{'calories': 4.6, 'cholesterol': 4.9, 'fat': 1, 'sodium': 7.75}],
   {'calories': '0', 'cholesterol': 'less than 5 mg', 'fat': '1 g', 'sodium': '10 mg'}],
  ['repair check: cholesterol less-than band',
   [{'calories': 56.25, 'carbs': 12.5, 'cholesterol': 4.9, 'fat': 0.5, 'sodium': 7}],
   {'calories': '60', 'carbs': '13 g', 'cholesterol': 'less than 5 mg', 'fat': '0.5 g', 'sodium': '5 mg'}],
  ['generated control 1', [{'calories': 57.25, 'carbs': 0.5, 'fat': 17.5, 'sodium': 2.75}],
   {'calories': '60', 'carbs': 'less than 1 g', 'fat': '18 g', 'sodium': '0 mg'}],
  ['generated control 2', [{'calories': 371.5, 'carbs': 1.5, 'fat': 2.25, 'sodium': 8.25}],
   {'calories': '370', 'carbs': '2 g', 'fat': '2.5 g', 'sodium': '10 mg'}],
  ['generated control 3', [{'calories': 7, 'fat': 1.25}], {'calories': '5', 'fat': '1.5 g'}]],
 [['insignificant calories', [{'calories': 4.9, 'fat': 0.4}], {'calories': '0', 'fat': '0 g'}],
  ['mid-band sodium', [{'carbs': 0.9, 'sodium': 137.5}], {'carbs': 'less than 1 g', 'sodium': '140 mg'}],
  ['large values', [{'calories': 245, 'cholesterol': 22.5, 'fat': 12.5, 'sodium': 455}],
   {'calories': '250', 'cholesterol': '25 mg', 'fat': '13 g', 'sodium': '460 mg'}],
  ['regression: cholesterol less-than band',
   [{'calories': 9.75, 'cholesterol': 2, 'fat': 2.75, 'sodium': 120.5}],
   {'calories': '10', 'cholesterol': 'less than 5 mg', 'fat': '3 g', 'sodium': '120 mg'}],
  ['repair check: cholesterol less-than band', [{'calories': 55, 'cholesterol': 3, 'fat': 1.25}],
   {'calories': '60', 'cholesterol': 'less than 5 mg', 'fat': '1.5 g'}],
  ['generated control 1', [{'calories': 233.5, 'fat': 3.5, 'sodium': 1.75}],
   {'calories': '230', 'fat': '3.5 g', 'sodium': '0 mg'}],
  ['generated control 2', [{'calories': 7.25, 'cholesterol': 7.5, 'fat': 3, 'sodium': 7.5}],
   {'calories': '5', 'cholesterol': '10 mg', 'fat': '3 g', 'sodium': '10 mg'}],
  ['generated control 3', [{'calories': 41.75, 'carbs': 0.5, 'cholesterol': 12, 'fat': 0.75, 'sodium': 7.5}],
   {'calories': '40', 'carbs': 'less than 1 g', 'cholesterol': '10 mg', 'fat': '1 g', 'sodium': '10 mg'}]],
 [['mid-band sodium', [{'carbs': 0.9, 'sodium': 137.5}], {'carbs': 'less than 1 g', 'sodium': '140 mg'}],
  ['large values', [{'calories': 245, 'cholesterol': 22.5, 'fat': 12.5, 'sodium': 455}],
   {'calories': '250', 'cholesterol': '25 mg', 'fat': '13 g', 'sodium': '460 mg'}],
  ['small cholesterol', [{'carbs': 12.5, 'cholesterol': 3}],
   {'carbs': '13 g', 'cholesterol': 'less than 5 mg'}],
  ['regression: cholesterol less-than band',
   [{'calories': 0, 'carbs': 0.2, 'cholesterol': 4.9, 'fat': 0.4, 'sodium': 1.75}],
   {'calories': '0', 'carbs': '0 g', 'cholesterol': 'less than 5 mg', 'fat': '0 g', 'sodium': '0 mg'}],
  ['repair check: cholesterol less-than band',
   [{'calories': 2.5, 'carbs': 0.2, 'cholesterol': 3, 'fat': 2.25, 'sodium': 10.25}],
   {'calories': '0', 'carbs': '0 g', 'cholesterol': 'less than 5 mg', 'fat': '2.5 g', 'sodium': '10 mg'}],
  ['generated control 1', [{'calories': 6, 'cholesterol': 5, 'sodium': 137.5}],
   {'calories': '5', 'cholesterol': '5 mg', 'sodium': '140 mg'}],
  ['generated control 2', [{'calories': 359.5, 'carbs': 0.2, 'cholesterol': 7.5, 'sodium': 12.5}],
   {'calories': '360', 'carbs': '0 g', 'cholesterol': '10 mg', 'sodium': '15 mg'}],
  ['generated control 3', [{'calories': 41.5, 'cholesterol': 5, 'fat': 9.25, 'sodium': 181}],
   {'calories': '40', 'cholesterol': '5 mg', 'fat': '9 g', 'sodium': '180 mg'}]],
 [['large values', [{'calories': 245, 'cholesterol': 22.5, 'fat': 12.5, 'sodium': 455}],
   {'calories': '250', 'cholesterol': '25 mg', 'fat': '13 g', 'sodium': '460 mg'}],
  ['small cholesterol', [{'carbs': 12.5, 'cholesterol': 3}],
   {'carbs': '13 g', 'cholesterol': 'less than 5 mg'}],
  ['empty panel', [{}], {}],
  ['regression: cholesterol less-than band',
   [{'calories': 55.75, 'carbs': 0.5, 'cholesterol': 4.9, 'fat': 2.75, 'sodium': 145}],
   {'calories': '60',
    'carbs': 'less than 1 g',
    'cholesterol': 'less than 5 mg',
    'fat': '3 g',
    'sodium': '150 mg'}],
  ['repair check: cholesterol less-than band', [{'calories': 40.5, 'cholesterol': 4.9, 'fat': 2.75}],
   {'calories': '40', 'cholesterol': 'less than 5 mg', 'fat': '3 g'}],
  ['generated control 1', [{'calories': 2.5, 'fat': 0.4}], {'calories': '0', 'fat': '0 g'}],
  ['generated control 2', [{'calories': 4.6, 'cholesterol': 7.5, 'fat': 1}],
   {'calories': '0', 'cholesterol': '10 mg', 'fat': '1 g'}],
  ['generated control 3', [{'calories': 2.5, 'fat': 4.5, 'sodium': 142.5}],
   {'calories': '0', 'fat': '4.5 g', 'sodium': '140 mg'}]],
 [['small cholesterol', [{'carbs': 12.5, 'cholesterol': 3}],
   {'carbs': '13 g', 'cholesterol': 'less than 5 mg'}],
  ['empty panel', [{}], {}],
  ['insignificant calories', [{'calories': 4.9, 'fat': 0.4}], {'calories': '0', 'fat': '0 g'}],
  ['regression: cholesterol less-than band',
   [{'calories': 4.6, 'cholesterol': 3, 'fat': 11.75, 'sodium': 12.5}],
   {'calories': '0', 'cholesterol': 'less than 5 mg', 'fat': '12 g', 'sodium': '15 mg'}],
  ['repair check: cholesterol less-than band', [{'calories': 6.75, 'cholesterol': 3, 'fat': 15.75}],
   {'calories': '5', 'cholesterol': 'less than 5 mg', 'fat': '16 g'}],
  ['generated control 1', [{'calories': 47.5, 'cholesterol': 1.5, 'fat': 0.4, 'sodium': 185.5}],
   {'calories': '50', 'cholesterol': '0 mg', 'fat': '0 g', 'sodium': '190 mg'}],
  ['generated control 2', [{'calories': 194.5, 'carbs': 0.9, 'cholesterol': 1.5, 'fat': 4.75, 'sodium': 100}],
   {'calories': '190', 'carbs': 'less than 1 g', 'cholesterol': '0 mg', 'fat': '5 g', 'sodium': '100 mg'}],
  ['generated control 3', [{'calories': 41.75, 'cholesterol': 5, 'fat': 1.25, 'sodium': 10.5}],
   {'calories': '40', 'cholesterol': '5 mg', 'fat': '1.5 g', 'sodium': '10 mg'}]]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
empty panel{}{}Passed
insignificant calories{'calories': '0', 'fat': '0 g'}{'calories': '0', 'fat': '0 g'}Passed
mid-band sodium{'carbs': 'less than 1 g', 'sodium': '140 mg'}{'carbs': 'less than 1 g', 'sodium': '140 mg'}Passed
regression: cholesterol less-than band{'calories': '0', 'cholesterol': 'less than 5 mg', 'fat': '1 g', 'sodium': '10 mg'}{'calories': '0', 'cholesterol': 'less than 5 mg', 'fat': '1 g', 'sodium': '10 mg'}Passed
repair check: cholesterol less-than band{'calories': '60', 'carbs': '13 g', 'cholesterol': 'less than 5 mg', 'fat': '0.5 g', 'sodium': '5 mg'}{'calories': '60', 'carbs': '13 g', 'cholesterol': 'less than 5 mg', 'fat': '0.5 g', 'sodium': '5 mg'}Passed
generated control 1{'calories': '60', 'carbs': 'less than 1 g', 'fat': '18 g', 'sodium': '0 mg'}{'calories': '60', 'carbs': 'less than 1 g', 'fat': '18 g', 'sodium': '0 mg'}Passed
generated control 2{'calories': '370', 'carbs': '2 g', 'fat': '2.5 g', 'sodium': '10 mg'}{'calories': '370', 'carbs': '2 g', 'fat': '2.5 g', 'sodium': '10 mg'}Passed
generated control 3{'calories': '5', 'fat': '1.5 g'}{'calories': '5', 'fat': '1.5 g'}Passed

SHA-256 / d105f3f02c31fb8c9f28b678c2148370b095fadc7d4e8b3d52a9c879a8f0a71f

Verification & scope

A deterministic toy contract stated in full here; it is a bounded teaching model, not an authoritative reference or standards implementation. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.

Observations recorded using Python 3.12.14 at 2026-09-29T14:52:26.844275+00:00.

Case digest / 370ccf2459fa85177bb8b1eeb0575d225081231319323b4538375c8bb98a6060