def test_ints(self): for i in range(0x80): encoded = parity_encode(i) errors = parity_errors(encoded) self.assertFalse(errors, 'Encoded data has false errors.') decoded = parity_decode(encoded) self.assertEqual(decoded, i, 'Decoded data does not match original.') for b in range(8): oneerr = encoded ^ (1 << b) errors = parity_errors(oneerr) self.assertTrue(errors, 'Error not detected in encoded data.')
def test_ints(self): for i in range(0x80): encoded = parity_encode(i) errors = parity_errors(encoded) self.assertFalse(errors, 'Encoded data has false errors.') decoded = parity_decode(encoded) self.assertEqual(decoded, i, 'Decoded data does not match original.') for b in range(8): oneerr = encoded ^ (1 << b) errors = parity_errors(oneerr) self.assertTrue(errors, 'Error not detected in encoded data.')
def build(input, output, mode, bits): """Build pattern tables.""" from teletext.coding import parity_encode, hamming8_enc from teletext.vbi.pattern import build_pattern if mode == 'parity': pattern_set = set(parity_encode(range(0x80))) elif mode == 'hamming': pattern_set = set(hamming8_enc) else: pattern_set = range(256) chunks = FileChunker(input, 27) chunks = tqdm(chunks, unit='P', dynamic_ncols=True) build_pattern(chunks, output, *bits, pattern_set)
def _test_array(self, array: np.ndarray): encoded = parity_encode(array) self.assertEqual(encoded.dtype, np.int) self.assertEqual(array.shape, encoded.shape, 'Encoded data has wrong shape') #bitcounts = np.sum(np.unpackbits(encoded, axis=1), axis=1) #self.assertTrue(all(bitcounts & 1), 'Encoded data has wrong parity.') errors = parity_errors(encoded) self.assertFalse(any(errors), 'Encoded data has false errors.') decoded = parity_decode(encoded) self.assertEqual(decoded.dtype, np.int) self.assertTrue(all(decoded == array), 'Decoded data does not match original.') for b in range(8): oneerr = encoded ^ (1 << b) errors = parity_errors(oneerr) self.assertTrue(all(errors), 'Error not detected in encoded data.')
def _test_array(self, array: np.ndarray): encoded = parity_encode(array) self.assertEqual(encoded.dtype, np.int) self.assertEqual(array.shape, encoded.shape, 'Encoded data has wrong shape') #bitcounts = np.sum(np.unpackbits(encoded, axis=1), axis=1) #self.assertTrue(all(bitcounts & 1), 'Encoded data has wrong parity.') errors = parity_errors(encoded) self.assertFalse(any(errors), 'Encoded data has false errors.') decoded = parity_decode(encoded) self.assertEqual(decoded.dtype, np.int) self.assertTrue(all(decoded == array), 'Decoded data does not match original.') for b in range(8): oneerr = encoded ^ (1 << b) errors = parity_errors(oneerr) self.assertTrue(all(errors), 'Error not detected in encoded data.')
def test_unit_list(self): data = [0] encoded = parity_encode(data) self.assertEqual(encoded.shape, (1, ), 'Encoded data has wrong shape')
def test_int_type(self): encoded = parity_encode(0)
def test_full_list(self): data = list(range(0x80)) encoded = parity_encode(data) self.assertEqual(encoded.shape, (len(data), ), 'Encoded data has wrong shape')
def test_unit_array_type(self): encoded = parity_encode(np.array([0], dtype=np.uint8)) self.assertIsInstance(encoded, np.ndarray)
def test_unit_list_type(self): encoded = parity_encode([0]) self.assertIsInstance(encoded, np.ndarray)
def test_array_type(self): encoded = parity_encode(np.array(range(0x80), dtype=np.uint8)) self.assertIsInstance(encoded, np.ndarray)
def test_list_type(self): encoded = parity_encode(list(range(0x80))) self.assertIsInstance(encoded, np.ndarray)
def test_array_type(self): encoded = parity_encode(np.array(range(0x80), dtype=np.uint8)) self.assertIsInstance(encoded, np.ndarray)
def test_list_type(self): encoded = parity_encode(list(range(0x80))) self.assertIsInstance(encoded, np.ndarray)
def test_unit_array_type(self): encoded = parity_encode(np.array([0], dtype=np.uint8)) self.assertIsInstance(encoded, np.ndarray)
def test_unit_list(self): data = [0] encoded = parity_encode(data) self.assertEqual(encoded.shape, (1, ), 'Encoded data has wrong shape')
def test_full_list(self): data = list(range(0x80)) encoded = parity_encode(data) self.assertEqual(encoded.shape, (len(data),), 'Encoded data has wrong shape')
def test_int_type(self): encoded = parity_encode(0)
def test_unit_list_type(self): encoded = parity_encode([0]) self.assertIsInstance(encoded, np.ndarray)