import bukkit
import time


def test_creation():
    ticks = 42
    fake_clock = lambda: ticks

    bucket = bukkit.TokenBucket(rate=23, limit=9000, clock=fake_clock)
    assert bucket.clock is fake_clock
    assert bucket.ts == ticks
    assert bucket.rate == 23
    assert bucket.limit == 9000
    assert bucket._available == bucket.limit


def test_consumption():
    ticks = 0
    fake_clock = lambda: ticks

    bucket = bukkit.TokenBucket(5, 20, clock=fake_clock)
    assert bucket.tokens == 20
    assert bucket.consume(10)
    assert not bucket.consume(15)
    assert bucket.tokens == 10
    
    ticks += 1
    assert bucket.tokens == 15
    ticks += 2
    assert bucket.tokens == 20

    assert bucket.consume(1)
    assert bucket.tokens == 19
    ticks += 1
    assert bucket.tokens == 20

@@ -773,28 +773,513 @@
  assert bucket.tokens == 20%0A
+%0A%0Adef test_comparison():%0A    ticks = 0%0A    fake_clock = lambda: ticks%0A%0A    b1 = bukkit.TokenBucket(5, 20, clock=fake_clock)%0A    b2 = bukkit.TokenBucket(5, 20, clock=fake_clock)%0A%0A    # These comparisons check when the buckets were last *used*, not the number%0A    # of tokens each contains.%0A    assert b1 == b2%0A    ticks += 1%0A    b1.consume(1)%0A    assert b2 %3C b1%0A    ticks += 1%0A    b2.consume(1)%0A    assert b1 %3C b2%0A    ticks += 1%0A    b1.consume(1)%0A    b2.consume(1)%0A    assert b1 == b2%0A%0A

Test temporal comparison.