const { deepEqual, throws } = require('assert'); const { describe, it } = require('node:test'); const { Decoders } = require('../dist/cjs'); const goodTests = [ { description: 'RTTrP Header', bytes: new Uint8Array([ 0x41, 0x54, 0x43, 0x34, 0x00, 0x02, 0x12, 0x34, 0x56, 0x78, 0x00, 0x00, 0x12, 0x12, 0x34, 0x56, 0x78, 0x00, ]), expected: { intHeader: 0x4154, floatHeader: 0x4334, version: 2, packetID: 305419896, packetFormat: 0, size: 18, context: 305419896, subModuleCount: 0, }, decoder: Decoders.RTTrPHeader, }, { description: 'Centroid Position', bytes: new Uint8Array([ 0x02, 0x00, 0x1d, 0x00, 0x10, 0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ]), expected: { type: 0x02, size: 0x1d, latency: 16, x: 1.0, y: 2.0, z: 3.0, }, decoder: Decoders.CentroidPosition, }, { description: 'Tracked Point Position', bytes: new Uint8Array([ 0x06, 0x00, 0x1e, 0x00, 0x10, 0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, ]), expected: { type: 0x06, size: 0x1e, latency: 16, x: 1.0, y: 2.0, z: 3.0, index: 1, }, decoder: Decoders.TrackedPointPosition, }, { description: 'Orientation (Quaternion)', bytes: new Uint8Array([ 0x03, 0x00, 37, 0x00, 0x10, 0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ]), expected: { type: 0x03, size: 37, latency: 16, Qx: 1.0, Qy: 2.0, Qz: 3.0, Qw: 4.0, }, decoder: Decoders.OrientationQuaternion, }, { description: 'Orientation (Euler)', bytes: new Uint8Array([ 0x04, 0x00, 31, 0x00, 0x10, 0x01, 0x23, 0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ]), expected: { type: 0x04, size: 31, latency: 16, order: 0x0123, r1: 1.0, r2: 2.0, r3: 3.0, }, decoder: Decoders.OrientationEuler, }, ]; describe('RTTrP Bytes Decoding', () => { goodTests.forEach((bytesTest) => { it(bytesTest.description, () => { const decoded = bytesTest.decoder(bytesTest.bytes); deepEqual(decoded, bytesTest.expected); }); }); }); // TODO(jwetzell): add error tests const badTests = []; describe('RTTrP Bytes Decoding Throws', () => { badTests.forEach((bytesTest) => { it(bytesTest.description, () => { throws(() => { bytesTest.decoder(bytesTest.bytes); }, bytesTest.throwsMessage); }); }); });