before functional changes by codex
This commit is contained in:
48
test/integration/upstream-reactor.integration.test.js
Normal file
48
test/integration/upstream-reactor.integration.test.js
Normal file
@@ -0,0 +1,48 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
|
||||
const { Reactor_CSTR } = require('../../src/specificClass');
|
||||
const { makeReactorConfig } = require('../helpers/factories');
|
||||
|
||||
const DAY_MS = 1000 * 60 * 60 * 24;
|
||||
|
||||
test('registering upstream reactor subscribes to upstream stateChange events', () => {
|
||||
const downstream = new Reactor_CSTR(makeReactorConfig({ reactor_type: 'CSTR' }));
|
||||
const upstream = new Reactor_CSTR(makeReactorConfig({ reactor_type: 'CSTR' }));
|
||||
|
||||
let calledWith = null;
|
||||
downstream.updateState = (timestamp) => {
|
||||
calledWith = timestamp;
|
||||
};
|
||||
|
||||
downstream.registerChild(upstream, 'reactor');
|
||||
upstream.emitter.emit('stateChange', 12345);
|
||||
|
||||
assert.equal(downstream.upstreamReactor, upstream);
|
||||
assert.equal(calledWith, 12345);
|
||||
});
|
||||
|
||||
test('updateState pulls influent from upstream reactor effluent when linked', () => {
|
||||
const downstream = new Reactor_CSTR(makeReactorConfig({ reactor_type: 'CSTR', n_inlets: 1, timeStep: 1 }));
|
||||
const upstream = new Reactor_CSTR(makeReactorConfig({ reactor_type: 'CSTR', n_inlets: 1 }));
|
||||
|
||||
upstream.Fs[0] = 3;
|
||||
upstream.state = Array(13).fill(11);
|
||||
|
||||
downstream.upstreamReactor = upstream;
|
||||
downstream.currentTime = 0;
|
||||
downstream.timeStep = 1;
|
||||
downstream.speedUpFactor = 1;
|
||||
|
||||
let ticks = 0;
|
||||
downstream.tick = () => {
|
||||
ticks += 1;
|
||||
return downstream.state;
|
||||
};
|
||||
|
||||
downstream.updateState(DAY_MS);
|
||||
|
||||
assert.equal(ticks, 1);
|
||||
assert.equal(downstream.Fs[0], 3);
|
||||
assert.deepEqual(downstream.Cs_in[0], Array(13).fill(11));
|
||||
});
|
||||
Reference in New Issue
Block a user