def test_can_consume_tokenRefill(self): tb = TokenBucket(10, 1) self.assertFalse(tb.can_consume(50)) self.clock.set(40) self.assertFalse(tb.can_consume(50))
def test_can_consume_enoughTokens(self): tb = TokenBucket(10, 1) self.assertTrue(tb.can_consume(5))
def test_can_consume_notEnoughTokens(self): tb = TokenBucket(10, 1) self.assertFalse(tb.can_consume(50))
def test_consume_verifyTokenDecrease(self): tb = TokenBucket(10, 1) self.assertTrue(tb.consume(10)) self.assertEquals(0, tb.tokens)
def test_consume_notEnoughTokens(self): tb = TokenBucket(10, 1) self.assertFalse(tb.consume(100)) self.assertEquals(10, tb.tokens)