def test_vle_decode(self): for v in self.VLE_TESTS: rvl.Clear() rvl.encoded = bytearray(v[1]) got = rvl.DecodeVLE() self.assertEqual("%x" % v[0], "%x" % got, "decode VLE for test %d" % v[0])
def test_rvl_decompress(self): for v in self.RVL_TESTS: rvl.Clear() rvl.encoded = bytearray(v[1]) got = rvl.DecompressRVL(len(v[0])) self.assertEqual(len(rvl.plain), len(v[0]), "RVL compress length for test") for i in range(len(v[0])): self.assertEqual( rvl.plain[i], v[0][i], "RVL compression at index %d for test %s" % (i, v[0]))
def test_rvl_compress(self): for v in self.RVL_TESTS: rvl.Clear() rvl.plain = list(v[0]) got = rvl.CompressRVL() self.assertEqual(len(rvl.encoded), len(v[1]), "RVL compress length for test") for i in range(len(v[1])): self.assertEqual( "%02x" % rvl.encoded[i], "%02x" % v[1][i], "RVL compression at index %d for test %s" % (i, v[0]))
def test_vle_encode(self): for v in self.VLE_TESTS: rvl.Clear() rvl.EncodeVLE(v[0]) rvl.Flush() self.assertEqual(len(rvl.encoded), len(v[1]), "VLE length for test %d" % v[0]) for i in range(len(v[1])): self.assertEqual( "%x" % rvl.encoded[i], "%x" % v[1][i], "VLE encoding at index %d for test %d" % (i, v[0]))
def gen_and_send(ts): data = [] w = 128 nvecs = w * w for i in range(w): for j in range(w): v = (math.sin(i / 16.0 + ts / 3.0) + math.cos(j / 16.0 + ts / 3.0)) * 0.1 data += [int(v * SCALE_FACTOR)] rvl.Clear() rvl.plain = data rvl.CompressRVL() packed = struct.pack(fmt % len(rvl.encoded), 20, nvecs, *rvl.encoded) print(len(packed)) sock.sendto(packed, (UDP_IP, UDP_PORT))