50 lines
1.5 KiB
JavaScript
50 lines
1.5 KiB
JavaScript
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
|
|
const Monster = require('../../src/specificClass');
|
|
const {
|
|
makeMonsterConfig,
|
|
withMockedDate,
|
|
makeFlowMeasurementChild,
|
|
loadRainSeed,
|
|
loadScheduleSeed,
|
|
} = require('../helpers/factories');
|
|
|
|
test('effective flow uses average of measured and manual flow', () => {
|
|
withMockedDate('2024-10-15T00:00:00Z', ({ advance }) => {
|
|
const monster = new Monster(makeMonsterConfig());
|
|
const child = makeFlowMeasurementChild({ positionVsParent: 'downstream' });
|
|
monster.registerChild(child, 'measurement');
|
|
|
|
child.measurements
|
|
.type('flow')
|
|
.variant('measured')
|
|
.position('downstream')
|
|
.value(60, Date.now(), 'm3/h');
|
|
|
|
monster.handleInput('input_q', { value: 20, unit: 'm3/h' });
|
|
advance(1000);
|
|
monster.tick();
|
|
|
|
assert.equal(monster.q, 40);
|
|
});
|
|
});
|
|
|
|
test('rain and schedule payloads update prediction context and next date', () => {
|
|
withMockedDate('2024-10-15T00:00:00Z', () => {
|
|
const monster = new Monster(makeMonsterConfig());
|
|
const rain = loadRainSeed();
|
|
const schedule = loadScheduleSeed();
|
|
|
|
monster.aquonSampleName = '112100';
|
|
monster.handleInput('rain_data', rain);
|
|
monster.handleInput('monsternametijden', schedule);
|
|
|
|
assert.ok(monster.avgRain >= 0);
|
|
assert.ok(monster.sumRain >= 0);
|
|
const nextDate = monster.nextDate instanceof Date ? monster.nextDate.getTime() : Number(monster.nextDate);
|
|
assert.ok(Number.isFinite(nextDate));
|
|
assert.ok(nextDate > Date.now());
|
|
});
|
|
});
|