Files
appRobotHoming/test/spinNormalize.test.js
2026-06-15 09:23:21 +02:00

47 lines
1.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* spinNormalize.test.js
* Unit-Tests für server/spinNormalize.cjs
*
* Sichert ab, dass der Spin-Normalisierer alle Randfälle korrekt behandelt,
* insbesondere negative Werte (z.B. 0 90 = 90 → 270).
*/
const { normalizeSpinDeg } = require('../server/spinNormalize.cjs');
describe('normalizeSpinDeg', () => {
test('Standardwerte 0 / 90 / 180 / 270 bleiben unverändert', () => {
expect(normalizeSpinDeg(0)).toBe(0);
expect(normalizeSpinDeg(90)).toBe(90);
expect(normalizeSpinDeg(180)).toBe(180);
expect(normalizeSpinDeg(270)).toBe(270);
});
test('Wert 360 wird auf 0 normalisiert', () => {
expect(normalizeSpinDeg(360)).toBe(0);
expect(normalizeSpinDeg(720)).toBe(0);
expect(normalizeSpinDeg(450)).toBe(90);
});
test('Negative Werte werden korrekt umgerechnet', () => {
expect(normalizeSpinDeg(-90)).toBe(270); // 0 90 → 270
expect(normalizeSpinDeg(-180)).toBe(180);
expect(normalizeSpinDeg(-270)).toBe(90);
expect(normalizeSpinDeg(-360)).toBe(0);
expect(normalizeSpinDeg(-1)).toBe(359);
});
test('Strings werden als Zahlen interpretiert', () => {
expect(normalizeSpinDeg('90')).toBe(90);
expect(normalizeSpinDeg('-90')).toBe(270);
});
test('Ergebnis liegt immer in [0, 360)', () => {
const inputs = [-720, -359, -1, 0, 1, 89, 90, 179, 270, 359, 360, 450, 720, 1080];
for (const v of inputs) {
const r = normalizeSpinDeg(v);
expect(r).toBeGreaterThanOrEqual(0);
expect(r).toBeLessThan(360);
}
});
});