Functional Weave
Code in Python

retail.price-rounding@1.0.0

vectors.json

3,935 bytes · view raw

[
  {"name": "charm .99 up from 1.87", "args": [{"minor": 187, "currency": "GBP"}, 100, 1, "up"], "expect": {"minor": 199, "currency": "GBP"}},
  {"name": "charm .99 down from 1.87", "args": [{"minor": 187, "currency": "GBP"}, 100, 1, "down"], "expect": {"minor": 99, "currency": "GBP"}},
  {"name": "charm .99 nearest from 1.87", "args": [{"minor": 187, "currency": "GBP"}, 100, 1, "nearest"], "expect": {"minor": 199, "currency": "GBP"}},
  {"name": "a price already on a point is unchanged, up", "args": [{"minor": 199, "currency": "GBP"}, 100, 1, "up"], "expect": {"minor": 199, "currency": "GBP"}},
  {"name": "a price already on a point is unchanged, down", "args": [{"minor": 199, "currency": "GBP"}, 100, 1, "down"], "expect": {"minor": 199, "currency": "GBP"}},
  {"name": "2.00 is just past 1.99, so up goes to 2.99, not 2.00 or 1.99", "args": [{"minor": 200, "currency": "GBP"}, 100, 1, "up"], "expect": {"minor": 299, "currency": "GBP"}},
  {"name": "2.00 nearest is 1.99", "args": [{"minor": 200, "currency": "GBP"}, 100, 1, "nearest"], "expect": {"minor": 199, "currency": "GBP"}},
  {"name": "charm .95 nearest from 4.20 goes down to 3.95", "args": [{"minor": 420, "currency": "GBP"}, 100, 5, "nearest"], "expect": {"minor": 395, "currency": "GBP"}},
  {"name": "nearest 5p rounds 1.23 up to 1.25", "args": [{"minor": 123, "currency": "GBP"}, 5, 0, "nearest"], "expect": {"minor": 125, "currency": "GBP"}},
  {"name": "nearest 5p rounds 1.22 down to 1.20", "args": [{"minor": 122, "currency": "GBP"}, 5, 0, "nearest"], "expect": {"minor": 120, "currency": "GBP"}},
  {"name": "nearest 10p: an exact half goes to the higher price", "args": [{"minor": 125, "currency": "GBP"}, 10, 0, "nearest"], "expect": {"minor": 130, "currency": "GBP"}},
  {"name": "down to 10p", "args": [{"minor": 129, "currency": "GBP"}, 10, 0, "down"], "expect": {"minor": 120, "currency": "GBP"}},
  {"name": "up to 10p", "args": [{"minor": 121, "currency": "GBP"}, 10, 0, "up"], "expect": {"minor": 130, "currency": "GBP"}},
  {"name": "a tie between 1.99 and 2.99 goes to the higher price", "args": [{"minor": 249, "currency": "GBP"}, 100, 1, "nearest"], "expect": {"minor": 299, "currency": "GBP"}},
  {"name": "zero has no .99 point below it, so nearest is 0.99", "args": [{"minor": 0, "currency": "GBP"}, 100, 1, "nearest"], "expect": {"minor": 99, "currency": "GBP"}},
  {"name": "zero with plain rounding stays zero", "args": [{"minor": 0, "currency": "GBP"}, 10, 0, "down"], "expect": {"minor": 0, "currency": "GBP"}},
  {"name": "9.99 / 19.99 ladder, nearest from 14.50", "args": [{"minor": 1450, "currency": "GBP"}, 1000, 1, "nearest"], "expect": {"minor": 999, "currency": "GBP"}},
  {"name": "9.99 / 19.99 ladder, up from 12.00", "args": [{"minor": 1200, "currency": "GBP"}, 1000, 1, "up"], "expect": {"minor": 1999, "currency": "GBP"}},
  {"name": "yen points ending in 80, nearest", "args": [{"minor": 1234, "currency": "JPY"}, 100, 20, "nearest"], "expect": {"minor": 1280, "currency": "JPY"}},
  {"name": "step 1 leaves any price alone", "args": [{"minor": 1234, "currency": "GBP"}, 1, 0, "nearest"], "expect": {"minor": 1234, "currency": "GBP"}},
  {"name": "down below the first point is an error", "args": [{"minor": 50, "currency": "GBP"}, 100, 1, "down"], "expectError": "no price point at or below 50"},
  {"name": "a step of 0 is an error", "args": [{"minor": 100, "currency": "GBP"}, 0, 0, "up"], "expectError": "step must be 1 or more"},
  {"name": "an ending as large as the step is an error", "args": [{"minor": 100, "currency": "GBP"}, 100, 100, "up"], "expectError": "ending must be from 0 to step - 1"},
  {"name": "a negative price is an error", "args": [{"minor": -100, "currency": "GBP"}, 100, 1, "up"], "expectError": "price must not be negative"},
  {"name": "an unknown direction is an error", "args": [{"minor": 100, "currency": "GBP"}, 100, 1, "sideways"], "expectError": "unknown direction \"sideways\""}
]