Functional Weave
Code in Python

monitor.counter-increase@1.0.0

vectors.json

3,174 bytes · view raw

[
  {"name": "a steadily growing counter: 150 more over 120 seconds is 1.25 a second", "args": [[{"at": 0, "value": 100}, {"at": 60, "value": 160}, {"at": 120, "value": 250}]], "expect": {"increase": 150, "resets": 0, "ratePerSecondMilli": 1250, "firstAt": 0, "lastAt": 120}},
  {"name": "a drop is a restart from zero: 60 + 20 + 30, where last minus first says -50", "args": [[{"at": 0, "value": 100}, {"at": 60, "value": 160}, {"at": 120, "value": 20}, {"at": 180, "value": 50}]], "expect": {"increase": 110, "resets": 1, "ratePerSecondMilli": 611, "firstAt": 0, "lastAt": 180}},
  {"name": "a restart read at exactly zero adds nothing but still counts as a reset", "args": [[{"at": 0, "value": 500}, {"at": 10, "value": 0}, {"at": 20, "value": 5}]], "expect": {"increase": 5, "resets": 1, "ratePerSecondMilli": 250, "firstAt": 0, "lastAt": 20}},
  {"name": "two restarts in a row", "args": [[{"at": 0, "value": 10}, {"at": 10, "value": 3}, {"at": 20, "value": 1}, {"at": 30, "value": 4}]], "expect": {"increase": 7, "resets": 2, "ratePerSecondMilli": 233, "firstAt": 0, "lastAt": 30}},
  {"name": "an unchanged counter grew by nothing", "args": [[{"at": 0, "value": 7}, {"at": 30, "value": 7}]], "expect": {"increase": 0, "resets": 0, "ratePerSecondMilli": 0, "firstAt": 0, "lastAt": 30}},
  {"name": "no samples: nothing grew and there is no rate or span", "args": [[]], "expect": {"increase": 0, "resets": 0, "ratePerSecondMilli": null, "firstAt": null, "lastAt": null}},
  {"name": "one sample has no interval, so no rate", "args": [[{"at": 1000, "value": 42}]], "expect": {"increase": 0, "resets": 0, "ratePerSecondMilli": null, "firstAt": 1000, "lastAt": 1000}},
  {"name": "a rate of exactly half a milli rounds up", "args": [[{"at": 0, "value": 0}, {"at": 2000, "value": 1}]], "expect": {"increase": 1, "resets": 0, "ratePerSecondMilli": 1, "firstAt": 0, "lastAt": 2000}},
  {"name": "a rate just under half a milli rounds down", "args": [[{"at": 0, "value": 0}, {"at": 2001, "value": 1}]], "expect": {"increase": 1, "resets": 0, "ratePerSecondMilli": 0, "firstAt": 0, "lastAt": 2001}},
  {"name": "a byte counter in the trillions: increase x1000 passes 2^53 and still rounds exactly", "args": [[{"at": 0, "value": 5000000000000}, {"at": 3, "value": 15000000000000}]], "expect": {"increase": 10000000000000, "resets": 0, "ratePerSecondMilli": 3333333333333333, "firstAt": 0, "lastAt": 3}},
  {"name": "times before 1970 are fine", "args": [[{"at": -100, "value": 0}, {"at": -50, "value": 25}]], "expect": {"increase": 25, "resets": 0, "ratePerSecondMilli": 500, "firstAt": -100, "lastAt": -50}},
  {"name": "a negative counter value is an error", "args": [[{"at": 0, "value": 5}, {"at": 10, "value": -1}]], "expectError": "counter value must not be negative: -1 at 10"},
  {"name": "two samples at the same second are an error", "args": [[{"at": 10, "value": 1}, {"at": 10, "value": 2}]], "expectError": "samples must be in strictly ascending time order: 10 follows 10"},
  {"name": "samples out of order are an error", "args": [[{"at": 20, "value": 1}, {"at": 10, "value": 2}]], "expectError": "samples must be in strictly ascending time order: 10 follows 20"}
]