Example #1
0
def test_fucked_clock():
  # clock going backwards loses data but doesn't except or anything.
  clock = TestClock()
  bw = Bandwidth(clock=clock)
  bw.add(100)
  assert bw.bandwidth == 1. * 100 / 60
  clock.advance(-1)
  assert bw.bandwidth == 1. * 100 / 60
  clock.advance(60)
  assert bw.bandwidth == 1. * 100 / 60
  clock.advance(1)
  assert bw.bandwidth == 0
  clock.advance(-2)
  assert bw.bandwidth == 0
Example #2
0
def test_add():
  Bandwidth().add(23)
  clock = TestClock(0)
  bw = Bandwidth(window=Amount(1, Time.MINUTES), denominator=Time.SECONDS, clock=clock)
  bw.add(60)
  assert bw.bandwidth == 1  # 60 units in one minute = 1 units per second
  clock.advance(30)
  assert bw.bandwidth == 1
  clock.advance(30)
  assert bw.bandwidth == 0
  bw.add(60)
  assert bw.bandwidth == 1
  bw.add(60)
  assert bw.bandwidth == 2