'Util.number.exact_log2'

def test_exact_log2(self):

    self.assertRaises(TypeError, number.exact_log2, '0')
    self.assertRaises(ValueError, number.exact_log2, (-1))
    self.assertRaises(ValueError, number.exact_log2, 0)
    self.assertEqual(0, number.exact_log2(1))
    self.assertEqual(1, number.exact_log2(2))
    self.assertRaises(ValueError, number.exact_log2, 3)
    self.assertEqual(2, number.exact_log2(4))
    self.assertRaises(ValueError, number.exact_log2, 5)
    self.assertRaises(ValueError, number.exact_log2, 6)
    self.assertRaises(ValueError, number.exact_log2, 7)
    e = 3
    n = 8
    while (e < 16):
        if (n == (2 ** e)):
            self.assertEqual(e, number.exact_log2(n), ('expected=2**%d,    n=%d' % (e, n)))
            e += 1
        else:
            self.assertRaises(ValueError, number.exact_log2, n)
        n += 1
    for e in range(16, (1 + 64), 2):
        self.assertRaises(ValueError, number.exact_log2, ((2L ** e) - 1))
        self.assertEqual(e, number.exact_log2((2L ** e)))
        self.assertRaises(ValueError, number.exact_log2, ((2L ** e) + 1))
