FAILURE MAP
← Case archive

FA-97016 / Recipe scaling and nutrition / Open access

Percent daily value formatter: micronutrient floor band · case 01

Calcium at 1.5% prints "2%" and 0.5% prints "<1%".

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

ROOT CAUSE

Micronutrients use the macronutrient "<1%" floor instead of "<2%".

THE FAILURE

Micronutrients use the macronutrient "<1%" floor instead of "<2%".

Unsuccessful approach: Using <= 2 hides an exact 2% as "<2%".

Case contract

DVs: sodium 2300 mg, fat 78 g, fiber 28 g, calcium 1300 mg, vitamin d 20 mcg, added sugars 50 g, protein 50 g. Names are trimmed, case-insensitive; unknown -> "error: no daily value". Units g, mg, mcg convert exactly; "iu" is allowed only for vitamin d (40 IU = 1 mcg), else "error: unit". pct = amount/DV*100. Zero -> "0%". Calcium and vitamin d: <2 -> "<2%", <=10 -> nearest 2, <=50 -> nearest 5, else nearest 10. Others: <1 -> "<1%", else nearest 1. Half-up.

Why this case matters

Label software prints %DV with different increments for micronutrients and macronutrients.

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(nutrient, amount, unit):
    DV = {'sodium': (2300, 'mg'), 'fat': (78, 'g'), 'fiber': (28, 'g'), 'calcium': (1300, 'mg'),
          'vitamin d': (20, 'mcg'), 'added sugars': (50, 'g'), 'protein': (50, 'g')}
    SCALE = {'g': 1000000, 'mg': 1000, 'mcg': 1}
    key = nutrient.strip().lower()
    if key not in DV:
        return 'error: no daily value'
    amt = Fraction(str(amount))
    if unit == 'iu':
        if key != 'vitamin d':
            return 'error: unit'
        amt, unit = amt / 40, 'mcg'
    if unit not in SCALE:
        return 'error: unit'
    dv, dvu = DV[key]
    p = amt * SCALE[unit] / (dv * SCALE[dvu]) * 100
    def near(v, s):
        return math.floor(v / s + Fraction(1, 2)) * s
    if p == 0:
        return '0%'
    if key in ('calcium', 'vitamin d'):
        if p < 1:
            return '<1%'
        v = near(p, 2) if p <= 10 else near(p, 5) if p <= 50 else near(p, 10)
    else:
        if p < 1:
            return '<1%'
        v = near(p, 1)
    return '%d%%' % v
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['sodium control', ['sodium', 460, 'mg'], '20%'],
  ['calcium exactly two percent', ['calcium', 26, 'mg'], '2%'],
  ['vitamin d in IU', ['vitamin d', 400, 'iu'], '50%'],
  ['regression: micronutrient floor band', ['CALCIUM', 5, 'mg'], '<2%'],
  ['repair check: micronutrient floor band', ['CALCIUM', 26, 'mg'], '2%'],
  ['generated control 1', [' Sodium', 0, 'mg'], '0%'], ['generated control 2', ['protein', 40, 'mcg'], '<1%'],
  ['generated control 3', ['iron', 2300, 'g'], 'error: no daily value']],
 [['calcium exactly two percent', ['calcium', 26, 'mg'], '2%'],
  ['vitamin d in IU', ['vitamin d', 400, 'iu'], '50%'], ['fat in grams', ['fat', 3, 'g'], '4%'],
  ['regression: micronutrient floor band', ['calcium', 0.2, 'mcg'], '<2%'],
  ['generated control 1', ['calcium', 2300, 'iu'], 'error: unit'],
  ['generated control 2', [' Sodium', 0.39, 'mg'], '<1%'],
  ['generated control 3', ['fiber', 300, 'mg'], '1%'],
  ['generated control 4', ['sodium', 300, 'mcg'], '<1%']],
 [['vitamin d in IU', ['vitamin d', 400, 'iu'], '50%'], ['fat in grams', ['fat', 3, 'g'], '4%'],
  ['zero calcium', ['calcium', 0, 'mg'], '0%'],
  ['regression: micronutrient floor band', ['CALCIUM', 0.2, 'mcg'], '<2%'],
  ['repair check: micronutrient floor band', ['CALCIUM', 26, 'mg'], '2%'],
  ['generated control 1', ['sodium', 700, 'g'], '30435%'], ['generated control 2', ['fiber', 1, 'mg'], '<1%'],
  ['generated control 3', ['added sugars', 2300, 'mg'], '5%']],
 [['fat in grams', ['fat', 3, 'g'], '4%'], ['zero calcium', ['calcium', 0, 'mg'], '0%'],
  ['iu for sodium rejected', ['sodium', 10, 'iu'], 'error: unit'],
  ['regression: micronutrient floor band', ['calcium', 260, 'mcg'], '<2%'],
  ['repair check: micronutrient floor band', ['CALCIUM', 26, 'mg'], '2%'],
  ['generated control 1', ['calcium', 0, 'g'], '0%'],
  ['generated control 2', ['calcium', 0.5, 'iu'], 'error: unit'],
  ['generated control 3', ['added sugars', 0, 'mg'], '0%']],
 [['zero calcium', ['calcium', 0, 'mg'], '0%'],
  ['iu for sodium rejected', ['sodium', 10, 'iu'], 'error: unit'],
  ['sodium control', ['sodium', 460, 'mg'], '20%'],
  ['regression: micronutrient floor band', ['CALCIUM', 3, 'mg'], '<2%'],
  ['repair check: micronutrient floor band', ['calcium', 26, 'mg'], '2%'],
  ['generated control 1', ['vitamin d', 300, 'mg'], '1500000%'],
  ['generated control 2', ['protein', 40, 'g'], '80%'],
  ['generated control 3', ['added sugars', 2, 'mcg'], '<1%']]]
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
sodium control20%20%Passed
calcium exactly two percent2%2%Passed
vitamin d in IU50%50%Passed
regression: micronutrient floor band<1%<2%Failed
repair check: micronutrient floor band2%2%Passed
generated control 10%0%Passed
generated control 2<1%<1%Passed
generated control 3error: no daily valueerror: no daily valuePassed

SHA-256 / 0ad3084c588b1d3624794483c70dd01203f6c08b58c83930262ad2d22c8dd4d1

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(nutrient, amount, unit):
    DV = {'sodium': (2300, 'mg'), 'fat': (78, 'g'), 'fiber': (28, 'g'), 'calcium': (1300, 'mg'),
          'vitamin d': (20, 'mcg'), 'added sugars': (50, 'g'), 'protein': (50, 'g')}
    SCALE = {'g': 1000000, 'mg': 1000, 'mcg': 1}
    key = nutrient.strip().lower()
    if key not in DV:
        return 'error: no daily value'
    amt = Fraction(str(amount))
    if unit == 'iu':
        if key != 'vitamin d':
            return 'error: unit'
        amt, unit = amt / 40, 'mcg'
    if unit not in SCALE:
        return 'error: unit'
    dv, dvu = DV[key]
    p = amt * SCALE[unit] / (dv * SCALE[dvu]) * 100
    def near(v, s):
        return math.floor(v / s + Fraction(1, 2)) * s
    if p == 0:
        return '0%'
    if key in ('calcium', 'vitamin d'):
        if p <= 2:
            return '<2%'
        v = near(p, 2) if p <= 10 else near(p, 5) if p <= 50 else near(p, 10)
    else:
        if p < 1:
            return '<1%'
        v = near(p, 1)
    return '%d%%' % v
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['sodium control', ['sodium', 460, 'mg'], '20%'],
  ['calcium exactly two percent', ['calcium', 26, 'mg'], '2%'],
  ['vitamin d in IU', ['vitamin d', 400, 'iu'], '50%'],
  ['regression: micronutrient floor band', ['CALCIUM', 5, 'mg'], '<2%'],
  ['repair check: micronutrient floor band', ['CALCIUM', 26, 'mg'], '2%'],
  ['generated control 1', [' Sodium', 0, 'mg'], '0%'], ['generated control 2', ['protein', 40, 'mcg'], '<1%'],
  ['generated control 3', ['iron', 2300, 'g'], 'error: no daily value']],
 [['calcium exactly two percent', ['calcium', 26, 'mg'], '2%'],
  ['vitamin d in IU', ['vitamin d', 400, 'iu'], '50%'], ['fat in grams', ['fat', 3, 'g'], '4%'],
  ['regression: micronutrient floor band', ['calcium', 0.2, 'mcg'], '<2%'],
  ['generated control 1', ['calcium', 2300, 'iu'], 'error: unit'],
  ['generated control 2', [' Sodium', 0.39, 'mg'], '<1%'],
  ['generated control 3', ['fiber', 300, 'mg'], '1%'],
  ['generated control 4', ['sodium', 300, 'mcg'], '<1%']],
 [['vitamin d in IU', ['vitamin d', 400, 'iu'], '50%'], ['fat in grams', ['fat', 3, 'g'], '4%'],
  ['zero calcium', ['calcium', 0, 'mg'], '0%'],
  ['regression: micronutrient floor band', ['CALCIUM', 0.2, 'mcg'], '<2%'],
  ['repair check: micronutrient floor band', ['CALCIUM', 26, 'mg'], '2%'],
  ['generated control 1', ['sodium', 700, 'g'], '30435%'], ['generated control 2', ['fiber', 1, 'mg'], '<1%'],
  ['generated control 3', ['added sugars', 2300, 'mg'], '5%']],
 [['fat in grams', ['fat', 3, 'g'], '4%'], ['zero calcium', ['calcium', 0, 'mg'], '0%'],
  ['iu for sodium rejected', ['sodium', 10, 'iu'], 'error: unit'],
  ['regression: micronutrient floor band', ['calcium', 260, 'mcg'], '<2%'],
  ['repair check: micronutrient floor band', ['CALCIUM', 26, 'mg'], '2%'],
  ['generated control 1', ['calcium', 0, 'g'], '0%'],
  ['generated control 2', ['calcium', 0.5, 'iu'], 'error: unit'],
  ['generated control 3', ['added sugars', 0, 'mg'], '0%']],
 [['zero calcium', ['calcium', 0, 'mg'], '0%'],
  ['iu for sodium rejected', ['sodium', 10, 'iu'], 'error: unit'],
  ['sodium control', ['sodium', 460, 'mg'], '20%'],
  ['regression: micronutrient floor band', ['CALCIUM', 3, 'mg'], '<2%'],
  ['repair check: micronutrient floor band', ['calcium', 26, 'mg'], '2%'],
  ['generated control 1', ['vitamin d', 300, 'mg'], '1500000%'],
  ['generated control 2', ['protein', 40, 'g'], '80%'],
  ['generated control 3', ['added sugars', 2, 'mcg'], '<1%']]]
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
sodium control20%20%Passed
calcium exactly two percent<2%2%Failed
vitamin d in IU50%50%Passed
regression: micronutrient floor band<2%<2%Passed
repair check: micronutrient floor band<2%2%Failed
generated control 10%0%Passed
generated control 2<1%<1%Passed
generated control 3error: no daily valueerror: no daily valuePassed

SHA-256 / 53013280a90d76a9f526ea7d974dba8329cf9079d2a420e10c0f1b9750b31922

HELD IN THE MEMBER ARCHIVE

The verified repair and its recorded checks are member-only.

This mechanism has 8 recorded checks per implementation. The open-access tier publishes the failure and the unsuccessful fix; the repaired source that passes every check, and the observations that prove it, are available to members.

Every case sharing this mechanism uses the same contract and the same repair, so this one record is held back for all of them.

Member access is invitation-based. Sign in with your invited account to inspect the repair.

Sign in to the archive ↗

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:28.014799+00:00.

Case digest / 4748ee4b8ccf54a60c299cc7a52699bf1deeb5a77999ecd8edf1d3c75d440466