Files
rotatingMachine/test/integration/sequences.integration.test.js

30 lines
1.3 KiB
JavaScript
Raw Normal View History

2026-02-12 10:48:44 +01:00
const test = require('node:test');
const assert = require('node:assert/strict');
const Machine = require('../../src/specificClass');
const { makeMachineConfig, makeStateConfig } = require('../helpers/factories');
test('execSequence startup reaches operational with zero transition times', async () => {
const machine = new Machine(makeMachineConfig(), makeStateConfig());
await machine.handleInput('parent', 'execSequence', 'startup');
assert.equal(machine.state.getCurrentState(), 'operational');
});
2026-03-11 11:13:26 +01:00
test('execMovement constrains controller position to safe bounds in operational state', async () => {
2026-02-12 10:48:44 +01:00
const machine = new Machine(makeMachineConfig(), makeStateConfig({ state: { current: 'operational' } }));
const { min, max } = machine._resolveSetpointBounds();
2026-02-12 10:48:44 +01:00
// Test upper constraint: setpoint above max gets clamped to max
await machine.handleInput('parent', 'execMovement', max + 50);
let pos = machine.state.getCurrentPosition();
assert.equal(pos, max, `setpoint above max should be clamped to ${max}`);
2026-02-12 10:48:44 +01:00
// Test that a valid setpoint within bounds is applied as-is
await machine.handleInput('parent', 'execMovement', 10);
pos = machine.state.getCurrentPosition();
assert.equal(pos, 10, 'setpoint within bounds should be applied as-is');
assert.ok(pos >= min && pos <= max);
2026-02-12 10:48:44 +01:00
});