# Path: pym2149/timer.py
# class SimpleTimer(Timer):
# 
#     def __init__(self, clock):
#         self.carryticks = 0
#         self.clock = clock
# 
#     def blocksforperiod(self, refreshrate):
#         available = self.carryticks + self.clock
#         blockticks = int(round(available / refreshrate))
#         self.carryticks = available - blockticks * refreshrate
#         yield Block(blockticks)
# 
#     def __del__(self):
#         if self.carryticks:
#             log.warning("Non-zero carry on dispose: %s", self.carryticks)
# 
# class MinBlockRateTimer(SimpleTimer):
# 
#     def __init__(self, clock, minblockrate):
#         # If division not exact, rate will slightly exceed given minimum:
#         self.maxblocksize = int(clock // minblockrate)
#         if not self.maxblocksize:
#             raise Exception(clock, minblockrate)
#         super().__init__(clock)
# 
#     def blocksforperiod(self, refreshrate):
#         wholeperiodblock, = super().blocksforperiod(refreshrate)
#         blockticks = wholeperiodblock.framecount
#         while blockticks:
#             size = min(blockticks, self.maxblocksize)
#             b = Block(size)
#             blockticks -= size
#             yield b


from .timer import SimpleTimer, MinBlockRateTimer
from unittest import TestCase
        self.assertEqual(0, t.carryticks)
        self.assertEqual(clock * 10, self.periodframecount(.1))
        self.assertEqual(0, t.carryticks)

    def test_fractionalrefreshrates(self):
        t = self.t = SimpleTimer(100)
        self.assertEqual(200, self.periodframecount(.5))
        self.assertEqual(0, t.carryticks)
        self.assertEqual(300, self.periodframecount(1 / 3))
        self.assertEqual(0, t.carryticks)
        self.assertEqual(67, self.periodframecount(1.5))
        self.assertEqual(-.5, t.carryticks)
        self.assertEqual(66, self.periodframecount(1.5))
        self.assertEqual(.5, t.carryticks)
        self.assertEqual(67, self.periodframecount(1.5))
        self.assertEqual(0, t.carryticks)

    def test_nonintegerclock(self):
        t = self.t = SimpleTimer(100.5)
        self.assertEqual(34, self.periodframecount(3))
        self.assertEqual(-1.5, t.carryticks)
        self.assertEqual(33, self.periodframecount(3))
        self.assertEqual(0, t.carryticks)
        self.assertEqual(34, self.periodframecount(3))
        self.assertEqual(-1.5, t.carryticks)
        t.carryticks = 0

class TestMinBlockRateTimer(TestCase):

    def test_minblockrate(self):

# Path: pym2149/timer.py
# class SimpleTimer(Timer):
# 
#     def __init__(self, clock):
#         self.carryticks = 0
#         self.clock = clock
# 
#     def blocksforperiod(self, refreshrate):
#         available = self.carryticks + self.clock
#         blockticks = int(round(available / refreshrate))
#         self.carryticks = available - blockticks * refreshrate
#         yield Block(blockticks)
# 
#     def __del__(self):
#         if self.carryticks:
#             log.warning("Non-zero carry on dispose: %s", self.carryticks)
# 
# class MinBlockRateTimer(SimpleTimer):
# 
#     def __init__(self, clock, minblockrate):
#         # If division not exact, rate will slightly exceed given minimum:
#         self.maxblocksize = int(clock // minblockrate)
#         if not self.maxblocksize:
#             raise Exception(clock, minblockrate)
#         super().__init__(clock)
# 
#     def blocksforperiod(self, refreshrate):
#         wholeperiodblock, = super().blocksforperiod(refreshrate)
#         blockticks = wholeperiodblock.framecount
#         while blockticks:
#             size = min(blockticks, self.maxblocksize)
#             b = Block(size)
#             blockticks -= size
#             yield b


# Path: pym2149/test_timer.py
from .timer import SimpleTimer, MinBlockRateTimer
from unittest import TestCase

        self.assertEqual(0, t.carryticks)
        self.assertEqual(clock * 10, self.periodframecount(.1))
        self.assertEqual(0, t.carryticks)

    def test_fractionalrefreshrates(self):
        t = self.t = SimpleTimer(100)
        self.assertEqual(200, self.periodframecount(.5))
        self.assertEqual(0, t.carryticks)
        self.assertEqual(300, self.periodframecount(1 / 3))
        self.assertEqual(0, t.carryticks)
        self.assertEqual(67, self.periodframecount(1.5))
        self.assertEqual(-.5, t.carryticks)
        self.assertEqual(66, self.periodframecount(1.5))
        self.assertEqual(.5, t.carryticks)
        self.assertEqual(67, self.periodframecount(1.5))
        self.assertEqual(0, t.carryticks)

    def test_nonintegerclock(self):
        t = self.t = SimpleTimer(100.5)
        self.assertEqual(34, self.periodframecount(3))
        self.assertEqual(-1.5, t.carryticks)
        self.assertEqual(33, self.periodframecount(3))
        self.assertEqual(0, t.carryticks)
        self.assertEqual(34, self.periodframecount(3))
        self.assertEqual(-1.5, t.carryticks)
        t.carryticks = 0

class TestMinBlockRateTimer(TestCase):

    def test_minblockrate(self):

        t = MinBlockRateTimer(1000, 2)