def test_encode_package_padding_byte(self): package_type = 0x00 package_byte = 0x00 padding = 7 for padding_byte in range(0x00, 0xff): for length in range(1, 8): package = [package_byte] * length packets = CMS50Dplus.encode_package(package_type, package, padding, padding_byte) self.assertEqual( packets[2:], [CMS50Dplus.set_bit(package_byte)] * length + [CMS50Dplus.set_bit(padding_byte)] * (padding - length))
def test_set_bit(self): # 0 to 1 for position in range(0, 8): result = CMS50Dplus.set_bit(0x00, 1, position) self.assertTrue(result & 0x01 << position) # 1 to 1 for position in range(0, 8): result = CMS50Dplus.set_bit(0xff, 1, position) self.assertTrue(result & 0x01 << position) # 0 to 0 for position in range(0, 8): result = CMS50Dplus.set_bit(0x00, 0, position) self.assertFalse(result & 0x01 << position) # 1 to 0 for position in range(0, 8): result = CMS50Dplus.set_bit(0xff, 0, position) self.assertFalse(result & 0x01 << position)