Tests
CalculateAngles verpacken
This commit is contained in:
55
test/calculateAngles.test.js
Normal file
55
test/calculateAngles.test.js
Normal file
@@ -0,0 +1,55 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { calculate } = require('../public/calculateAngles.cjs');
|
||||
|
||||
/* -------------------------
|
||||
Hilfsfunktionen
|
||||
------------------------- */
|
||||
|
||||
function loadMarkersFromCSV(filePath) {
|
||||
const text = fs.readFileSync(filePath, 'utf8');
|
||||
|
||||
const [header, ...lines] = text
|
||||
.split('\n')
|
||||
.map(l => l.trim())
|
||||
.filter(Boolean);
|
||||
|
||||
return lines.map(line => {
|
||||
const [
|
||||
id,
|
||||
x, y, z,
|
||||
roll, pitch, yaw,
|
||||
seen_by
|
||||
] = line.split(',');
|
||||
|
||||
return {
|
||||
id: Number(id),
|
||||
position: [Number(x), Number(y), Number(z)],
|
||||
rotation: [Number(roll), Number(pitch), Number(yaw)],
|
||||
seen_by: Number(seen_by)
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function loadJSON(filePath) {
|
||||
return JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
||||
}
|
||||
|
||||
/* -------------------------
|
||||
Tests
|
||||
------------------------- */
|
||||
|
||||
describe('calculateAngles.calculate', () => {
|
||||
test('berechnet X-Durchschnitt für Base / Arm1 / Joint1', async () => {
|
||||
const markersPath = path.resolve('./test/snapshots/snapshot_video0_1774805028717_two_cam.csv');
|
||||
const robotPath = path.resolve('./public/robot.json');
|
||||
|
||||
const foundMarkers = loadMarkersFromCSV(markersPath);
|
||||
const jsonRobot = loadJSON(robotPath);
|
||||
|
||||
const result = await calculate(foundMarkers, jsonRobot);
|
||||
|
||||
expect(result.status).toBe('ok');
|
||||
expect(result.result).toBeDefined();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user