updates to rotating machine struct
This commit is contained in:
31
test/basic/constructor.basic.test.js
Normal file
31
test/basic/constructor.basic.test.js
Normal file
@@ -0,0 +1,31 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
|
||||
const Machine = require('../../src/specificClass');
|
||||
const { makeMachineConfig, makeStateConfig } = require('../helpers/factories');
|
||||
|
||||
test('constructor initializes with valid curve model', () => {
|
||||
const machine = new Machine(makeMachineConfig(), makeStateConfig());
|
||||
assert.equal(machine.hasCurve, true);
|
||||
assert.ok(machine.predictFlow);
|
||||
assert.ok(machine.predictPower);
|
||||
assert.ok(machine.predictCtrl);
|
||||
|
||||
const out = machine.getOutput();
|
||||
assert.ok('state' in out);
|
||||
assert.ok('mode' in out);
|
||||
assert.ok('ctrl' in out);
|
||||
});
|
||||
|
||||
test('constructor handles missing curve model without throwing', () => {
|
||||
const cfg = makeMachineConfig({ asset: { supplier: 'x', category: 'machine', type: 'pump', model: 'not-existing-model', unit: 'm3/h' } });
|
||||
const machine = new Machine(cfg, makeStateConfig());
|
||||
|
||||
assert.equal(machine.hasCurve, false);
|
||||
assert.equal(machine.predictFlow, null);
|
||||
assert.equal(machine.predictPower, null);
|
||||
assert.equal(machine.predictCtrl, null);
|
||||
|
||||
const out = machine.getOutput();
|
||||
assert.ok('state' in out);
|
||||
});
|
||||
35
test/basic/mode-and-input.basic.test.js
Normal file
35
test/basic/mode-and-input.basic.test.js
Normal file
@@ -0,0 +1,35 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
|
||||
const Machine = require('../../src/specificClass');
|
||||
const { makeMachineConfig, makeStateConfig } = require('../helpers/factories');
|
||||
|
||||
test('setMode changes mode only for allowed values', () => {
|
||||
const machine = new Machine(makeMachineConfig(), makeStateConfig());
|
||||
const original = machine.currentMode;
|
||||
|
||||
machine.setMode('virtualControl');
|
||||
assert.equal(machine.currentMode, 'virtualControl');
|
||||
|
||||
machine.setMode('invalid-mode');
|
||||
assert.equal(machine.currentMode, 'virtualControl');
|
||||
assert.notEqual(machine.currentMode, original);
|
||||
});
|
||||
|
||||
test('handleInput rejects non-string action safely', async () => {
|
||||
const machine = new Machine(makeMachineConfig(), makeStateConfig());
|
||||
await assert.doesNotReject(async () => {
|
||||
await machine.handleInput('GUI', 123, null);
|
||||
});
|
||||
});
|
||||
|
||||
test('handleInput ignores disallowed source/action combination', async () => {
|
||||
const machine = new Machine(makeMachineConfig(), makeStateConfig());
|
||||
machine.setMode('fysicalControl');
|
||||
|
||||
const before = machine.state.getCurrentState();
|
||||
await machine.handleInput('GUI', 'execSequence', 'startup');
|
||||
const after = machine.state.getCurrentState();
|
||||
|
||||
assert.equal(before, after);
|
||||
});
|
||||
Reference in New Issue
Block a user