Functional Weave
Code in Rust

hospitality.tronc-allocation@1.0.0

vectors.json

7,388 bytes · view raw

[
  {"name": "by hours: 40, 30, 20 and 10 hours share 1000.00", "args": [{"minor": 100000, "currency": "GBP"}, [{"id": "ana", "minutesWorked": 2400, "points": 3}, {"id": "ben", "minutesWorked": 1800, "points": 2}, {"id": "cat", "minutesWorked": 1200, "points": 2}, {"id": "dev", "minutesWorked": 600, "points": 1}], "hours"], "expect": [{"id": "ana", "weight": 2400, "share": {"minor": 40000, "currency": "GBP"}}, {"id": "ben", "weight": 1800, "share": {"minor": 30000, "currency": "GBP"}}, {"id": "cat", "weight": 1200, "share": {"minor": 20000, "currency": "GBP"}}, {"id": "dev", "weight": 600, "share": {"minor": 10000, "currency": "GBP"}}]},
  {"name": "equal hours, the odd penny goes to the first listed", "args": [{"minor": 10000, "currency": "GBP"}, [{"id": "a", "minutesWorked": 60, "points": 1}, {"id": "b", "minutesWorked": 60, "points": 1}, {"id": "c", "minutesWorked": 60, "points": 1}], "hours"], "expect": [{"id": "a", "weight": 60, "share": {"minor": 3334, "currency": "GBP"}}, {"id": "b", "weight": 60, "share": {"minor": 3333, "currency": "GBP"}}, {"id": "c", "weight": 60, "share": {"minor": 3333, "currency": "GBP"}}]},
  {"name": "by points: 10, 7, 4 and 3 points share 500.00 without losing a penny", "args": [{"minor": 50000, "currency": "GBP"}, [{"id": "head-chef", "minutesWorked": 2400, "points": 10}, {"id": "sous-chef", "minutesWorked": 2400, "points": 7}, {"id": "commis", "minutesWorked": 2400, "points": 4}, {"id": "kitchen-porter", "minutesWorked": 2400, "points": 3}], "points"], "expect": [{"id": "head-chef", "weight": 10, "share": {"minor": 20834, "currency": "GBP"}}, {"id": "sous-chef", "weight": 7, "share": {"minor": 14583, "currency": "GBP"}}, {"id": "commis", "weight": 4, "share": {"minor": 8333, "currency": "GBP"}}, {"id": "kitchen-porter", "weight": 3, "share": {"minor": 6250, "currency": "GBP"}}]},
  {"name": "hours and points: minutes worked times points", "args": [{"minor": 84000, "currency": "GBP"}, [{"id": "a", "minutesWorked": 2400, "points": 2}, {"id": "b", "minutesWorked": 1800, "points": 1}, {"id": "c", "minutesWorked": 600, "points": 3}], "hours-and-points"], "expect": [{"id": "a", "weight": 4800, "share": {"minor": 48000, "currency": "GBP"}}, {"id": "b", "weight": 1800, "share": {"minor": 18000, "currency": "GBP"}}, {"id": "c", "weight": 1800, "share": {"minor": 18000, "currency": "GBP"}}]},
  {"name": "hours and points on the floor team", "args": [{"minor": 100000, "currency": "GBP"}, [{"id": "ana", "minutesWorked": 2400, "points": 3}, {"id": "ben", "minutesWorked": 1800, "points": 2}, {"id": "cat", "minutesWorked": 1200, "points": 2}, {"id": "dev", "minutesWorked": 600, "points": 1}], "hours-and-points"], "expect": [{"id": "ana", "weight": 7200, "share": {"minor": 52174, "currency": "GBP"}}, {"id": "ben", "weight": 3600, "share": {"minor": 26087, "currency": "GBP"}}, {"id": "cat", "weight": 2400, "share": {"minor": 17391, "currency": "GBP"}}, {"id": "dev", "weight": 600, "share": {"minor": 4348, "currency": "GBP"}}]},
  {"name": "a 7.5 hour shift is exact in minutes", "args": [{"minor": 1000, "currency": "GBP"}, [{"id": "a", "minutesWorked": 450, "points": 1}, {"id": "b", "minutesWorked": 450, "points": 1}], "hours"], "expect": [{"id": "a", "weight": 450, "share": {"minor": 500, "currency": "GBP"}}, {"id": "b", "weight": 450, "share": {"minor": 500, "currency": "GBP"}}]},
  {"name": "someone who worked no hours gets nothing", "args": [{"minor": 1001, "currency": "GBP"}, [{"id": "a", "minutesWorked": 480, "points": 1}, {"id": "b", "minutesWorked": 0, "points": 1}], "hours"], "expect": [{"id": "a", "weight": 480, "share": {"minor": 1001, "currency": "GBP"}}, {"id": "b", "weight": 0, "share": {"minor": 0, "currency": "GBP"}}]},
  {"name": "the leftover pennies go to the largest remainders, not the first listed", "args": [{"minor": 100, "currency": "GBP"}, [{"id": "a", "minutesWorked": 1, "points": 1}, {"id": "b", "minutesWorked": 2, "points": 1}, {"id": "c", "minutesWorked": 3, "points": 1}, {"id": "d", "minutesWorked": 1, "points": 1}], "hours"], "expect": [{"id": "a", "weight": 1, "share": {"minor": 14, "currency": "GBP"}}, {"id": "b", "weight": 2, "share": {"minor": 29, "currency": "GBP"}}, {"id": "c", "weight": 3, "share": {"minor": 43, "currency": "GBP"}}, {"id": "d", "weight": 1, "share": {"minor": 14, "currency": "GBP"}}]},
  {"name": "an empty pool shares nothing", "args": [{"minor": 0, "currency": "GBP"}, [{"id": "ana", "minutesWorked": 2400, "points": 3}, {"id": "ben", "minutesWorked": 1800, "points": 2}, {"id": "cat", "minutesWorked": 1200, "points": 2}, {"id": "dev", "minutesWorked": 600, "points": 1}], "hours"], "expect": [{"id": "ana", "weight": 2400, "share": {"minor": 0, "currency": "GBP"}}, {"id": "ben", "weight": 1800, "share": {"minor": 0, "currency": "GBP"}}, {"id": "cat", "weight": 1200, "share": {"minor": 0, "currency": "GBP"}}, {"id": "dev", "weight": 600, "share": {"minor": 0, "currency": "GBP"}}]},
  {"name": "an empty pool with nobody weighted is still nothing", "args": [{"minor": 0, "currency": "GBP"}, [{"id": "a", "minutesWorked": 0, "points": 0}], "hours"], "expect": [{"id": "a", "weight": 0, "share": {"minor": 0, "currency": "GBP"}}]},
  {"name": "one person takes the whole pool", "args": [{"minor": 12345, "currency": "EUR"}, [{"id": "solo", "minutesWorked": 300, "points": 1}], "points"], "expect": [{"id": "solo", "weight": 1, "share": {"minor": 12345, "currency": "EUR"}}]},
  {"name": "no staff is an error", "args": [{"minor": 100, "currency": "GBP"}, [], "hours"], "expectError": "staff must have at least one member"},
  {"name": "a negative pool is an error", "args": [{"minor": -100, "currency": "GBP"}, [{"id": "ana", "minutesWorked": 2400, "points": 3}, {"id": "ben", "minutesWorked": 1800, "points": 2}, {"id": "cat", "minutesWorked": 1200, "points": 2}, {"id": "dev", "minutesWorked": 600, "points": 1}], "hours"], "expectError": "pool must not be negative"},
  {"name": "a duplicate id is an error", "args": [{"minor": 100, "currency": "GBP"}, [{"id": "a", "minutesWorked": 60, "points": 1}, {"id": "a", "minutesWorked": 60, "points": 1}], "hours"], "expectError": "staff id \"a\" appears twice"},
  {"name": "negative minutes are an error", "args": [{"minor": 100, "currency": "GBP"}, [{"id": "a", "minutesWorked": -60, "points": 1}], "hours"], "expectError": "minutesWorked must not be negative"},
  {"name": "negative points are an error", "args": [{"minor": 100, "currency": "GBP"}, [{"id": "a", "minutesWorked": 60, "points": -1}], "points"], "expectError": "points must not be negative"},
  {"name": "a pool with nobody to share it by is an error", "args": [{"minor": 100, "currency": "GBP"}, [{"id": "a", "minutesWorked": 60, "points": 0}, {"id": "b", "minutesWorked": 60, "points": 0}], "points"], "expectError": "nobody in the pool has any weight to share it by"},
  {"name": "an unknown method is an error", "args": [{"minor": 100, "currency": "GBP"}, [{"id": "ana", "minutesWorked": 2400, "points": 3}, {"id": "ben", "minutesWorked": 1800, "points": 2}, {"id": "cat", "minutesWorked": 1200, "points": 2}, {"id": "dev", "minutesWorked": 600, "points": 1}], "seniority"], "expectError": "unknown tronc method \"seniority\""},
  {"name": "an empty id is an error", "args": [{"minor": 100, "currency": "GBP"}, [{"id": "", "minutesWorked": 60, "points": 1}], "hours"], "expectError": "every member needs an id"}
]