File size: 1,077 Bytes
dbb04e4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | import unittest
import numpy as np
import base64
import sys
import os
# Add root to checking path
sys.path.append(os.getcwd())
from mnemocore.core.binary_hdv import BinaryHDV
class TestMinimal(unittest.TestCase):
def test_packed_payload_roundtrip(self):
print("Starting test...")
dim = 16384
original_hdv = BinaryHDV.random(dimension=dim)
packed_bytes = original_hdv.data.tobytes()
packed_b64 = base64.b64encode(packed_bytes).decode('ascii')
payload = {
"hdv_packed_b64": packed_b64,
"dimension": dim,
"hdv_type": "binary"
}
restored_bytes = base64.b64decode(payload["hdv_packed_b64"])
restored_packed = np.frombuffer(restored_bytes, dtype=np.uint8)
restored_hdv = BinaryHDV(data=restored_packed, dimension=payload["dimension"])
np.testing.assert_array_equal(original_hdv.data, restored_hdv.data)
print("Test passed!")
if __name__ == '__main__':
unittest.main()
|