def test_compressor(self): s = json.dumps(schema) with open('test/compressed.bin', 'rb') as f: data = f.read() with open('test/uncompressed.bin','rb') as f: original = f.read() self.assertEqual(len(data), len_compressed, "compressed file length is correct") self.assertEqual(len(original), len_uncompressed, "uncompressed file length is correct") # last four bytes are the point count compressed_point_count = struct.unpack('<L',data[-4:])[0] uncompressed_point_count = struct.unpack('<L',original[-4:])[0] self.assertEqual(compressed_point_count, uncompressed_point_count, "compressed point count matches expected") self.assertEqual(uncompressed_point_count, expected_point_count, "uncompressed point count matches expected") dtype = buildNumpyDescription(json.loads(s)) uncompressed = np.frombuffer(original[0:-4], dtype = dtype) self.assertEqual(uncompressed.shape[0], expected_point_count) point_data = np.frombuffer(original[:-4], dtype = dtype) empty = np.zeros(uncompressed_point_count, dtype = np.uint8) c = Compressor(s) compressed = c.compress(point_data) original_compressed = np.frombuffer(data[0:-4], dtype = np.uint8) self.assertEqual(len(original_compressed), len_compressed - 4) for i in range(len(compressed)): self.assertEqual(compressed[i], original_compressed[i])
def test_full_loop(self): s = json.dumps(schema) with open('test/uncompressed.bin', 'rb') as f: original = f.read() dtype = buildNumpyDescription(json.loads(s)) uncompressed = np.frombuffer(original[0:-4], dtype=dtype) c = Compressor(s) compressed = c.compress(uncompressed) d = Decompressor(compressed, s) decompressed = d.decompress(expected_point_count) self.assertEqual(len(decompressed), len(uncompressed)) for i in range(len(decompressed)): self.assertEqual(decompressed[i], uncompressed[i]) # confirm we can build from dtypes instead of json descriptions _ = Compressor(dtype) _ = Decompressor(compressed, dtype)
def test_compressor(self): s = json.dumps(schema) with open('test/compressed.bin', 'rb') as f: data = f.read() with open('test/uncompressed.bin', 'rb') as f: original = f.read() self.assertEqual(len(data), len_compressed, "compressed file length is correct") self.assertEqual(len(original), len_uncompressed, "uncompressed file length is correct") # last four bytes are the point count compressed_point_count = struct.unpack('<L', data[-4:])[0] uncompressed_point_count = struct.unpack('<L', original[-4:])[0] self.assertEqual(compressed_point_count, uncompressed_point_count, "compressed point count matches expected") self.assertEqual(uncompressed_point_count, expected_point_count, "uncompressed point count matches expected") dtype = buildNumpyDescription(json.loads(s)) uncompressed = np.frombuffer(original[0:-4], dtype=dtype) self.assertEqual(uncompressed.shape[0], expected_point_count) point_data = np.frombuffer(original[:-4], dtype=dtype) empty = np.zeros(uncompressed_point_count, dtype=np.uint8) c = Compressor(s) compressed = c.compress(point_data) original_compressed = np.frombuffer(data[0:-4], dtype=np.uint8) self.assertEqual(len(original_compressed), len_compressed - 4) for i in range(len(compressed)): self.assertEqual(compressed[i], original_compressed[i])