Functional Weave
Code in TypeScript

monitor.series-window@1.0.0

vectors.json

2,082 bytes · view raw

[
  {"name": "keeps the samples inside the window", "args": [[{"at": 100, "value": 1}, {"at": 160, "value": 2}, {"at": 220, "value": 3}, {"at": 280, "value": 4}], 150, 250], "expect": [{"at": 160, "value": 2}, {"at": 220, "value": 3}]},
  {"name": "a sample exactly at from is included", "args": [[{"at": 100, "value": 1}, {"at": 160, "value": 2}], 100, 200], "expect": [{"at": 100, "value": 1}, {"at": 160, "value": 2}]},
  {"name": "a sample exactly at to is excluded, so back-to-back windows never share one", "args": [[{"at": 100, "value": 1}, {"at": 200, "value": 2}], 100, 200], "expect": [{"at": 100, "value": 1}]},
  {"name": "an empty window when from equals to", "args": [[{"at": 100, "value": 1}], 100, 100], "expect": []},
  {"name": "an empty series is an empty window", "args": [[], 0, 1000], "expect": []},
  {"name": "a window before every sample is empty", "args": [[{"at": 500, "value": 7}], 0, 500], "expect": []},
  {"name": "negative values and times before 1970 are kept as they are", "args": [[{"at": -60, "value": -5}, {"at": 0, "value": 0}, {"at": 60, "value": 5}], -60, 1], "expect": [{"at": -60, "value": -5}, {"at": 0, "value": 0}]},
  {"name": "a window covering everything returns every sample", "args": [[{"at": 1, "value": 10}, {"at": 2, "value": 20}, {"at": 3, "value": 30}], 0, 4], "expect": [{"at": 1, "value": 10}, {"at": 2, "value": 20}, {"at": 3, "value": 30}]},
  {"name": "from after to is an error", "args": [[], 200, 100], "expectError": "from must not be after to: 200 > 100"},
  {"name": "two samples at the same second are an error", "args": [[{"at": 100, "value": 1}, {"at": 100, "value": 2}], 0, 1000], "expectError": "samples must be in strictly ascending time order: 100 follows 100"},
  {"name": "misordered samples outside the window are still an error", "args": [[{"at": 300, "value": 1}, {"at": 100, "value": 2}], 0, 50], "expectError": "samples must be in strictly ascending time order: 100 follows 300"},
  {"name": "a fractional bound is an error", "args": [[], 0.5, 10], "expectError": "from and to must be whole seconds"}
]