Functional Weave
Code in Rust

hospitality.recipe-cost@1.0.0

vectors.json

9,134 bytes · view raw

[
  {"name": "a batter for 8: grams from a kilo bag, a whole pack, eggs by the dozen, millilitres from a litre bottle", "args": [[{"name": "flour", "quantity": "500", "unit": "g", "yieldBasisPoints": 10000, "packSize": "1.5", "packUnit": "kg", "packPrice": {"minor": 180, "currency": "GBP"}}, {"name": "butter", "quantity": "250", "unit": "g", "yieldBasisPoints": 10000, "packSize": "250", "packUnit": "g", "packPrice": {"minor": 210, "currency": "GBP"}}, {"name": "eggs", "quantity": "3", "unit": "each", "yieldBasisPoints": 10000, "packSize": "12", "packUnit": "each", "packPrice": {"minor": 390, "currency": "GBP"}}, {"name": "milk", "quantity": "300", "unit": "mL", "yieldBasisPoints": 10000, "packSize": "2", "packUnit": "L", "packPrice": {"minor": 165, "currency": "GBP"}}], 8, "GBP"], "expect": {"lines": [{"name": "flour", "cost": {"minor": 60, "currency": "GBP"}}, {"name": "butter", "cost": {"minor": 210, "currency": "GBP"}}, {"name": "eggs", "cost": {"minor": 98, "currency": "GBP"}}, {"name": "milk", "cost": {"minor": 25, "currency": "GBP"}}], "total": {"minor": 393, "currency": "GBP"}, "portions": 8, "perPortion": {"minor": 49, "currency": "GBP"}}},
  {"name": "yield grosses up: 400 g peeled at 80% yield means 500 g bought, not 320 g", "args": [[{"name": "carrots", "quantity": "400", "unit": "g", "yieldBasisPoints": 8000, "packSize": "10", "packUnit": "kg", "packPrice": {"minor": 450, "currency": "GBP"}}], 4, "GBP"], "expect": {"lines": [{"name": "carrots", "cost": {"minor": 23, "currency": "GBP"}}], "total": {"minor": 23, "currency": "GBP"}, "portions": 4, "perPortion": {"minor": 6, "currency": "GBP"}}},
  {"name": "imperial: 8 oz from a 1 lb pack", "args": [[{"name": "butter", "quantity": "8", "unit": "oz", "yieldBasisPoints": 10000, "packSize": "1", "packUnit": "lb", "packPrice": {"minor": 300, "currency": "GBP"}}], 2, "GBP"], "expect": {"lines": [{"name": "butter", "cost": {"minor": 150, "currency": "GBP"}}], "total": {"minor": 150, "currency": "GBP"}, "portions": 2, "perPortion": {"minor": 75, "currency": "GBP"}}},
  {"name": "metric recipe, imperial pack: 100 g of a 1 lb pack is 0.220462262 lb", "args": [[{"name": "cheese", "quantity": "100", "unit": "g", "yieldBasisPoints": 10000, "packSize": "1", "packUnit": "lb", "packPrice": {"minor": 454, "currency": "GBP"}}], 1, "GBP"], "expect": {"lines": [{"name": "cheese", "cost": {"minor": 100, "currency": "GBP"}}], "total": {"minor": 100, "currency": "GBP"}, "portions": 1, "perPortion": {"minor": 100, "currency": "GBP"}}},
  {"name": "a pinch costs less than a penny and rounds to nothing", "args": [[{"name": "salt", "quantity": "1", "unit": "g", "yieldBasisPoints": 10000, "packSize": "1", "packUnit": "kg", "packPrice": {"minor": 65, "currency": "GBP"}}], 1, "GBP"], "expect": {"lines": [{"name": "salt", "cost": {"minor": 0, "currency": "GBP"}}], "total": {"minor": 0, "currency": "GBP"}, "portions": 1, "perPortion": {"minor": 0, "currency": "GBP"}}},
  {"name": "saffron by the gram", "args": [[{"name": "saffron", "quantity": "0.4", "unit": "g", "yieldBasisPoints": 10000, "packSize": "1", "packUnit": "g", "packPrice": {"minor": 800, "currency": "GBP"}}], 4, "GBP"], "expect": {"lines": [{"name": "saffron", "cost": {"minor": 320, "currency": "GBP"}}], "total": {"minor": 320, "currency": "GBP"}, "portions": 4, "perPortion": {"minor": 80, "currency": "GBP"}}},
  {"name": "a zero quantity costs nothing", "args": [[{"name": "garnish", "quantity": "0", "unit": "g", "yieldBasisPoints": 10000, "packSize": "100", "packUnit": "g", "packPrice": {"minor": 150, "currency": "GBP"}}], 1, "GBP"], "expect": {"lines": [{"name": "garnish", "cost": {"minor": 0, "currency": "GBP"}}], "total": {"minor": 0, "currency": "GBP"}, "portions": 1, "perPortion": {"minor": 0, "currency": "GBP"}}},
  {"name": "the portion cost rounds half-up: 0.10 over 4 is 0.025", "args": [[{"name": "lemon", "quantity": "1", "unit": "each", "yieldBasisPoints": 10000, "packSize": "1", "packUnit": "each", "packPrice": {"minor": 10, "currency": "GBP"}}], 4, "GBP"], "expect": {"lines": [{"name": "lemon", "cost": {"minor": 10, "currency": "GBP"}}], "total": {"minor": 10, "currency": "GBP"}, "portions": 4, "perPortion": {"minor": 3, "currency": "GBP"}}},
  {"name": "a fractional pack size: 0.75 L bottle of wine", "args": [[{"name": "wine", "quantity": "150", "unit": "mL", "yieldBasisPoints": 10000, "packSize": "0.75", "packUnit": "L", "packPrice": {"minor": 900, "currency": "GBP"}}], 1, "GBP"], "expect": {"lines": [{"name": "wine", "cost": {"minor": 180, "currency": "GBP"}}], "total": {"minor": 180, "currency": "GBP"}, "portions": 1, "perPortion": {"minor": 180, "currency": "GBP"}}},
  {"name": "half an egg", "args": [[{"name": "egg wash", "quantity": "0.5", "unit": "each", "yieldBasisPoints": 10000, "packSize": "6", "packUnit": "each", "packPrice": {"minor": 199, "currency": "GBP"}}], 1, "GBP"], "expect": {"lines": [{"name": "egg wash", "cost": {"minor": 17, "currency": "GBP"}}], "total": {"minor": 17, "currency": "GBP"}, "portions": 1, "perPortion": {"minor": 17, "currency": "GBP"}}},
  {"name": "euros", "args": [[{"name": "flour", "quantity": "500", "unit": "g", "yieldBasisPoints": 10000, "packSize": "1", "packUnit": "kg", "packPrice": {"minor": 129, "currency": "EUR"}}], 2, "EUR"], "expect": {"lines": [{"name": "flour", "cost": {"minor": 65, "currency": "EUR"}}], "total": {"minor": 65, "currency": "EUR"}, "portions": 2, "perPortion": {"minor": 33, "currency": "EUR"}}},
  {"name": "mass priced by volume is an error", "args": [[{"name": "oil", "quantity": "100", "unit": "g", "yieldBasisPoints": 10000, "packSize": "1", "packUnit": "L", "packPrice": {"minor": 300, "currency": "GBP"}}], 1, "GBP"], "expectError": "cannot convert g (mass) to L (volume)"},
  {"name": "each against grams is an error", "args": [[{"name": "eggs", "quantity": "2", "unit": "each", "yieldBasisPoints": 10000, "packSize": "600", "packUnit": "g", "packPrice": {"minor": 300, "currency": "GBP"}}], 1, "GBP"], "expectError": "cannot convert each to g"},
  {"name": "an unknown unit is an error", "args": [[{"name": "sugar", "quantity": "1", "unit": "cup", "yieldBasisPoints": 10000, "packSize": "1", "packUnit": "kg", "packPrice": {"minor": 100, "currency": "GBP"}}], 1, "GBP"], "expectError": "unknown unit \"cup\""},
  {"name": "a zero yield is an error", "args": [[{"name": "x", "quantity": "1", "unit": "g", "yieldBasisPoints": 0, "packSize": "1", "packUnit": "kg", "packPrice": {"minor": 100, "currency": "GBP"}}], 1, "GBP"], "expectError": "yieldBasisPoints must be from 1 to 10000"},
  {"name": "a yield over 100% is an error", "args": [[{"name": "x", "quantity": "1", "unit": "g", "yieldBasisPoints": 10001, "packSize": "1", "packUnit": "kg", "packPrice": {"minor": 100, "currency": "GBP"}}], 1, "GBP"], "expectError": "yieldBasisPoints must be from 1 to 10000"},
  {"name": "no portions is an error", "args": [[{"name": "flour", "quantity": "500", "unit": "g", "yieldBasisPoints": 10000, "packSize": "1.5", "packUnit": "kg", "packPrice": {"minor": 180, "currency": "GBP"}}, {"name": "butter", "quantity": "250", "unit": "g", "yieldBasisPoints": 10000, "packSize": "250", "packUnit": "g", "packPrice": {"minor": 210, "currency": "GBP"}}, {"name": "eggs", "quantity": "3", "unit": "each", "yieldBasisPoints": 10000, "packSize": "12", "packUnit": "each", "packPrice": {"minor": 390, "currency": "GBP"}}, {"name": "milk", "quantity": "300", "unit": "mL", "yieldBasisPoints": 10000, "packSize": "2", "packUnit": "L", "packPrice": {"minor": 165, "currency": "GBP"}}], 0, "GBP"], "expectError": "portions must be at least 1"},
  {"name": "an empty recipe is an error", "args": [[], 1, "GBP"], "expectError": "a recipe needs at least one ingredient"},
  {"name": "a negative quantity is an error", "args": [[{"name": "x", "quantity": "-1", "unit": "g", "yieldBasisPoints": 10000, "packSize": "1", "packUnit": "kg", "packPrice": {"minor": 100, "currency": "GBP"}}], 1, "GBP"], "expectError": "quantity must be a non-negative decimal"},
  {"name": "a zero pack size is an error", "args": [[{"name": "x", "quantity": "1", "unit": "g", "yieldBasisPoints": 10000, "packSize": "0", "packUnit": "kg", "packPrice": {"minor": 100, "currency": "GBP"}}], 1, "GBP"], "expectError": "packSize must be a positive decimal"},
  {"name": "a pack size with 7 decimal places is an error", "args": [[{"name": "x", "quantity": "1", "unit": "g", "yieldBasisPoints": 10000, "packSize": "1.0000001", "packUnit": "kg", "packPrice": {"minor": 100, "currency": "GBP"}}], 1, "GBP"], "expectError": "packSize must be a positive decimal"},
  {"name": "a negative pack price is an error", "args": [[{"name": "x", "quantity": "1", "unit": "g", "yieldBasisPoints": 10000, "packSize": "1", "packUnit": "kg", "packPrice": {"minor": -100, "currency": "GBP"}}], 1, "GBP"], "expectError": "packPrice must not be negative"},
  {"name": "a pack priced in another currency is an error", "args": [[{"name": "x", "quantity": "1", "unit": "g", "yieldBasisPoints": 10000, "packSize": "1", "packUnit": "kg", "packPrice": {"minor": 100, "currency": "EUR"}}], 1, "GBP"], "expectError": "currency mismatch"}
]