Skip to content

Commit 1b31af3

Browse files
committed
test(web): add LiDAR codec tests
1 parent 07847ca commit 1b31af3

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import test from 'node:test';
2+
import assert from 'node:assert/strict';
3+
import { decodeLiDARPacket, depthToPointCloud } from './codec.mjs';
4+
5+
function b64(bytes) {
6+
return Buffer.from(bytes).toString('base64');
7+
}
8+
9+
test('decodes u16 millimeter depth and confidence', () => {
10+
const packet = {
11+
type: 'ruview.lidar.depth.v1',
12+
intrinsics: { fx: 100, fy: 100, cx: 1, cy: 1, imageWidth: 2, imageHeight: 2 },
13+
pose: { matrix: Array(16).fill(0) },
14+
depth: {
15+
width: 2,
16+
height: 2,
17+
encoding: 'u16le-mm+u8-confidence',
18+
millimetersBase64: b64([0xe8,0x03,0xd0,0x07,0xb8,0x0b,0xa0,0x0f]),
19+
confidenceBase64: b64([2,2,1,0]),
20+
},
21+
provenance: { sensor: 'test', source: 'live', privacyClass: 'geometry-only', sequence: 1, timestampNs: 1, schema: 'ruview.lidar.depth.v1' },
22+
};
23+
24+
const frame = decodeLiDARPacket(packet);
25+
assert.deepEqual(Array.from(frame.depth.meters), [1,2,3,4]);
26+
assert.deepEqual(Array.from(frame.depth.confidence), [2,2,1,0]);
27+
});
28+
29+
test('rejects malformed payload length', () => {
30+
assert.throws(() => decodeLiDARPacket({
31+
type: 'ruview.lidar.depth.v1',
32+
depth: { width: 2, height: 2, encoding: 'u16le-mm+u8-confidence', millimetersBase64: b64([1,2]), confidenceBase64: b64([1,1,1,1]) },
33+
}), /length mismatch/);
34+
});
35+
36+
test('projects depth into a point cloud and honors confidence', () => {
37+
const frame = {
38+
intrinsics: { fx: 100, fy: 100, cx: 0, cy: 0, imageWidth: 2, imageHeight: 2 },
39+
depth: { width: 2, height: 2, meters: Float32Array.from([1,1,1,1]), confidence: Uint8Array.from([2,0,2,0]) },
40+
};
41+
const points = depthToPointCloud(frame, 1);
42+
assert.equal(points.length, 2);
43+
assert.deepEqual(points[0], [0, 0, -1]);
44+
});

0 commit comments

Comments
 (0)