FAILURE MAP
← Case archive

FA-97131 / Recipe scaling and nutrition / Open access

Shopping list aggregator: double-s guard · case 01

Watercress is listed as "watercres".

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

ROOT CAUSE

The singularizer strips the s from words ending in "ss".

VERIFIED REPAIR

Keep words ending in "ss" unchanged.

Unsuccessful approach: A consonant-before-s rule still clips "watercress" and fails to singularize "peas".

Case contract

Rows [name, qty, unit]. Names normalize: trim, lower, "-oes" -> drop "es", "-ies" -> "y", other trailing "s" dropped unless "ss". Volume (tsp=1, tbsp=3, cup=48 tsp), mass (g, kg=1000 g) and other units aggregate separately per name. Pantry {name: [qty, unit]} subtracts from the same name and dimension, never below 0. Output sorted by (name, dimension) as [name, str(qty), unit], skipping zero totals; volume shows cup if >=12 tsp, else tbsp if >=3 tsp, else tsp; mass shows kg if >=1000 g.

Why this case matters

Meal planners merge ingredient lists across recipes and subtract what is already in the pantry.

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(recipes, pantry):
    VOL = {'tsp': 1, 'tbsp': 3, 'cup': 48}
    MASS = {'g': 1, 'kg': 1000}
    def norm(n):
        n = n.strip().lower()
        if n.endswith('oes'):
            return n[:-2]
        if n.endswith('ies'):
            return n[:-3] + 'y'
        if n.endswith('s'):
            return n[:-1]
        return n
    def base(q, u):
        if u in VOL:
            return 'volume', Fraction(q) * VOL[u]
        if u in MASS:
            return 'mass', Fraction(q) * MASS[u]
        return u, Fraction(q)
    tot = {}
    for recipe in recipes:
        for name, q, u in recipe:
            dim, v = base(q, u)
            k = (norm(name), dim)
            tot[k] = tot.get(k, 0) + v
    for name, (q, u) in pantry.items():
        dim, v = base(q, u)
        pk = (norm(name), dim)
        if pk in tot:
            tot[pk] = max(Fraction(0), tot[pk] - v)
    out = []
    for (name, dim), v in sorted(tot.items()):
        if v == 0:
            continue
        if dim == 'volume':
            unit, v2 = ('cup', v / 48) if v >= 12 else ('tbsp', v / 3) if v >= 3 else ('tsp', v)
        elif dim == 'mass':
            unit, v2 = ('kg', v / 1000) if v >= 1000 else ('g', v)
        else:
            unit, v2 = dim, v
        out.append([name, str(v2), unit])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['single recipe', [[[['flour', '1', 'cup']]], {}], [['flour', '1', 'cup']]],
  ['merge plurals', [[[['tomatoes', '2', 'each']], [['Tomato', '1', 'each']]], {}],
   [['tomato', '3', 'each']]],
  ['pantry covers all', [[[['eggs', '2', 'each']]], {'egg': ['6', 'each']}], []],
  ['regression: double-s guard',
   [[[['berries', '1/3', 'cup'], ['egg', '1/2', 'tbsp'], ['eggs', '2', 'tbsp']], [['berries', '3', 'g']],
     [['Tomato', '1', 'cup'], ['sugar ', '2', 'kg'], ['berries', '1', 'tsp'], ['watercress', '3/4', 'cup']]],
    {'egg': ['1/3', 'tbsp'], 'peas': ['4', 'tsp']}],
   [['berry', '3', 'g'], ['berry', '17/48', 'cup'], ['egg', '13/6', 'tbsp'], ['sugar', '2', 'kg'],
    ['tomato', '1', 'cup'], ['watercress', '3/4', 'cup']]],
  ['repair check: double-s guard',
   [[[['grape', '3', 'tbsp'], ['peas', '1/3', 'cup'], ['peas', '1/2', 'each']]],
    {'potatoes': ['3/4', 'tsp']}],
   [['grape', '3', 'tbsp'], ['pea', '1/2', 'each'], ['pea', '1/3', 'cup']]],
  ['generated control 1', [[[['grapes', '2', 'kg'], ['potatoes', '1/3', 'tsp']]], {}],
   [['grape', '2', 'kg'], ['potato', '1/3', 'tsp']]],
  ['generated control 2',
   [[[['tomatoes', '3/4', 'tsp'], ['grape', '4', 'g']],
     [['grape', '1/4', 'g'], ['berries', '4', 'g'], ['flour', '1/2', 'kg']]],
    {}],
   [['berry', '4', 'g'], ['flour', '500', 'g'], ['grape', '17/4', 'g'], ['tomato', '3/4', 'tsp']]],
  ['generated control 3',
   [[[['potatoes', '1/4', 'tsp'], ['grape', '1/2', 'tbsp']],
     [['sugar ', '3', 'tsp'], ['sugar ', '4', 'kg'], ['potatoes', '3', 'g'], ['potatoes', '1', 'g']],
     [['Tomato', '1/4', 'g'], ['sugar ', '4', 'kg']]],
    {}],
   [['grape', '3/2', 'tsp'], ['potato', '4', 'g'], ['potato', '1/4', 'tsp'], ['sugar', '8', 'kg'],
    ['sugar', '1', 'tbsp'], ['tomato', '1/4', 'g']]]],
 [['merge plurals', [[[['tomatoes', '2', 'each']], [['Tomato', '1', 'each']]], {}],
   [['tomato', '3', 'each']]],
  ['pantry covers all', [[[['eggs', '2', 'each']]], {'egg': ['6', 'each']}], []],
  ['watercress keeps ss', [[[['watercress', '100', 'g']]], {}], [['watercress', '100', 'g']]],
  ['regression: double-s guard',
   [[[['watercress', '1/2', 'tbsp'], ['flour', '1/3', 'g'], ['tomatoes', '3', 'tbsp']],
     [['tomatoes', '1/2', 'g'], ['Tomato', '1', 'g'], ['egg', '3', 'g'], ['tomatoes', '1/3', 'cup']],
     [['eggs', '1/4', 'kg'], ['flour', '1/3', 'tbsp']]],
    {'tomatoes': ['1/4', 'g']}],
   [['egg', '253', 'g'], ['flour', '1/3', 'g'], ['flour', '1', 'tsp'], ['tomato', '5/4', 'g'],
    ['tomato', '25/48', 'cup'], ['watercress', '3/2', 'tsp']]],
  ['repair check: double-s guard',
   [[[['peas', '3', 'cup'], ['grape', '1', 'g']],
     [['peas', '1/3', 'kg'], ['egg', '3/4', 'tbsp'], ['tomatoes', '3/4', 'tsp'], ['tomatoes', '4', 'tsp']],
     [['flour', '2', 'tsp'], ['tomatoes', '1/2', 'cup'], ['potatoes', '1/4', 'cup'], ['flour', '4', 'kg']]],
    {}],
   [['egg', '9/4', 'tsp'], ['flour', '4', 'kg'], ['flour', '2', 'tsp'], ['grape', '1', 'g'],
    ['pea', '1000/3', 'g'], ['pea', '3', 'cup'], ['potato', '1/4', 'cup'], ['tomato', '115/192', 'cup']]],
  ['generated control 1', [[[['sugar ', '1/3', 'kg']]], {'berry': ['1/4', 'g'], 'sugar ': ['3', 'tbsp']}],
   [['sugar', '1000/3', 'g']]],
  ['generated control 2',
   [[[['potatoes', '1/2', 'tbsp'], ['flour', '1/3', 'tsp']], [['peas', '3/4', 'kg']],
     [['Tomato', '3', 'tbsp'], ['peas', '1/3', 'kg'], ['berries', '1/4', 'g']]],
    {'peas': ['1/2', 'kg']}],
   [['berry', '1/4', 'g'], ['flour', '1/3', 'tsp'], ['pea', '1750/3', 'g'], ['potato', '3/2', 'tsp'],
    ['tomato', '3', 'tbsp']]],
  ['generated control 3',
   [[[['flour', '1/2', 'each']],
     [['egg', '1/2', 'g'], ['eggs', '1', 'kg'], ['sugar ', '1/4', 'each'], ['Tomato', '4', 'tbsp']]],
    {'berry': ['1/3', 'g'], 'potatoes': ['1/4', 'tbsp']}],
   [['egg', '2001/2000', 'kg'], ['flour', '1/2', 'each'], ['sugar', '1/4', 'each'],
    ['tomato', '1/4', 'cup']]]],
 [['pantry covers all', [[[['eggs', '2', 'each']]], {'egg': ['6', 'each']}], []],
  ['watercress keeps ss', [[[['watercress', '100', 'g']]], {}], [['watercress', '100', 'g']]],
  ['single recipe', [[[['flour', '1', 'cup']]], {}], [['flour', '1', 'cup']]],
  ['regression: double-s guard',
   [[[['eggs', '2', 'each']], [['watercress', '4', 'g'], ['peas', '1/2', 'tsp'], ['tomatoes', '1/2', 'kg']]],
    {'peas': ['1/3', 'each']}],
   [['egg', '2', 'each'], ['pea', '1/2', 'tsp'], ['tomato', '500', 'g'], ['watercress', '4', 'g']]],
  ['repair check: double-s guard',
   [[[['eggs', '4', 'tbsp'], ['potatoes', '1/2', 'kg'], ['sugar ', '3/4', 'tbsp']],
     [['berry', '1/4', 'each']],
     [['eggs', '4', 'each'], ['grape', '1', 'tsp'], ['peas', '1/4', 'tbsp'], ['egg', '1/4', 'kg']]],
    {'watercress': ['1/3', 'each']}],
   [['berry', '1/4', 'each'], ['egg', '4', 'each'], ['egg', '250', 'g'], ['egg', '1/4', 'cup'],
    ['grape', '1', 'tsp'], ['pea', '3/4', 'tsp'], ['potato', '500', 'g'], ['sugar', '9/4', 'tsp']]],
  ['generated control 1',
   [[[['sugar ', '3', 'tsp'], ['egg', '2', 'tbsp']], [['egg', '1/2', 'each'], ['flour', '1', 'each']]],
    {'eggs': ['3', 'g'], 'tomatoes': ['1', 'tsp']}],
   [['egg', '1/2', 'each'], ['egg', '2', 'tbsp'], ['flour', '1', 'each'], ['sugar', '1', 'tbsp']]],
  ['generated control 2',
   [[[['grape', '3', 'tsp'], ['Tomato', '3/4', 'cup'], ['potatoes', '2', 'kg']],
     [['watercress', '3/4', 'each'], ['Tomato', '3/4', 'tsp'], ['berries', '2', 'each'],
      ['flour', '1', 'tbsp']],
     [['egg', '1/2', 'g'], ['potatoes', '1/3', 'g']]],
    {}],
   [['berry', '2', 'each'], ['egg', '1/2', 'g'], ['flour', '1', 'tbsp'], ['grape', '1', 'tbsp'],
    ['potato', '6001/3000', 'kg'], ['tomato', '49/64', 'cup'], ['watercress', '3/4', 'each']]],
  ['generated control 3', [[[['watercress', '2', 'g'], ['eggs', '1', 'tbsp']]], {'potatoes': ['4', 'cup']}],
   [['egg', '1', 'tbsp'], ['watercress', '2', 'g']]]],
 [['watercress keeps ss', [[[['watercress', '100', 'g']]], {}], [['watercress', '100', 'g']]],
  ['single recipe', [[[['flour', '1', 'cup']]], {}], [['flour', '1', 'cup']]],
  ['merge plurals', [[[['tomatoes', '2', 'each']], [['Tomato', '1', 'each']]], {}],
   [['tomato', '3', 'each']]],
  ['regression: double-s guard',
   [[[['watercress', '1/4', 'tbsp'], ['potatoes', '3', 'g'], ['egg', '1/4', 'tbsp']],
     [['berry', '4', 'g'], ['egg', '4', 'each'], ['flour', '4', 'kg'], ['tomatoes', '3', 'g']],
     [['tomatoes', '1/4', 'each'], ['potatoes', '2', 'each']]],
    {}],
   [['berry', '4', 'g'], ['egg', '4', 'each'], ['egg', '3/4', 'tsp'], ['flour', '4', 'kg'],
    ['potato', '2', 'each'], ['potato', '3', 'g'], ['tomato', '1/4', 'each'], ['tomato', '3', 'g'],
    ['watercress', '3/4', 'tsp']]],
  ['repair check: double-s guard',
   [[[['potatoes', '1', 'tbsp']],
     [['egg', '1/3', 'cup'], ['eggs', '1/3', 'g'], ['grape', '1/2', 'g'], ['grapes', '1/3', 'kg']]],
    {}],
   [['egg', '1/3', 'g'], ['egg', '1/3', 'cup'], ['grape', '2003/6', 'g'], ['potato', '1', 'tbsp']]],
  ['generated control 1',
   [[[['eggs', '1/4', 'tsp'], ['tomatoes', '1', 'kg']], [['eggs', '1/3', 'each']]],
    {'peas': ['4', 'g'], 'sugar ': ['1/4', 'each']}],
   [['egg', '1/3', 'each'], ['egg', '1/4', 'tsp'], ['tomato', '1', 'kg']]],
  ['generated control 2',
   [[[['sugar ', '1/4', 'g'], ['Tomato', '2', 'tsp']]], {'berries': ['1/2', 'tbsp'], 'eggs': ['3', 'each']}],
   [['sugar', '1/4', 'g'], ['tomato', '2', 'tsp']]],
  ['generated control 3',
   [[[['egg', '3/4', 'cup'], ['egg', '4', 'tbsp'], ['grapes', '1/2', 'tsp']]], {'flour': ['1', 'cup']}],
   [['egg', '1', 'cup'], ['grape', '1/2', 'tsp']]]],
 [['single recipe', [[[['flour', '1', 'cup']]], {}], [['flour', '1', 'cup']]],
  ['merge plurals', [[[['tomatoes', '2', 'each']], [['Tomato', '1', 'each']]], {}],
   [['tomato', '3', 'each']]],
  ['pantry covers all', [[[['eggs', '2', 'each']]], {'egg': ['6', 'each']}], []],
  ['regression: double-s guard',
   [[[['potatoes', '3/4', 'tsp'], ['eggs', '2', 'each'], ['watercress', '1/2', 'each'], ['egg', '1', 'kg']]],
    {'flour': ['3/4', 'tbsp']}],
   [['egg', '2', 'each'], ['egg', '1', 'kg'], ['potato', '3/4', 'tsp'], ['watercress', '1/2', 'each']]],
  ['repair check: double-s guard',
   [[[['watercress', '3', 'kg'], ['flour', '4', 'tsp']], [['grapes', '1/2', 'tsp']]],
    {'eggs': ['1', 'tbsp']}],
   [['flour', '4/3', 'tbsp'], ['grape', '1/2', 'tsp'], ['watercress', '3', 'kg']]],
  ['generated control 1', [[[['eggs', '3/4', 'kg']]], {}], [['egg', '750', 'g']]],
  ['generated control 2', [[[['Tomato', '1/4', 'each']]], {}], [['tomato', '1/4', 'each']]],
  ['generated control 3',
   [[[['grape', '1', 'cup'], ['grape', '1', 'g'], ['Tomato', '1', 'g']],
     [['berry', '4', 'g'], ['potatoes', '4', 'g']]],
    {'watercress': ['1/3', 'tsp']}],
   [['berry', '4', 'g'], ['grape', '1', 'g'], ['grape', '1', 'cup'], ['potato', '4', 'g'],
    ['tomato', '1', 'g']]]]]
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
single recipe[['flour', '1', 'cup']][['flour', '1', 'cup']]Passed
merge plurals[['tomato', '3', 'each']][['tomato', '3', 'each']]Passed
pantry covers all[][]Passed
regression: double-s guard[['berry', '3', 'g'], ['berry', '17/48', 'cup'], ['egg', '13/6', 'tbsp'], ['sugar', '2', 'kg'], ['tomato', '1', 'cup'], ['watercres', '3/4', 'cup']][['berry', '3', 'g'], ['berry', '17/48', 'cup'], ['egg', '13/6', 'tbsp'], ['sugar', '2', 'kg'], ['tomato', '1', 'cup'], ['watercress', '3/4', 'cup']]Failed
repair check: double-s guard[['grape', '3', 'tbsp'], ['pea', '1/2', 'each'], ['pea', '1/3', 'cup']][['grape', '3', 'tbsp'], ['pea', '1/2', 'each'], ['pea', '1/3', 'cup']]Passed
generated control 1[['grape', '2', 'kg'], ['potato', '1/3', 'tsp']][['grape', '2', 'kg'], ['potato', '1/3', 'tsp']]Passed
generated control 2[['berry', '4', 'g'], ['flour', '500', 'g'], ['grape', '17/4', 'g'], ['tomato', '3/4', 'tsp']][['berry', '4', 'g'], ['flour', '500', 'g'], ['grape', '17/4', 'g'], ['tomato', '3/4', 'tsp']]Passed
generated control 3[['grape', '3/2', 'tsp'], ['potato', '4', 'g'], ['potato', '1/4', 'tsp'], ['sugar', '8', 'kg'], ['sugar', '1', 'tbsp'], ['tomato', '1/4', 'g']][['grape', '3/2', 'tsp'], ['potato', '4', 'g'], ['potato', '1/4', 'tsp'], ['sugar', '8', 'kg'], ['sugar', '1', 'tbsp'], ['tomato', '1/4', 'g']]Passed

SHA-256 / 2514a75a73e4becfc0f4e9dd454414de1c4ec8cc0b9eec5b700472bb983474ba

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(recipes, pantry):
    VOL = {'tsp': 1, 'tbsp': 3, 'cup': 48}
    MASS = {'g': 1, 'kg': 1000}
    def norm(n):
        n = n.strip().lower()
        if n.endswith('oes'):
            return n[:-2]
        if n.endswith('ies'):
            return n[:-3] + 'y'
        if n.endswith('s') and n[-2] not in 'aeiou':
            return n[:-1]
        return n
    def base(q, u):
        if u in VOL:
            return 'volume', Fraction(q) * VOL[u]
        if u in MASS:
            return 'mass', Fraction(q) * MASS[u]
        return u, Fraction(q)
    tot = {}
    for recipe in recipes:
        for name, q, u in recipe:
            dim, v = base(q, u)
            k = (norm(name), dim)
            tot[k] = tot.get(k, 0) + v
    for name, (q, u) in pantry.items():
        dim, v = base(q, u)
        pk = (norm(name), dim)
        if pk in tot:
            tot[pk] = max(Fraction(0), tot[pk] - v)
    out = []
    for (name, dim), v in sorted(tot.items()):
        if v == 0:
            continue
        if dim == 'volume':
            unit, v2 = ('cup', v / 48) if v >= 12 else ('tbsp', v / 3) if v >= 3 else ('tsp', v)
        elif dim == 'mass':
            unit, v2 = ('kg', v / 1000) if v >= 1000 else ('g', v)
        else:
            unit, v2 = dim, v
        out.append([name, str(v2), unit])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['single recipe', [[[['flour', '1', 'cup']]], {}], [['flour', '1', 'cup']]],
  ['merge plurals', [[[['tomatoes', '2', 'each']], [['Tomato', '1', 'each']]], {}],
   [['tomato', '3', 'each']]],
  ['pantry covers all', [[[['eggs', '2', 'each']]], {'egg': ['6', 'each']}], []],
  ['regression: double-s guard',
   [[[['berries', '1/3', 'cup'], ['egg', '1/2', 'tbsp'], ['eggs', '2', 'tbsp']], [['berries', '3', 'g']],
     [['Tomato', '1', 'cup'], ['sugar ', '2', 'kg'], ['berries', '1', 'tsp'], ['watercress', '3/4', 'cup']]],
    {'egg': ['1/3', 'tbsp'], 'peas': ['4', 'tsp']}],
   [['berry', '3', 'g'], ['berry', '17/48', 'cup'], ['egg', '13/6', 'tbsp'], ['sugar', '2', 'kg'],
    ['tomato', '1', 'cup'], ['watercress', '3/4', 'cup']]],
  ['repair check: double-s guard',
   [[[['grape', '3', 'tbsp'], ['peas', '1/3', 'cup'], ['peas', '1/2', 'each']]],
    {'potatoes': ['3/4', 'tsp']}],
   [['grape', '3', 'tbsp'], ['pea', '1/2', 'each'], ['pea', '1/3', 'cup']]],
  ['generated control 1', [[[['grapes', '2', 'kg'], ['potatoes', '1/3', 'tsp']]], {}],
   [['grape', '2', 'kg'], ['potato', '1/3', 'tsp']]],
  ['generated control 2',
   [[[['tomatoes', '3/4', 'tsp'], ['grape', '4', 'g']],
     [['grape', '1/4', 'g'], ['berries', '4', 'g'], ['flour', '1/2', 'kg']]],
    {}],
   [['berry', '4', 'g'], ['flour', '500', 'g'], ['grape', '17/4', 'g'], ['tomato', '3/4', 'tsp']]],
  ['generated control 3',
   [[[['potatoes', '1/4', 'tsp'], ['grape', '1/2', 'tbsp']],
     [['sugar ', '3', 'tsp'], ['sugar ', '4', 'kg'], ['potatoes', '3', 'g'], ['potatoes', '1', 'g']],
     [['Tomato', '1/4', 'g'], ['sugar ', '4', 'kg']]],
    {}],
   [['grape', '3/2', 'tsp'], ['potato', '4', 'g'], ['potato', '1/4', 'tsp'], ['sugar', '8', 'kg'],
    ['sugar', '1', 'tbsp'], ['tomato', '1/4', 'g']]]],
 [['merge plurals', [[[['tomatoes', '2', 'each']], [['Tomato', '1', 'each']]], {}],
   [['tomato', '3', 'each']]],
  ['pantry covers all', [[[['eggs', '2', 'each']]], {'egg': ['6', 'each']}], []],
  ['watercress keeps ss', [[[['watercress', '100', 'g']]], {}], [['watercress', '100', 'g']]],
  ['regression: double-s guard',
   [[[['watercress', '1/2', 'tbsp'], ['flour', '1/3', 'g'], ['tomatoes', '3', 'tbsp']],
     [['tomatoes', '1/2', 'g'], ['Tomato', '1', 'g'], ['egg', '3', 'g'], ['tomatoes', '1/3', 'cup']],
     [['eggs', '1/4', 'kg'], ['flour', '1/3', 'tbsp']]],
    {'tomatoes': ['1/4', 'g']}],
   [['egg', '253', 'g'], ['flour', '1/3', 'g'], ['flour', '1', 'tsp'], ['tomato', '5/4', 'g'],
    ['tomato', '25/48', 'cup'], ['watercress', '3/2', 'tsp']]],
  ['repair check: double-s guard',
   [[[['peas', '3', 'cup'], ['grape', '1', 'g']],
     [['peas', '1/3', 'kg'], ['egg', '3/4', 'tbsp'], ['tomatoes', '3/4', 'tsp'], ['tomatoes', '4', 'tsp']],
     [['flour', '2', 'tsp'], ['tomatoes', '1/2', 'cup'], ['potatoes', '1/4', 'cup'], ['flour', '4', 'kg']]],
    {}],
   [['egg', '9/4', 'tsp'], ['flour', '4', 'kg'], ['flour', '2', 'tsp'], ['grape', '1', 'g'],
    ['pea', '1000/3', 'g'], ['pea', '3', 'cup'], ['potato', '1/4', 'cup'], ['tomato', '115/192', 'cup']]],
  ['generated control 1', [[[['sugar ', '1/3', 'kg']]], {'berry': ['1/4', 'g'], 'sugar ': ['3', 'tbsp']}],
   [['sugar', '1000/3', 'g']]],
  ['generated control 2',
   [[[['potatoes', '1/2', 'tbsp'], ['flour', '1/3', 'tsp']], [['peas', '3/4', 'kg']],
     [['Tomato', '3', 'tbsp'], ['peas', '1/3', 'kg'], ['berries', '1/4', 'g']]],
    {'peas': ['1/2', 'kg']}],
   [['berry', '1/4', 'g'], ['flour', '1/3', 'tsp'], ['pea', '1750/3', 'g'], ['potato', '3/2', 'tsp'],
    ['tomato', '3', 'tbsp']]],
  ['generated control 3',
   [[[['flour', '1/2', 'each']],
     [['egg', '1/2', 'g'], ['eggs', '1', 'kg'], ['sugar ', '1/4', 'each'], ['Tomato', '4', 'tbsp']]],
    {'berry': ['1/3', 'g'], 'potatoes': ['1/4', 'tbsp']}],
   [['egg', '2001/2000', 'kg'], ['flour', '1/2', 'each'], ['sugar', '1/4', 'each'],
    ['tomato', '1/4', 'cup']]]],
 [['pantry covers all', [[[['eggs', '2', 'each']]], {'egg': ['6', 'each']}], []],
  ['watercress keeps ss', [[[['watercress', '100', 'g']]], {}], [['watercress', '100', 'g']]],
  ['single recipe', [[[['flour', '1', 'cup']]], {}], [['flour', '1', 'cup']]],
  ['regression: double-s guard',
   [[[['eggs', '2', 'each']], [['watercress', '4', 'g'], ['peas', '1/2', 'tsp'], ['tomatoes', '1/2', 'kg']]],
    {'peas': ['1/3', 'each']}],
   [['egg', '2', 'each'], ['pea', '1/2', 'tsp'], ['tomato', '500', 'g'], ['watercress', '4', 'g']]],
  ['repair check: double-s guard',
   [[[['eggs', '4', 'tbsp'], ['potatoes', '1/2', 'kg'], ['sugar ', '3/4', 'tbsp']],
     [['berry', '1/4', 'each']],
     [['eggs', '4', 'each'], ['grape', '1', 'tsp'], ['peas', '1/4', 'tbsp'], ['egg', '1/4', 'kg']]],
    {'watercress': ['1/3', 'each']}],
   [['berry', '1/4', 'each'], ['egg', '4', 'each'], ['egg', '250', 'g'], ['egg', '1/4', 'cup'],
    ['grape', '1', 'tsp'], ['pea', '3/4', 'tsp'], ['potato', '500', 'g'], ['sugar', '9/4', 'tsp']]],
  ['generated control 1',
   [[[['sugar ', '3', 'tsp'], ['egg', '2', 'tbsp']], [['egg', '1/2', 'each'], ['flour', '1', 'each']]],
    {'eggs': ['3', 'g'], 'tomatoes': ['1', 'tsp']}],
   [['egg', '1/2', 'each'], ['egg', '2', 'tbsp'], ['flour', '1', 'each'], ['sugar', '1', 'tbsp']]],
  ['generated control 2',
   [[[['grape', '3', 'tsp'], ['Tomato', '3/4', 'cup'], ['potatoes', '2', 'kg']],
     [['watercress', '3/4', 'each'], ['Tomato', '3/4', 'tsp'], ['berries', '2', 'each'],
      ['flour', '1', 'tbsp']],
     [['egg', '1/2', 'g'], ['potatoes', '1/3', 'g']]],
    {}],
   [['berry', '2', 'each'], ['egg', '1/2', 'g'], ['flour', '1', 'tbsp'], ['grape', '1', 'tbsp'],
    ['potato', '6001/3000', 'kg'], ['tomato', '49/64', 'cup'], ['watercress', '3/4', 'each']]],
  ['generated control 3', [[[['watercress', '2', 'g'], ['eggs', '1', 'tbsp']]], {'potatoes': ['4', 'cup']}],
   [['egg', '1', 'tbsp'], ['watercress', '2', 'g']]]],
 [['watercress keeps ss', [[[['watercress', '100', 'g']]], {}], [['watercress', '100', 'g']]],
  ['single recipe', [[[['flour', '1', 'cup']]], {}], [['flour', '1', 'cup']]],
  ['merge plurals', [[[['tomatoes', '2', 'each']], [['Tomato', '1', 'each']]], {}],
   [['tomato', '3', 'each']]],
  ['regression: double-s guard',
   [[[['watercress', '1/4', 'tbsp'], ['potatoes', '3', 'g'], ['egg', '1/4', 'tbsp']],
     [['berry', '4', 'g'], ['egg', '4', 'each'], ['flour', '4', 'kg'], ['tomatoes', '3', 'g']],
     [['tomatoes', '1/4', 'each'], ['potatoes', '2', 'each']]],
    {}],
   [['berry', '4', 'g'], ['egg', '4', 'each'], ['egg', '3/4', 'tsp'], ['flour', '4', 'kg'],
    ['potato', '2', 'each'], ['potato', '3', 'g'], ['tomato', '1/4', 'each'], ['tomato', '3', 'g'],
    ['watercress', '3/4', 'tsp']]],
  ['repair check: double-s guard',
   [[[['potatoes', '1', 'tbsp']],
     [['egg', '1/3', 'cup'], ['eggs', '1/3', 'g'], ['grape', '1/2', 'g'], ['grapes', '1/3', 'kg']]],
    {}],
   [['egg', '1/3', 'g'], ['egg', '1/3', 'cup'], ['grape', '2003/6', 'g'], ['potato', '1', 'tbsp']]],
  ['generated control 1',
   [[[['eggs', '1/4', 'tsp'], ['tomatoes', '1', 'kg']], [['eggs', '1/3', 'each']]],
    {'peas': ['4', 'g'], 'sugar ': ['1/4', 'each']}],
   [['egg', '1/3', 'each'], ['egg', '1/4', 'tsp'], ['tomato', '1', 'kg']]],
  ['generated control 2',
   [[[['sugar ', '1/4', 'g'], ['Tomato', '2', 'tsp']]], {'berries': ['1/2', 'tbsp'], 'eggs': ['3', 'each']}],
   [['sugar', '1/4', 'g'], ['tomato', '2', 'tsp']]],
  ['generated control 3',
   [[[['egg', '3/4', 'cup'], ['egg', '4', 'tbsp'], ['grapes', '1/2', 'tsp']]], {'flour': ['1', 'cup']}],
   [['egg', '1', 'cup'], ['grape', '1/2', 'tsp']]]],
 [['single recipe', [[[['flour', '1', 'cup']]], {}], [['flour', '1', 'cup']]],
  ['merge plurals', [[[['tomatoes', '2', 'each']], [['Tomato', '1', 'each']]], {}],
   [['tomato', '3', 'each']]],
  ['pantry covers all', [[[['eggs', '2', 'each']]], {'egg': ['6', 'each']}], []],
  ['regression: double-s guard',
   [[[['potatoes', '3/4', 'tsp'], ['eggs', '2', 'each'], ['watercress', '1/2', 'each'], ['egg', '1', 'kg']]],
    {'flour': ['3/4', 'tbsp']}],
   [['egg', '2', 'each'], ['egg', '1', 'kg'], ['potato', '3/4', 'tsp'], ['watercress', '1/2', 'each']]],
  ['repair check: double-s guard',
   [[[['watercress', '3', 'kg'], ['flour', '4', 'tsp']], [['grapes', '1/2', 'tsp']]],
    {'eggs': ['1', 'tbsp']}],
   [['flour', '4/3', 'tbsp'], ['grape', '1/2', 'tsp'], ['watercress', '3', 'kg']]],
  ['generated control 1', [[[['eggs', '3/4', 'kg']]], {}], [['egg', '750', 'g']]],
  ['generated control 2', [[[['Tomato', '1/4', 'each']]], {}], [['tomato', '1/4', 'each']]],
  ['generated control 3',
   [[[['grape', '1', 'cup'], ['grape', '1', 'g'], ['Tomato', '1', 'g']],
     [['berry', '4', 'g'], ['potatoes', '4', 'g']]],
    {'watercress': ['1/3', 'tsp']}],
   [['berry', '4', 'g'], ['grape', '1', 'g'], ['grape', '1', 'cup'], ['potato', '4', 'g'],
    ['tomato', '1', 'g']]]]]
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
single recipe[['flour', '1', 'cup']][['flour', '1', 'cup']]Passed
merge plurals[['tomato', '3', 'each']][['tomato', '3', 'each']]Passed
pantry covers all[][]Passed
regression: double-s guard[['berry', '3', 'g'], ['berry', '17/48', 'cup'], ['egg', '13/6', 'tbsp'], ['sugar', '2', 'kg'], ['tomato', '1', 'cup'], ['watercres', '3/4', 'cup']][['berry', '3', 'g'], ['berry', '17/48', 'cup'], ['egg', '13/6', 'tbsp'], ['sugar', '2', 'kg'], ['tomato', '1', 'cup'], ['watercress', '3/4', 'cup']]Failed
repair check: double-s guard[['grape', '3', 'tbsp'], ['peas', '1/2', 'each'], ['peas', '1/3', 'cup']][['grape', '3', 'tbsp'], ['pea', '1/2', 'each'], ['pea', '1/3', 'cup']]Failed
generated control 1[['grapes', '2', 'kg'], ['potato', '1/3', 'tsp']][['grape', '2', 'kg'], ['potato', '1/3', 'tsp']]Failed
generated control 2[['berry', '4', 'g'], ['flour', '500', 'g'], ['grape', '17/4', 'g'], ['tomato', '3/4', 'tsp']][['berry', '4', 'g'], ['flour', '500', 'g'], ['grape', '17/4', 'g'], ['tomato', '3/4', 'tsp']]Passed
generated control 3[['grape', '3/2', 'tsp'], ['potato', '4', 'g'], ['potato', '1/4', 'tsp'], ['sugar', '8', 'kg'], ['sugar', '1', 'tbsp'], ['tomato', '1/4', 'g']][['grape', '3/2', 'tsp'], ['potato', '4', 'g'], ['potato', '1/4', 'tsp'], ['sugar', '8', 'kg'], ['sugar', '1', 'tbsp'], ['tomato', '1/4', 'g']]Passed

SHA-256 / eb32b8f9f4bf9fffefab3435f6e5b5158c87a5d0d59f7af880be4b0439c093b4

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(recipes, pantry):
    VOL = {'tsp': 1, 'tbsp': 3, 'cup': 48}
    MASS = {'g': 1, 'kg': 1000}
    def norm(n):
        n = n.strip().lower()
        if n.endswith('oes'):
            return n[:-2]
        if n.endswith('ies'):
            return n[:-3] + 'y'
        if n.endswith('s') and not n.endswith('ss'):
            return n[:-1]
        return n
    def base(q, u):
        if u in VOL:
            return 'volume', Fraction(q) * VOL[u]
        if u in MASS:
            return 'mass', Fraction(q) * MASS[u]
        return u, Fraction(q)
    tot = {}
    for recipe in recipes:
        for name, q, u in recipe:
            dim, v = base(q, u)
            k = (norm(name), dim)
            tot[k] = tot.get(k, 0) + v
    for name, (q, u) in pantry.items():
        dim, v = base(q, u)
        pk = (norm(name), dim)
        if pk in tot:
            tot[pk] = max(Fraction(0), tot[pk] - v)
    out = []
    for (name, dim), v in sorted(tot.items()):
        if v == 0:
            continue
        if dim == 'volume':
            unit, v2 = ('cup', v / 48) if v >= 12 else ('tbsp', v / 3) if v >= 3 else ('tsp', v)
        elif dim == 'mass':
            unit, v2 = ('kg', v / 1000) if v >= 1000 else ('g', v)
        else:
            unit, v2 = dim, v
        out.append([name, str(v2), unit])
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['single recipe', [[[['flour', '1', 'cup']]], {}], [['flour', '1', 'cup']]],
  ['merge plurals', [[[['tomatoes', '2', 'each']], [['Tomato', '1', 'each']]], {}],
   [['tomato', '3', 'each']]],
  ['pantry covers all', [[[['eggs', '2', 'each']]], {'egg': ['6', 'each']}], []],
  ['regression: double-s guard',
   [[[['berries', '1/3', 'cup'], ['egg', '1/2', 'tbsp'], ['eggs', '2', 'tbsp']], [['berries', '3', 'g']],
     [['Tomato', '1', 'cup'], ['sugar ', '2', 'kg'], ['berries', '1', 'tsp'], ['watercress', '3/4', 'cup']]],
    {'egg': ['1/3', 'tbsp'], 'peas': ['4', 'tsp']}],
   [['berry', '3', 'g'], ['berry', '17/48', 'cup'], ['egg', '13/6', 'tbsp'], ['sugar', '2', 'kg'],
    ['tomato', '1', 'cup'], ['watercress', '3/4', 'cup']]],
  ['repair check: double-s guard',
   [[[['grape', '3', 'tbsp'], ['peas', '1/3', 'cup'], ['peas', '1/2', 'each']]],
    {'potatoes': ['3/4', 'tsp']}],
   [['grape', '3', 'tbsp'], ['pea', '1/2', 'each'], ['pea', '1/3', 'cup']]],
  ['generated control 1', [[[['grapes', '2', 'kg'], ['potatoes', '1/3', 'tsp']]], {}],
   [['grape', '2', 'kg'], ['potato', '1/3', 'tsp']]],
  ['generated control 2',
   [[[['tomatoes', '3/4', 'tsp'], ['grape', '4', 'g']],
     [['grape', '1/4', 'g'], ['berries', '4', 'g'], ['flour', '1/2', 'kg']]],
    {}],
   [['berry', '4', 'g'], ['flour', '500', 'g'], ['grape', '17/4', 'g'], ['tomato', '3/4', 'tsp']]],
  ['generated control 3',
   [[[['potatoes', '1/4', 'tsp'], ['grape', '1/2', 'tbsp']],
     [['sugar ', '3', 'tsp'], ['sugar ', '4', 'kg'], ['potatoes', '3', 'g'], ['potatoes', '1', 'g']],
     [['Tomato', '1/4', 'g'], ['sugar ', '4', 'kg']]],
    {}],
   [['grape', '3/2', 'tsp'], ['potato', '4', 'g'], ['potato', '1/4', 'tsp'], ['sugar', '8', 'kg'],
    ['sugar', '1', 'tbsp'], ['tomato', '1/4', 'g']]]],
 [['merge plurals', [[[['tomatoes', '2', 'each']], [['Tomato', '1', 'each']]], {}],
   [['tomato', '3', 'each']]],
  ['pantry covers all', [[[['eggs', '2', 'each']]], {'egg': ['6', 'each']}], []],
  ['watercress keeps ss', [[[['watercress', '100', 'g']]], {}], [['watercress', '100', 'g']]],
  ['regression: double-s guard',
   [[[['watercress', '1/2', 'tbsp'], ['flour', '1/3', 'g'], ['tomatoes', '3', 'tbsp']],
     [['tomatoes', '1/2', 'g'], ['Tomato', '1', 'g'], ['egg', '3', 'g'], ['tomatoes', '1/3', 'cup']],
     [['eggs', '1/4', 'kg'], ['flour', '1/3', 'tbsp']]],
    {'tomatoes': ['1/4', 'g']}],
   [['egg', '253', 'g'], ['flour', '1/3', 'g'], ['flour', '1', 'tsp'], ['tomato', '5/4', 'g'],
    ['tomato', '25/48', 'cup'], ['watercress', '3/2', 'tsp']]],
  ['repair check: double-s guard',
   [[[['peas', '3', 'cup'], ['grape', '1', 'g']],
     [['peas', '1/3', 'kg'], ['egg', '3/4', 'tbsp'], ['tomatoes', '3/4', 'tsp'], ['tomatoes', '4', 'tsp']],
     [['flour', '2', 'tsp'], ['tomatoes', '1/2', 'cup'], ['potatoes', '1/4', 'cup'], ['flour', '4', 'kg']]],
    {}],
   [['egg', '9/4', 'tsp'], ['flour', '4', 'kg'], ['flour', '2', 'tsp'], ['grape', '1', 'g'],
    ['pea', '1000/3', 'g'], ['pea', '3', 'cup'], ['potato', '1/4', 'cup'], ['tomato', '115/192', 'cup']]],
  ['generated control 1', [[[['sugar ', '1/3', 'kg']]], {'berry': ['1/4', 'g'], 'sugar ': ['3', 'tbsp']}],
   [['sugar', '1000/3', 'g']]],
  ['generated control 2',
   [[[['potatoes', '1/2', 'tbsp'], ['flour', '1/3', 'tsp']], [['peas', '3/4', 'kg']],
     [['Tomato', '3', 'tbsp'], ['peas', '1/3', 'kg'], ['berries', '1/4', 'g']]],
    {'peas': ['1/2', 'kg']}],
   [['berry', '1/4', 'g'], ['flour', '1/3', 'tsp'], ['pea', '1750/3', 'g'], ['potato', '3/2', 'tsp'],
    ['tomato', '3', 'tbsp']]],
  ['generated control 3',
   [[[['flour', '1/2', 'each']],
     [['egg', '1/2', 'g'], ['eggs', '1', 'kg'], ['sugar ', '1/4', 'each'], ['Tomato', '4', 'tbsp']]],
    {'berry': ['1/3', 'g'], 'potatoes': ['1/4', 'tbsp']}],
   [['egg', '2001/2000', 'kg'], ['flour', '1/2', 'each'], ['sugar', '1/4', 'each'],
    ['tomato', '1/4', 'cup']]]],
 [['pantry covers all', [[[['eggs', '2', 'each']]], {'egg': ['6', 'each']}], []],
  ['watercress keeps ss', [[[['watercress', '100', 'g']]], {}], [['watercress', '100', 'g']]],
  ['single recipe', [[[['flour', '1', 'cup']]], {}], [['flour', '1', 'cup']]],
  ['regression: double-s guard',
   [[[['eggs', '2', 'each']], [['watercress', '4', 'g'], ['peas', '1/2', 'tsp'], ['tomatoes', '1/2', 'kg']]],
    {'peas': ['1/3', 'each']}],
   [['egg', '2', 'each'], ['pea', '1/2', 'tsp'], ['tomato', '500', 'g'], ['watercress', '4', 'g']]],
  ['repair check: double-s guard',
   [[[['eggs', '4', 'tbsp'], ['potatoes', '1/2', 'kg'], ['sugar ', '3/4', 'tbsp']],
     [['berry', '1/4', 'each']],
     [['eggs', '4', 'each'], ['grape', '1', 'tsp'], ['peas', '1/4', 'tbsp'], ['egg', '1/4', 'kg']]],
    {'watercress': ['1/3', 'each']}],
   [['berry', '1/4', 'each'], ['egg', '4', 'each'], ['egg', '250', 'g'], ['egg', '1/4', 'cup'],
    ['grape', '1', 'tsp'], ['pea', '3/4', 'tsp'], ['potato', '500', 'g'], ['sugar', '9/4', 'tsp']]],
  ['generated control 1',
   [[[['sugar ', '3', 'tsp'], ['egg', '2', 'tbsp']], [['egg', '1/2', 'each'], ['flour', '1', 'each']]],
    {'eggs': ['3', 'g'], 'tomatoes': ['1', 'tsp']}],
   [['egg', '1/2', 'each'], ['egg', '2', 'tbsp'], ['flour', '1', 'each'], ['sugar', '1', 'tbsp']]],
  ['generated control 2',
   [[[['grape', '3', 'tsp'], ['Tomato', '3/4', 'cup'], ['potatoes', '2', 'kg']],
     [['watercress', '3/4', 'each'], ['Tomato', '3/4', 'tsp'], ['berries', '2', 'each'],
      ['flour', '1', 'tbsp']],
     [['egg', '1/2', 'g'], ['potatoes', '1/3', 'g']]],
    {}],
   [['berry', '2', 'each'], ['egg', '1/2', 'g'], ['flour', '1', 'tbsp'], ['grape', '1', 'tbsp'],
    ['potato', '6001/3000', 'kg'], ['tomato', '49/64', 'cup'], ['watercress', '3/4', 'each']]],
  ['generated control 3', [[[['watercress', '2', 'g'], ['eggs', '1', 'tbsp']]], {'potatoes': ['4', 'cup']}],
   [['egg', '1', 'tbsp'], ['watercress', '2', 'g']]]],
 [['watercress keeps ss', [[[['watercress', '100', 'g']]], {}], [['watercress', '100', 'g']]],
  ['single recipe', [[[['flour', '1', 'cup']]], {}], [['flour', '1', 'cup']]],
  ['merge plurals', [[[['tomatoes', '2', 'each']], [['Tomato', '1', 'each']]], {}],
   [['tomato', '3', 'each']]],
  ['regression: double-s guard',
   [[[['watercress', '1/4', 'tbsp'], ['potatoes', '3', 'g'], ['egg', '1/4', 'tbsp']],
     [['berry', '4', 'g'], ['egg', '4', 'each'], ['flour', '4', 'kg'], ['tomatoes', '3', 'g']],
     [['tomatoes', '1/4', 'each'], ['potatoes', '2', 'each']]],
    {}],
   [['berry', '4', 'g'], ['egg', '4', 'each'], ['egg', '3/4', 'tsp'], ['flour', '4', 'kg'],
    ['potato', '2', 'each'], ['potato', '3', 'g'], ['tomato', '1/4', 'each'], ['tomato', '3', 'g'],
    ['watercress', '3/4', 'tsp']]],
  ['repair check: double-s guard',
   [[[['potatoes', '1', 'tbsp']],
     [['egg', '1/3', 'cup'], ['eggs', '1/3', 'g'], ['grape', '1/2', 'g'], ['grapes', '1/3', 'kg']]],
    {}],
   [['egg', '1/3', 'g'], ['egg', '1/3', 'cup'], ['grape', '2003/6', 'g'], ['potato', '1', 'tbsp']]],
  ['generated control 1',
   [[[['eggs', '1/4', 'tsp'], ['tomatoes', '1', 'kg']], [['eggs', '1/3', 'each']]],
    {'peas': ['4', 'g'], 'sugar ': ['1/4', 'each']}],
   [['egg', '1/3', 'each'], ['egg', '1/4', 'tsp'], ['tomato', '1', 'kg']]],
  ['generated control 2',
   [[[['sugar ', '1/4', 'g'], ['Tomato', '2', 'tsp']]], {'berries': ['1/2', 'tbsp'], 'eggs': ['3', 'each']}],
   [['sugar', '1/4', 'g'], ['tomato', '2', 'tsp']]],
  ['generated control 3',
   [[[['egg', '3/4', 'cup'], ['egg', '4', 'tbsp'], ['grapes', '1/2', 'tsp']]], {'flour': ['1', 'cup']}],
   [['egg', '1', 'cup'], ['grape', '1/2', 'tsp']]]],
 [['single recipe', [[[['flour', '1', 'cup']]], {}], [['flour', '1', 'cup']]],
  ['merge plurals', [[[['tomatoes', '2', 'each']], [['Tomato', '1', 'each']]], {}],
   [['tomato', '3', 'each']]],
  ['pantry covers all', [[[['eggs', '2', 'each']]], {'egg': ['6', 'each']}], []],
  ['regression: double-s guard',
   [[[['potatoes', '3/4', 'tsp'], ['eggs', '2', 'each'], ['watercress', '1/2', 'each'], ['egg', '1', 'kg']]],
    {'flour': ['3/4', 'tbsp']}],
   [['egg', '2', 'each'], ['egg', '1', 'kg'], ['potato', '3/4', 'tsp'], ['watercress', '1/2', 'each']]],
  ['repair check: double-s guard',
   [[[['watercress', '3', 'kg'], ['flour', '4', 'tsp']], [['grapes', '1/2', 'tsp']]],
    {'eggs': ['1', 'tbsp']}],
   [['flour', '4/3', 'tbsp'], ['grape', '1/2', 'tsp'], ['watercress', '3', 'kg']]],
  ['generated control 1', [[[['eggs', '3/4', 'kg']]], {}], [['egg', '750', 'g']]],
  ['generated control 2', [[[['Tomato', '1/4', 'each']]], {}], [['tomato', '1/4', 'each']]],
  ['generated control 3',
   [[[['grape', '1', 'cup'], ['grape', '1', 'g'], ['Tomato', '1', 'g']],
     [['berry', '4', 'g'], ['potatoes', '4', 'g']]],
    {'watercress': ['1/3', 'tsp']}],
   [['berry', '4', 'g'], ['grape', '1', 'g'], ['grape', '1', 'cup'], ['potato', '4', 'g'],
    ['tomato', '1', 'g']]]]]
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
single recipe[['flour', '1', 'cup']][['flour', '1', 'cup']]Passed
merge plurals[['tomato', '3', 'each']][['tomato', '3', 'each']]Passed
pantry covers all[][]Passed
regression: double-s guard[['berry', '3', 'g'], ['berry', '17/48', 'cup'], ['egg', '13/6', 'tbsp'], ['sugar', '2', 'kg'], ['tomato', '1', 'cup'], ['watercress', '3/4', 'cup']][['berry', '3', 'g'], ['berry', '17/48', 'cup'], ['egg', '13/6', 'tbsp'], ['sugar', '2', 'kg'], ['tomato', '1', 'cup'], ['watercress', '3/4', 'cup']]Passed
repair check: double-s guard[['grape', '3', 'tbsp'], ['pea', '1/2', 'each'], ['pea', '1/3', 'cup']][['grape', '3', 'tbsp'], ['pea', '1/2', 'each'], ['pea', '1/3', 'cup']]Passed
generated control 1[['grape', '2', 'kg'], ['potato', '1/3', 'tsp']][['grape', '2', 'kg'], ['potato', '1/3', 'tsp']]Passed
generated control 2[['berry', '4', 'g'], ['flour', '500', 'g'], ['grape', '17/4', 'g'], ['tomato', '3/4', 'tsp']][['berry', '4', 'g'], ['flour', '500', 'g'], ['grape', '17/4', 'g'], ['tomato', '3/4', 'tsp']]Passed
generated control 3[['grape', '3/2', 'tsp'], ['potato', '4', 'g'], ['potato', '1/4', 'tsp'], ['sugar', '8', 'kg'], ['sugar', '1', 'tbsp'], ['tomato', '1/4', 'g']][['grape', '3/2', 'tsp'], ['potato', '4', 'g'], ['potato', '1/4', 'tsp'], ['sugar', '8', 'kg'], ['sugar', '1', 'tbsp'], ['tomato', '1/4', 'g']]Passed

SHA-256 / 4dc0e7465f8114bc2638e7cd6c69a27f314fb818c30e3e320837ac52eed00391

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

Case digest / 47754f0fb91333a6e99adf45332ad2456b3ece8d9b392ec4836bb0f72f28a6f4