def test_which_pools(self): """FortunaAccumulator.which_pools""" # which_pools(0) should trigger an assertion failure (unless using -O or -OO) if not assert_disabled(): self.assertRaises(AssertionError, FortunaAccumulator.which_pools, 0) self.assertEqual(FortunaAccumulator.which_pools(1), [0]) self.assertEqual(FortunaAccumulator.which_pools(2), [0, 1]) self.assertEqual(FortunaAccumulator.which_pools(3), [0]) self.assertEqual(FortunaAccumulator.which_pools(4), [0, 1, 2]) self.assertEqual(FortunaAccumulator.which_pools(5), [0]) self.assertEqual(FortunaAccumulator.which_pools(6), [0, 1]) self.assertEqual(FortunaAccumulator.which_pools(7), [0]) self.assertEqual(FortunaAccumulator.which_pools(8), [0, 1, 2, 3]) for i in range(1, 32): self.assertEqual(FortunaAccumulator.which_pools(2L**i - 1), [0]) self.assertEqual(FortunaAccumulator.which_pools(2L**i), range(i + 1)) self.assertEqual(FortunaAccumulator.which_pools(2L**i + 1), [0]) self.assertEqual(FortunaAccumulator.which_pools(2L**31), range(32)) self.assertEqual(FortunaAccumulator.which_pools(2L**32), range(32)) self.assertEqual(FortunaAccumulator.which_pools(2L**33), range(32)) self.assertEqual(FortunaAccumulator.which_pools(2L**34), range(32)) self.assertEqual(FortunaAccumulator.which_pools(2L**35), range(32)) self.assertEqual(FortunaAccumulator.which_pools(2L**36), range(32)) self.assertEqual(FortunaAccumulator.which_pools(2L**64), range(32)) self.assertEqual(FortunaAccumulator.which_pools(2L**128), range(32))
def test_which_pools(self): """FortunaAccumulator.which_pools""" # which_pools(0) should trigger an assertion failure (unless using -O or -OO) if not assert_disabled(): self.assertRaises(AssertionError, FortunaAccumulator.which_pools, 0) self.assertEqual(FortunaAccumulator.which_pools(1), [0]) self.assertEqual(FortunaAccumulator.which_pools(2), [0, 1]) self.assertEqual(FortunaAccumulator.which_pools(3), [0]) self.assertEqual(FortunaAccumulator.which_pools(4), [0, 1, 2]) self.assertEqual(FortunaAccumulator.which_pools(5), [0]) self.assertEqual(FortunaAccumulator.which_pools(6), [0, 1]) self.assertEqual(FortunaAccumulator.which_pools(7), [0]) self.assertEqual(FortunaAccumulator.which_pools(8), [0, 1, 2, 3]) for i in range(1, 32): self.assertEqual(FortunaAccumulator.which_pools(2L**i-1), [0]) self.assertEqual(FortunaAccumulator.which_pools(2L**i), range(i+1)) self.assertEqual(FortunaAccumulator.which_pools(2L**i+1), [0]) self.assertEqual(FortunaAccumulator.which_pools(2L**31), range(32)) self.assertEqual(FortunaAccumulator.which_pools(2L**32), range(32)) self.assertEqual(FortunaAccumulator.which_pools(2L**33), range(32)) self.assertEqual(FortunaAccumulator.which_pools(2L**34), range(32)) self.assertEqual(FortunaAccumulator.which_pools(2L**35), range(32)) self.assertEqual(FortunaAccumulator.which_pools(2L**36), range(32)) self.assertEqual(FortunaAccumulator.which_pools(2L**64), range(32)) self.assertEqual(FortunaAccumulator.which_pools(2L**128), range(32))
def test_ceil_shift(self): """Util.number.ceil_shift""" if not assert_disabled(): self.assertRaises(AssertionError, number.ceil_shift, -1, 1) self.assertRaises(AssertionError, number.ceil_shift, 1, -1) # b = 0 self.assertEqual(0, number.ceil_shift(0, 0)) self.assertEqual(1, number.ceil_shift(1, 0)) self.assertEqual(2, number.ceil_shift(2, 0)) self.assertEqual(3, number.ceil_shift(3, 0)) # b = 1 self.assertEqual(0, number.ceil_shift(0, 1)) self.assertEqual(1, number.ceil_shift(1, 1)) self.assertEqual(1, number.ceil_shift(2, 1)) self.assertEqual(2, number.ceil_shift(3, 1)) # b = 2 self.assertEqual(0, number.ceil_shift(0, 2)) self.assertEqual(1, number.ceil_shift(1, 2)) self.assertEqual(1, number.ceil_shift(2, 2)) self.assertEqual(1, number.ceil_shift(3, 2)) self.assertEqual(1, number.ceil_shift(4, 2)) self.assertEqual(2, number.ceil_shift(5, 2)) self.assertEqual(2, number.ceil_shift(6, 2)) self.assertEqual(2, number.ceil_shift(7, 2)) self.assertEqual(2, number.ceil_shift(8, 2)) self.assertEqual(3, number.ceil_shift(9, 2)) for b in range(3, 1 + 129, 3): # 3, 6, ... , 129 self.assertEqual(0, number.ceil_shift(0, b)) n = 1L while n <= 2L**(b + 2): (q, r) = divmod(n - 1, 2L**b) expected = q + int(not not r) self.assertEqual((n - 1, b, expected), (n - 1, b, number.ceil_shift(n - 1, b))) (q, r) = divmod(n, 2L**b) expected = q + int(not not r) self.assertEqual((n, b, expected), (n, b, number.ceil_shift(n, b))) (q, r) = divmod(n + 1, 2L**b) expected = q + int(not not r) self.assertEqual((n + 1, b, expected), (n + 1, b, number.ceil_shift(n + 1, b))) n *= 2
def test_ceil_shift(self): """Util.number.ceil_shift""" if not assert_disabled(): self.assertRaises(AssertionError, number.ceil_shift, -1, 1) self.assertRaises(AssertionError, number.ceil_shift, 1, -1) # b = 0 self.assertEqual(0, number.ceil_shift(0, 0)) self.assertEqual(1, number.ceil_shift(1, 0)) self.assertEqual(2, number.ceil_shift(2, 0)) self.assertEqual(3, number.ceil_shift(3, 0)) # b = 1 self.assertEqual(0, number.ceil_shift(0, 1)) self.assertEqual(1, number.ceil_shift(1, 1)) self.assertEqual(1, number.ceil_shift(2, 1)) self.assertEqual(2, number.ceil_shift(3, 1)) # b = 2 self.assertEqual(0, number.ceil_shift(0, 2)) self.assertEqual(1, number.ceil_shift(1, 2)) self.assertEqual(1, number.ceil_shift(2, 2)) self.assertEqual(1, number.ceil_shift(3, 2)) self.assertEqual(1, number.ceil_shift(4, 2)) self.assertEqual(2, number.ceil_shift(5, 2)) self.assertEqual(2, number.ceil_shift(6, 2)) self.assertEqual(2, number.ceil_shift(7, 2)) self.assertEqual(2, number.ceil_shift(8, 2)) self.assertEqual(3, number.ceil_shift(9, 2)) for b in range(3, 1+129, 3): # 3, 6, ... , 129 self.assertEqual(0, number.ceil_shift(0, b)) n = 1L while n <= 2L**(b+2): (q, r) = divmod(n-1, 2L**b) expected = q + int(not not r) self.assertEqual((n-1, b, expected), (n-1, b, number.ceil_shift(n-1, b))) (q, r) = divmod(n, 2L**b) expected = q + int(not not r) self.assertEqual((n, b, expected), (n, b, number.ceil_shift(n, b))) (q, r) = divmod(n+1, 2L**b) expected = q + int(not not r) self.assertEqual((n+1, b, expected), (n+1, b, number.ceil_shift(n+1, b))) n *= 2