Functional Weave
Code in Python

math.clamp@1.0.0

vectors.json

1,180 bytes · view raw

[
  { "name": "a value inside the range is returned unchanged", "args": [5, 0, 10], "expect": 5 },
  { "name": "below the range gives the lower bound", "args": [-3, 0, 10], "expect": 0 },
  { "name": "above the range gives the upper bound", "args": [42, 0, 10], "expect": 10 },
  { "name": "exactly the lower bound is inside", "args": [0, 0, 10], "expect": 0 },
  { "name": "exactly the upper bound is inside", "args": [10, 0, 10], "expect": 10 },
  { "name": "a single-point range pins every value", "args": [99, 7, 7], "expect": 7 },
  { "name": "a wholly negative range", "args": [-50, -20, -10], "expect": -20 },
  { "name": "a range across zero", "args": [3, -5, 5], "expect": 3 },
  { "name": "a discount capped at 100 percent in basis points", "args": [12500, 0, 10000], "expect": 10000 },
  { "name": "the largest safe integers", "args": [9007199254740991, -9007199254740991, 9007199254740990], "expect": 9007199254740990 },
  { "name": "swapped bounds are an error, not always the lower bound", "args": [5, 10, 0], "expectError": "min must not be greater than max" },
  { "name": "a fractional value is an error", "args": [2.5, 0, 10], "expectError": "integers only" }
]