Functional Weave
Code in TypeScript

time.round-to-increment@1.0.0

vectors.json

2,063 bytes · view raw

[
  { "name": "7 minutes in six-minute units, rounding up, bills two units", "args": [7, 6, "up"], "expect": 12 },
  { "name": "7 minutes in six-minute units, rounding down, bills one", "args": [7, 6, "down"], "expect": 6 },
  { "name": "7 minutes to the nearest six is 6", "args": [7, 6, "half-up"], "expect": 6 },
  { "name": "9 minutes is exactly half way between 6 and 12: half-up goes to 12", "args": [9, 6, "half-up"], "expect": 12 },
  { "name": "15 minutes is half way between 12 and 18: half-up goes to 18", "args": [15, 6, "half-up"], "expect": 18 },
  { "name": "15 minutes, half-even goes to the even unit count, 2 units = 12", "args": [15, 6, "half-even"], "expect": 12 },
  { "name": "3 minutes, half-even rounds the half unit to zero units", "args": [3, 6, "half-even"], "expect": 0 },
  { "name": "an exact multiple is unchanged when rounding up", "args": [12, 6, "up"], "expect": 12 },
  { "name": "one minute in quarter hours, rounding up, is a quarter hour", "args": [1, 15, "up"], "expect": 15 },
  { "name": "22 minutes to the nearest quarter hour is 15", "args": [22, 15, "half-up"], "expect": 15 },
  { "name": "23 minutes to the nearest quarter hour is 30", "args": [23, 15, "half-up"], "expect": 30 },
  { "name": "52 minutes rounding down in quarter hours is 45", "args": [52, 15, "down"], "expect": 45 },
  { "name": "zero stays zero even rounding up: a minimum charge is not rounding", "args": [0, 15, "up"], "expect": 0 },
  { "name": "an increment of one minute changes nothing", "args": [37, 1, "up"], "expect": 37 },
  { "name": "a long day in six-minute units", "args": [487, 6, "up"], "expect": 492 },
  { "name": "negative minutes are an error", "args": [-5, 6, "up"], "expectError": "minutes must be a non-negative integer" },
  { "name": "an increment of zero is an error", "args": [7, 0, "up"], "expectError": "increment must be a positive integer" },
  { "name": "\"nearest\" is spelled half-up or half-even, so an unknown mode is an error", "args": [7, 6, "nearest"], "expectError": "unknown rounding mode \"nearest\"" }
]