Files
reactor/test/basic/constructor.basic.test.js

66 lines
2.7 KiB
JavaScript
Raw Normal View History

2026-02-19 17:37:42 +01:00
const test = require('node:test');
const assert = require('node:assert/strict');
const NodeClass = require('../../src/nodeClass');
const { Reactor_CSTR, Reactor_PFR } = require('../../src/specificClass');
const { makeUiConfig } = require('../helpers/factories');
2026-02-19 17:37:42 +01:00
// These tests pinned the old private _loadConfig / _setupClass methods on
// the pre-refactor nodeClass. After the BaseNodeAdapter migration the
// same logic lives in buildDomainConfig + the Reactor wrapper's engine
// selector. We exercise both surfaces directly.
test('buildDomainConfig coerces numeric fields and builds initial state vector', () => {
2026-02-19 17:37:42 +01:00
const inst = Object.create(NodeClass.prototype);
inst.node = { id: 'n-reactor-1' };
inst.name = 'reactor';
const dc = inst.buildDomainConfig(
2026-02-19 17:37:42 +01:00
makeUiConfig({
volume: '12.5',
length: '9',
resolution_L: '7',
alpha: '0.5',
n_inlets: '3',
timeStep: '2',
S_O_init: '1.1',
}),
);
assert.equal(dc.reactor.volume, 12.5);
assert.equal(dc.reactor.length, 9);
assert.equal(dc.reactor.resolution_L, 7);
assert.equal(dc.reactor.alpha, 0.5);
assert.equal(dc.reactor.n_inlets, 3);
assert.equal(dc.reactor.timeStep, 2);
assert.equal(Object.keys(dc.initialState).length, 13);
assert.equal(dc.initialState.S_O, 1.1);
2026-02-19 17:37:42 +01:00
});
test('Reactor wrapper instantiates CSTR engine when configured as CSTR', () => {
const Reactor = require('../../src/specificClass');
const config = {
general: { name: 'reactor', id: 'n', logging: { enabled: false, logLevel: 'error' } },
functionality: { softwareType: 'reactor', positionVsParent: 'atEquipment' },
reactor: { reactor_type: 'CSTR', volume: 100, length: 10, resolution_L: 5, alpha: 0,
n_inlets: 1, kla: NaN, timeStep: 1 },
initialState: { S_O: 0, S_I: 30, S_S: 100, S_NH: 16, S_N2: 0, S_NO: 0, S_HCO: 5,
X_I: 25, X_S: 75, X_H: 30, X_STO: 0, X_A: 0.001, X_TS: 125 },
};
const r = new Reactor(config);
assert.ok(r.engine instanceof Reactor_CSTR);
2026-02-19 17:37:42 +01:00
});
test('Reactor wrapper instantiates PFR engine when configured as PFR', () => {
const Reactor = require('../../src/specificClass');
const config = {
general: { name: 'reactor', id: 'n', logging: { enabled: false, logLevel: 'error' } },
functionality: { softwareType: 'reactor', positionVsParent: 'atEquipment' },
reactor: { reactor_type: 'PFR', volume: 100, length: 10, resolution_L: 5, alpha: 0,
n_inlets: 1, kla: NaN, timeStep: 1 },
initialState: { S_O: 0, S_I: 30, S_S: 100, S_NH: 16, S_N2: 0, S_NO: 0, S_HCO: 5,
X_I: 25, X_S: 75, X_H: 30, X_STO: 0, X_A: 0.001, X_TS: 125 },
};
const r = new Reactor(config);
assert.ok(r.engine instanceof Reactor_PFR);
2026-02-19 17:37:42 +01:00
});