示例#1
0
 def test_popcount(self):
     self.assertEqual(bit_utils.popcount(1), 1)
     self.assertEqual(bit_utils.popcount(2), 1)
     self.assertEqual(bit_utils.popcount(3), 2)
     self.assertEqual(bit_utils.popcount(2 ** 16), 1)
     self.assertEqual(bit_utils.popcount(2**16 - 1), 16)
     self.assertEqual(bit_utils.popcount(2 ** 32), 1)
     self.assertEqual(bit_utils.popcount(2 ** 32 - 1), 32)
示例#2
0
 def test_popcount(self):
     nose.tools.assert_equal(bit_utils.popcount(1), 1)
     nose.tools.assert_equal(bit_utils.popcount(2), 1)
     nose.tools.assert_equal(bit_utils.popcount(3), 2)
     nose.tools.assert_equal(bit_utils.popcount(2 ** 16), 1)
     nose.tools.assert_equal(bit_utils.popcount(2**16 - 1), 16)
     nose.tools.assert_equal(bit_utils.popcount(2 ** 32), 1)
     nose.tools.assert_equal(bit_utils.popcount(2 ** 32 - 1), 32)
示例#3
0
    def test_popcount_limits(self):
        # Make sure documented integer limit is truthful.
        c = 10000
        for _ in range(c):
            # noinspection PyUnresolvedReferences
            v = random.randint(0, bit_utils.popcount.v_max)
            # Known method to always work based on counting python's binary
            # string representation.
            v_bin_count = bin(v).count('1')
            # Test method
            v_pop_count = bit_utils.popcount(v)

            self.assertEqual(v_pop_count, v_bin_count,
                             'popcount failed for integer %d' % v)
示例#4
0
 def test_popcount_0(self):
     self.assertEqual(bit_utils.popcount(0), 0)
示例#5
0
 def test_popcount_0(self):
     nose.tools.assert_equal(bit_utils.popcount(0), 0)