'L{task.LoopingCall.withCount} should never invoke its callable with a
zero.  Specifically, if a L{task.LoopingCall} created with C{withCount}
has its L{start <task.LoopingCall.start>} method invoked with a
floating-point number which introduces decimal inaccuracy when
multiplied or divided, such as "0.1", L{task.LoopingCall} will never
invoke its callable with 0.  Also, the sum of all the values passed to
its callable as the "count" will be an integer, the number of intervals
that have elapsed.
This is a regression test for a particularly tricky case to implement.'

def test_withCountFloatingPointBoundary(self):

    clock = task.Clock()
    accumulator = []
    call = task.LoopingCall.withCount(accumulator.append)
    call.clock = clock
    count = 10
    timespan = 1.0
    interval = (timespan / count)
    call.start(interval, now=False)
    for x in range(count):
        clock.advance(interval)
    epsilon = (timespan - sum(([interval] * count)))
    clock.advance(epsilon)
    secondsValue = clock.seconds()
    self.assertTrue((abs(epsilon) > 0.0), '{0}    should    be    greater    than    zero'.format(epsilon))
    self.assertTrue((secondsValue >= timespan), '{0}    should    be    greater    than    or    equal    to    {1}'.format(secondsValue, timespan))
    self.assertEqual(sum(accumulator), count)
    self.assertNotIn(0, accumulator)
