Example #1
0
    def test_byte_size_correctness(self):
        numbers = [-12, 12, 1200, 120091, 123456789]
        for num in numbers:
            if num < 0:
                bit_length = len(bin(num, None)) - 1
            else:
                bit_length = len(bin(num, None))
            count = int(math.ceil(bit_length / 8.0))
            self.assertEqual(builtins.integer_byte_size(num), count, "Boom. for number %d, expected %d" % (num, count))

        self.assertEqual(builtins.integer_byte_size(1 << 1023), 128)
        self.assertEqual(builtins.integer_byte_size((1 << 1024) - 1), 128)
        self.assertEqual(builtins.integer_byte_size(1 << 1024), 129)
Example #2
0
 def test_values(self):
   self.assertEqual(builtins.integer_byte_size(255), 1)
   self.assertEqual(builtins.integer_byte_size(256), 2)
   self.assertEqual(builtins.integer_byte_size(0xffff), 2)
   self.assertEqual(builtins.integer_byte_size(0xffffff), 3)
   self.assertEqual(builtins.integer_byte_size(0xffffffff), 4)
   self.assertEqual(builtins.integer_byte_size(0xffffffffff), 5)
   self.assertEqual(builtins.integer_byte_size(0xffffffffffff), 6)
   self.assertEqual(builtins.integer_byte_size(0xffffffffffffff), 7)
   self.assertEqual(builtins.integer_byte_size(0xffffffffffffffff), 8)
Example #3
0
 def test_values(self):
   self.assertEqual(integer_byte_size(255), 1)
   self.assertEqual(integer_byte_size(256), 2)
   self.assertEqual(integer_byte_size(0xffff), 2)
   self.assertEqual(integer_byte_size(0xffffff), 3)
   self.assertEqual(integer_byte_size(0xffffffff), 4)
   self.assertEqual(integer_byte_size(0xffffffffff), 5)
   self.assertEqual(integer_byte_size(0xffffffffffff), 6)
   self.assertEqual(integer_byte_size(0xffffffffffffff), 7)
   self.assertEqual(integer_byte_size(0xffffffffffffffff), 8)
Example #4
0
 def test_values(self):
     self.assertEqual(builtins.integer_byte_size(255), 1)
     self.assertEqual(builtins.integer_byte_size(256), 2)
     self.assertEqual(builtins.integer_byte_size(0xFFFF), 2)
     self.assertEqual(builtins.integer_byte_size(0xFFFFFF), 3)
     self.assertEqual(builtins.integer_byte_size(0xFFFFFFFF), 4)
     self.assertEqual(builtins.integer_byte_size(0xFFFFFFFFFF), 5)
     self.assertEqual(builtins.integer_byte_size(0xFFFFFFFFFFFF), 6)
     self.assertEqual(builtins.integer_byte_size(0xFFFFFFFFFFFFFF), 7)
     self.assertEqual(builtins.integer_byte_size(0xFFFFFFFFFFFFFFFF), 8)
Example #5
0
  def test_byte_size_correctness(self):
    numbers = [-12, 12, 1200, 120091, 123456789]
    for num in numbers:
      if num < 0:
        bit_length = len(bin(num, None)) - 1
      else:
        bit_length = len(bin(num, None))
      count = int(math.ceil(bit_length / 8.0))
      self.assertEqual(builtins.integer_byte_size(num), count,
                       "Boom. for number %d, expected %d" % (num, count))

    self.assertEqual(builtins.integer_byte_size(1 << 1023), 128)
    self.assertEqual(builtins.integer_byte_size((1 << 1024) - 1), 128)
    self.assertEqual(builtins.integer_byte_size(1 << 1024), 129)
Example #6
0
 def test_1_if_zero(self):
   self.assertEqual(builtins.integer_byte_size(0), 1)
Example #7
0
 def test_1_if_zero(self):
   self.assertEqual(integer_byte_size(0), 1)