FA-96896 / Recipe scaling and nutrition / Open access
Nutrition label rounding: half-up tie rounding · case 01
A 47.5 kcal serving prints 50 but 42.5 kcal prints 40, and 142.5 mg sodium flips between bands.
ROOT CAUSE
The shared rounding helper uses half-to-even, so ties alternate between rounding down and up.
VERIFIED REPAIR
Round ties half-up with floor(x/step + 1/2).
Unsuccessful approach: Ceiling of x/step - 1/2 rounds every tie down, which is half-down, not half-up.
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 round(x / step) * 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: half-up tie rounding', [{'calories': 161, 'carbs': 0.5, 'fat': 1.25, 'sodium': 7.5}],
{'calories': '160', 'carbs': 'less than 1 g', 'fat': '1.5 g', 'sodium': '10 mg'}],
['repair check: half-up tie rounding',
[{'calories': 57.75, 'cholesterol': 5, 'fat': 1.25, 'sodium': 137.5}],
{'calories': '60', 'cholesterol': '5 mg', 'fat': '1.5 g', 'sodium': '140 mg'}],
['generated control 1', [{'carbs': 30.4, 'sodium': 0.75}], {'carbs': '30 g', 'sodium': '0 mg'}],
['generated control 2', [{'calories': 2.5, 'cholesterol': 22.5, 'fat': 1.25, 'sodium': 7.25}],
{'calories': '0', 'cholesterol': '25 mg', 'fat': '1.5 g', 'sodium': '5 mg'}],
['generated control 3', [{'calories': 8.25, 'carbs': 0.9, 'fat': 2.75, 'sodium': 1.75}],
{'calories': '10', 'carbs': 'less than 1 g', 'fat': '3 g', 'sodium': '0 mg'}]],
[['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: half-up tie rounding', [{'carbs': 0.9, 'cholesterol': 12, 'fat': 4.5, 'sodium': 145}],
{'carbs': 'less than 1 g', 'cholesterol': '10 mg', 'fat': '4.5 g', 'sodium': '150 mg'}],
['repair check: half-up tie rounding',
[{'calories': 129, 'carbs': 1.5, 'cholesterol': 7.5, 'fat': 5.75, 'sodium': 142.5}],
{'calories': '130', 'carbs': '2 g', 'cholesterol': '10 mg', 'fat': '6 g', 'sodium': '140 mg'}],
['generated control 1', [{'calories': 66.5, 'carbs': 0.2, 'fat': 1.75, 'sodium': 12.5}],
{'calories': '70', 'carbs': '0 g', 'fat': '2 g', 'sodium': '15 mg'}],
['generated control 2', [{'calories': 217.5, 'cholesterol': 1.5, 'fat': 2.75, 'sodium': 145}],
{'calories': '220', 'cholesterol': '0 mg', 'fat': '3 g', 'sodium': '150 mg'}],
['generated control 3', [{'carbs': 0.5, 'fat': 15.25}], {'carbs': 'less than 1 g', 'fat': '15 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'}],
['small cholesterol', [{'carbs': 12.5, 'cholesterol': 3}],
{'carbs': '13 g', 'cholesterol': 'less than 5 mg'}],
['regression: half-up tie rounding', [{'calories': 12.25, 'carbs': 1, 'fat': 10.5, 'sodium': 137.5}],
{'calories': '10', 'carbs': '1 g', 'fat': '11 g', 'sodium': '140 mg'}],
['repair check: half-up tie rounding',
[{'calories': 200, 'carbs': 1, 'cholesterol': 1.5, 'fat': 2.75, 'sodium': 134}],
{'calories': '200', 'carbs': '1 g', 'cholesterol': '0 mg', 'fat': '3 g', 'sodium': '135 mg'}],
['generated control 1', [{'calories': 184.5, 'sodium': 5}], {'calories': '180', 'sodium': '5 mg'}],
['generated control 2', [{'calories': 96.5, 'carbs': 1.5, 'fat': 3.5, 'sodium': 7.5}],
{'calories': '100', 'carbs': '2 g', 'fat': '3.5 g', 'sodium': '10 mg'}],
['generated control 3', [{'calories': 1.25, 'cholesterol': 4.9, 'sodium': 142.5}],
{'calories': '0', 'cholesterol': 'less than 5 mg', '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'}],
['empty panel', [{}], {}],
['regression: half-up tie rounding', [{'calories': 4.6, 'cholesterol': 1.5, 'fat': 0, 'sodium': 12.5}],
{'calories': '0', 'cholesterol': '0 mg', 'fat': '0 g', 'sodium': '15 mg'}],
['repair check: half-up tie rounding', [{'calories': 41, 'cholesterol': 7.5}],
{'calories': '40', 'cholesterol': '10 mg'}],
['generated control 1', [{'calories': 2.5, 'carbs': 0.9, 'fat': 6, 'sodium': 137.5}],
{'calories': '0', 'carbs': 'less than 1 g', 'fat': '6 g', 'sodium': '140 mg'}],
['generated control 2', [{'fat': 0, 'sodium': 137}], {'fat': '0 g', 'sodium': '135 mg'}],
['generated control 3', [{'calories': 105, 'carbs': 0.2, 'cholesterol': 7.5, 'fat': 0.25, 'sodium': 2.75}],
{'calories': '110', 'carbs': '0 g', 'cholesterol': '10 mg', 'fat': '0 g', 'sodium': '0 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: half-up tie rounding', [{'calories': 89.5, 'fat': 1.25, 'sodium': 137.5}],
{'calories': '90', 'fat': '1.5 g', 'sodium': '140 mg'}],
['repair check: half-up tie rounding', [{'fat': 4.75, 'sodium': 7.5}], {'fat': '5 g', 'sodium': '10 mg'}],
['generated control 1', [{'calories': 89.5, 'carbs': 30.4, 'cholesterol': 5, 'fat': 15.5, 'sodium': 12.5}],
{'calories': '90', 'carbs': '30 g', 'cholesterol': '5 mg', 'fat': '16 g', 'sodium': '15 mg'}],
['generated control 2', [{'calories': 40.25, 'cholesterol': 2.2, 'fat': 7.5}],
{'calories': '40', 'cholesterol': 'less than 5 mg', 'fat': '8 g'}],
['generated control 3', [{'calories': 42.5, 'fat': 6.25, 'sodium': 142.5}],
{'calories': '45', 'fat': '6 g', 'sodium': '140 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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| 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: half-up tie rounding | {'calories': '160', 'carbs': 'less than 1 g', 'fat': '1 g', 'sodium': '10 mg'} | {'calories': '160', 'carbs': 'less than 1 g', 'fat': '1.5 g', 'sodium': '10 mg'} | Failed |
| repair check: half-up tie rounding | {'calories': '60', 'cholesterol': '5 mg', 'fat': '1 g', 'sodium': '140 mg'} | {'calories': '60', 'cholesterol': '5 mg', 'fat': '1.5 g', 'sodium': '140 mg'} | Failed |
| generated control 1 | {'carbs': '30 g', 'sodium': '0 mg'} | {'carbs': '30 g', 'sodium': '0 mg'} | Passed |
| generated control 2 | {'calories': '0', 'cholesterol': '20 mg', 'fat': '1 g', 'sodium': '5 mg'} | {'calories': '0', 'cholesterol': '25 mg', 'fat': '1.5 g', 'sodium': '5 mg'} | Failed |
| generated control 3 | {'calories': '10', 'carbs': 'less than 1 g', 'fat': '3 g', 'sodium': '0 mg'} | {'calories': '10', 'carbs': 'less than 1 g', 'fat': '3 g', 'sodium': '0 mg'} | Passed |
SHA-256 / 1f2ea026b22764cf43b220b51927ef49da4b9dc50a2f43b3f3ccdc9f2d270351
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.ceil(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: half-up tie rounding', [{'calories': 161, 'carbs': 0.5, 'fat': 1.25, 'sodium': 7.5}],
{'calories': '160', 'carbs': 'less than 1 g', 'fat': '1.5 g', 'sodium': '10 mg'}],
['repair check: half-up tie rounding',
[{'calories': 57.75, 'cholesterol': 5, 'fat': 1.25, 'sodium': 137.5}],
{'calories': '60', 'cholesterol': '5 mg', 'fat': '1.5 g', 'sodium': '140 mg'}],
['generated control 1', [{'carbs': 30.4, 'sodium': 0.75}], {'carbs': '30 g', 'sodium': '0 mg'}],
['generated control 2', [{'calories': 2.5, 'cholesterol': 22.5, 'fat': 1.25, 'sodium': 7.25}],
{'calories': '0', 'cholesterol': '25 mg', 'fat': '1.5 g', 'sodium': '5 mg'}],
['generated control 3', [{'calories': 8.25, 'carbs': 0.9, 'fat': 2.75, 'sodium': 1.75}],
{'calories': '10', 'carbs': 'less than 1 g', 'fat': '3 g', 'sodium': '0 mg'}]],
[['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: half-up tie rounding', [{'carbs': 0.9, 'cholesterol': 12, 'fat': 4.5, 'sodium': 145}],
{'carbs': 'less than 1 g', 'cholesterol': '10 mg', 'fat': '4.5 g', 'sodium': '150 mg'}],
['repair check: half-up tie rounding',
[{'calories': 129, 'carbs': 1.5, 'cholesterol': 7.5, 'fat': 5.75, 'sodium': 142.5}],
{'calories': '130', 'carbs': '2 g', 'cholesterol': '10 mg', 'fat': '6 g', 'sodium': '140 mg'}],
['generated control 1', [{'calories': 66.5, 'carbs': 0.2, 'fat': 1.75, 'sodium': 12.5}],
{'calories': '70', 'carbs': '0 g', 'fat': '2 g', 'sodium': '15 mg'}],
['generated control 2', [{'calories': 217.5, 'cholesterol': 1.5, 'fat': 2.75, 'sodium': 145}],
{'calories': '220', 'cholesterol': '0 mg', 'fat': '3 g', 'sodium': '150 mg'}],
['generated control 3', [{'carbs': 0.5, 'fat': 15.25}], {'carbs': 'less than 1 g', 'fat': '15 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'}],
['small cholesterol', [{'carbs': 12.5, 'cholesterol': 3}],
{'carbs': '13 g', 'cholesterol': 'less than 5 mg'}],
['regression: half-up tie rounding', [{'calories': 12.25, 'carbs': 1, 'fat': 10.5, 'sodium': 137.5}],
{'calories': '10', 'carbs': '1 g', 'fat': '11 g', 'sodium': '140 mg'}],
['repair check: half-up tie rounding',
[{'calories': 200, 'carbs': 1, 'cholesterol': 1.5, 'fat': 2.75, 'sodium': 134}],
{'calories': '200', 'carbs': '1 g', 'cholesterol': '0 mg', 'fat': '3 g', 'sodium': '135 mg'}],
['generated control 1', [{'calories': 184.5, 'sodium': 5}], {'calories': '180', 'sodium': '5 mg'}],
['generated control 2', [{'calories': 96.5, 'carbs': 1.5, 'fat': 3.5, 'sodium': 7.5}],
{'calories': '100', 'carbs': '2 g', 'fat': '3.5 g', 'sodium': '10 mg'}],
['generated control 3', [{'calories': 1.25, 'cholesterol': 4.9, 'sodium': 142.5}],
{'calories': '0', 'cholesterol': 'less than 5 mg', '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'}],
['empty panel', [{}], {}],
['regression: half-up tie rounding', [{'calories': 4.6, 'cholesterol': 1.5, 'fat': 0, 'sodium': 12.5}],
{'calories': '0', 'cholesterol': '0 mg', 'fat': '0 g', 'sodium': '15 mg'}],
['repair check: half-up tie rounding', [{'calories': 41, 'cholesterol': 7.5}],
{'calories': '40', 'cholesterol': '10 mg'}],
['generated control 1', [{'calories': 2.5, 'carbs': 0.9, 'fat': 6, 'sodium': 137.5}],
{'calories': '0', 'carbs': 'less than 1 g', 'fat': '6 g', 'sodium': '140 mg'}],
['generated control 2', [{'fat': 0, 'sodium': 137}], {'fat': '0 g', 'sodium': '135 mg'}],
['generated control 3', [{'calories': 105, 'carbs': 0.2, 'cholesterol': 7.5, 'fat': 0.25, 'sodium': 2.75}],
{'calories': '110', 'carbs': '0 g', 'cholesterol': '10 mg', 'fat': '0 g', 'sodium': '0 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: half-up tie rounding', [{'calories': 89.5, 'fat': 1.25, 'sodium': 137.5}],
{'calories': '90', 'fat': '1.5 g', 'sodium': '140 mg'}],
['repair check: half-up tie rounding', [{'fat': 4.75, 'sodium': 7.5}], {'fat': '5 g', 'sodium': '10 mg'}],
['generated control 1', [{'calories': 89.5, 'carbs': 30.4, 'cholesterol': 5, 'fat': 15.5, 'sodium': 12.5}],
{'calories': '90', 'carbs': '30 g', 'cholesterol': '5 mg', 'fat': '16 g', 'sodium': '15 mg'}],
['generated control 2', [{'calories': 40.25, 'cholesterol': 2.2, 'fat': 7.5}],
{'calories': '40', 'cholesterol': 'less than 5 mg', 'fat': '8 g'}],
['generated control 3', [{'calories': 42.5, 'fat': 6.25, 'sodium': 142.5}],
{'calories': '45', 'fat': '6 g', 'sodium': '140 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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| 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': '135 mg'} | {'carbs': 'less than 1 g', 'sodium': '140 mg'} | Failed |
| regression: half-up tie rounding | {'calories': '160', 'carbs': 'less than 1 g', 'fat': '1 g', 'sodium': '5 mg'} | {'calories': '160', 'carbs': 'less than 1 g', 'fat': '1.5 g', 'sodium': '10 mg'} | Failed |
| repair check: half-up tie rounding | {'calories': '60', 'cholesterol': '5 mg', 'fat': '1 g', 'sodium': '135 mg'} | {'calories': '60', 'cholesterol': '5 mg', 'fat': '1.5 g', 'sodium': '140 mg'} | Failed |
| generated control 1 | {'carbs': '30 g', 'sodium': '0 mg'} | {'carbs': '30 g', 'sodium': '0 mg'} | Passed |
| generated control 2 | {'calories': '0', 'cholesterol': '20 mg', 'fat': '1 g', 'sodium': '5 mg'} | {'calories': '0', 'cholesterol': '25 mg', 'fat': '1.5 g', 'sodium': '5 mg'} | Failed |
| generated control 3 | {'calories': '10', 'carbs': 'less than 1 g', 'fat': '2.5 g', 'sodium': '0 mg'} | {'calories': '10', 'carbs': 'less than 1 g', 'fat': '3 g', 'sodium': '0 mg'} | Failed |
SHA-256 / e4a1d025c29d8b038a59414a1e43e35602523226e8996ba74e75580afa8e7b12
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: half-up tie rounding', [{'calories': 161, 'carbs': 0.5, 'fat': 1.25, 'sodium': 7.5}],
{'calories': '160', 'carbs': 'less than 1 g', 'fat': '1.5 g', 'sodium': '10 mg'}],
['repair check: half-up tie rounding',
[{'calories': 57.75, 'cholesterol': 5, 'fat': 1.25, 'sodium': 137.5}],
{'calories': '60', 'cholesterol': '5 mg', 'fat': '1.5 g', 'sodium': '140 mg'}],
['generated control 1', [{'carbs': 30.4, 'sodium': 0.75}], {'carbs': '30 g', 'sodium': '0 mg'}],
['generated control 2', [{'calories': 2.5, 'cholesterol': 22.5, 'fat': 1.25, 'sodium': 7.25}],
{'calories': '0', 'cholesterol': '25 mg', 'fat': '1.5 g', 'sodium': '5 mg'}],
['generated control 3', [{'calories': 8.25, 'carbs': 0.9, 'fat': 2.75, 'sodium': 1.75}],
{'calories': '10', 'carbs': 'less than 1 g', 'fat': '3 g', 'sodium': '0 mg'}]],
[['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: half-up tie rounding', [{'carbs': 0.9, 'cholesterol': 12, 'fat': 4.5, 'sodium': 145}],
{'carbs': 'less than 1 g', 'cholesterol': '10 mg', 'fat': '4.5 g', 'sodium': '150 mg'}],
['repair check: half-up tie rounding',
[{'calories': 129, 'carbs': 1.5, 'cholesterol': 7.5, 'fat': 5.75, 'sodium': 142.5}],
{'calories': '130', 'carbs': '2 g', 'cholesterol': '10 mg', 'fat': '6 g', 'sodium': '140 mg'}],
['generated control 1', [{'calories': 66.5, 'carbs': 0.2, 'fat': 1.75, 'sodium': 12.5}],
{'calories': '70', 'carbs': '0 g', 'fat': '2 g', 'sodium': '15 mg'}],
['generated control 2', [{'calories': 217.5, 'cholesterol': 1.5, 'fat': 2.75, 'sodium': 145}],
{'calories': '220', 'cholesterol': '0 mg', 'fat': '3 g', 'sodium': '150 mg'}],
['generated control 3', [{'carbs': 0.5, 'fat': 15.25}], {'carbs': 'less than 1 g', 'fat': '15 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'}],
['small cholesterol', [{'carbs': 12.5, 'cholesterol': 3}],
{'carbs': '13 g', 'cholesterol': 'less than 5 mg'}],
['regression: half-up tie rounding', [{'calories': 12.25, 'carbs': 1, 'fat': 10.5, 'sodium': 137.5}],
{'calories': '10', 'carbs': '1 g', 'fat': '11 g', 'sodium': '140 mg'}],
['repair check: half-up tie rounding',
[{'calories': 200, 'carbs': 1, 'cholesterol': 1.5, 'fat': 2.75, 'sodium': 134}],
{'calories': '200', 'carbs': '1 g', 'cholesterol': '0 mg', 'fat': '3 g', 'sodium': '135 mg'}],
['generated control 1', [{'calories': 184.5, 'sodium': 5}], {'calories': '180', 'sodium': '5 mg'}],
['generated control 2', [{'calories': 96.5, 'carbs': 1.5, 'fat': 3.5, 'sodium': 7.5}],
{'calories': '100', 'carbs': '2 g', 'fat': '3.5 g', 'sodium': '10 mg'}],
['generated control 3', [{'calories': 1.25, 'cholesterol': 4.9, 'sodium': 142.5}],
{'calories': '0', 'cholesterol': 'less than 5 mg', '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'}],
['empty panel', [{}], {}],
['regression: half-up tie rounding', [{'calories': 4.6, 'cholesterol': 1.5, 'fat': 0, 'sodium': 12.5}],
{'calories': '0', 'cholesterol': '0 mg', 'fat': '0 g', 'sodium': '15 mg'}],
['repair check: half-up tie rounding', [{'calories': 41, 'cholesterol': 7.5}],
{'calories': '40', 'cholesterol': '10 mg'}],
['generated control 1', [{'calories': 2.5, 'carbs': 0.9, 'fat': 6, 'sodium': 137.5}],
{'calories': '0', 'carbs': 'less than 1 g', 'fat': '6 g', 'sodium': '140 mg'}],
['generated control 2', [{'fat': 0, 'sodium': 137}], {'fat': '0 g', 'sodium': '135 mg'}],
['generated control 3', [{'calories': 105, 'carbs': 0.2, 'cholesterol': 7.5, 'fat': 0.25, 'sodium': 2.75}],
{'calories': '110', 'carbs': '0 g', 'cholesterol': '10 mg', 'fat': '0 g', 'sodium': '0 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: half-up tie rounding', [{'calories': 89.5, 'fat': 1.25, 'sodium': 137.5}],
{'calories': '90', 'fat': '1.5 g', 'sodium': '140 mg'}],
['repair check: half-up tie rounding', [{'fat': 4.75, 'sodium': 7.5}], {'fat': '5 g', 'sodium': '10 mg'}],
['generated control 1', [{'calories': 89.5, 'carbs': 30.4, 'cholesterol': 5, 'fat': 15.5, 'sodium': 12.5}],
{'calories': '90', 'carbs': '30 g', 'cholesterol': '5 mg', 'fat': '16 g', 'sodium': '15 mg'}],
['generated control 2', [{'calories': 40.25, 'cholesterol': 2.2, 'fat': 7.5}],
{'calories': '40', 'cholesterol': 'less than 5 mg', 'fat': '8 g'}],
['generated control 3', [{'calories': 42.5, 'fat': 6.25, 'sodium': 142.5}],
{'calories': '45', 'fat': '6 g', 'sodium': '140 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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| 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: half-up tie rounding | {'calories': '160', 'carbs': 'less than 1 g', 'fat': '1.5 g', 'sodium': '10 mg'} | {'calories': '160', 'carbs': 'less than 1 g', 'fat': '1.5 g', 'sodium': '10 mg'} | Passed |
| repair check: half-up tie rounding | {'calories': '60', 'cholesterol': '5 mg', 'fat': '1.5 g', 'sodium': '140 mg'} | {'calories': '60', 'cholesterol': '5 mg', 'fat': '1.5 g', 'sodium': '140 mg'} | Passed |
| generated control 1 | {'carbs': '30 g', 'sodium': '0 mg'} | {'carbs': '30 g', 'sodium': '0 mg'} | Passed |
| generated control 2 | {'calories': '0', 'cholesterol': '25 mg', 'fat': '1.5 g', 'sodium': '5 mg'} | {'calories': '0', 'cholesterol': '25 mg', 'fat': '1.5 g', 'sodium': '5 mg'} | Passed |
| generated control 3 | {'calories': '10', 'carbs': 'less than 1 g', 'fat': '3 g', 'sodium': '0 mg'} | {'calories': '10', 'carbs': 'less than 1 g', 'fat': '3 g', 'sodium': '0 mg'} | Passed |
SHA-256 / 350fc77fb0d83777e33348c6e7929022581fa35b1b0dcc968983e86741e29d3d
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.914730+00:00.
Case digest / 8ec366b40bddc90c5a8d2158367a0266c799c1e9e1304e012c12f5843c3bb325