96 lines
2.4 KiB
JavaScript
96 lines
2.4 KiB
JavaScript
const Monster = require('../src/specificClass');
|
|
|
|
describe('monster specificClass', () => {
|
|
function createMonster(overrides = {}) {
|
|
return new Monster({
|
|
general: {
|
|
name: 'Monster Test',
|
|
unit: 'm3/h',
|
|
logging: {
|
|
enabled: false,
|
|
logLevel: 'error',
|
|
},
|
|
},
|
|
asset: {
|
|
emptyWeightBucket: 3,
|
|
},
|
|
constraints: {
|
|
samplingtime: 1,
|
|
minVolume: 5,
|
|
maxWeight: 23,
|
|
},
|
|
functionality: {
|
|
aquonSampleName: '112100',
|
|
},
|
|
...overrides,
|
|
});
|
|
}
|
|
|
|
test('aggregates rain data and exposes output state', () => {
|
|
const monster = createMonster();
|
|
|
|
monster.rain_data = [
|
|
{
|
|
latitude: 51.7,
|
|
longitude: 4.81,
|
|
hourly: {
|
|
time: ['2026-03-12T00:00', '2026-03-12T01:00'],
|
|
precipitation: [1, 3],
|
|
precipitation_probability: [100, 50],
|
|
},
|
|
},
|
|
{
|
|
latitude: 51.8,
|
|
longitude: 4.91,
|
|
hourly: {
|
|
time: ['2026-03-12T00:00', '2026-03-12T01:00'],
|
|
precipitation: [2, 2],
|
|
precipitation_probability: [100, 100],
|
|
},
|
|
},
|
|
];
|
|
|
|
const output = monster.getOutput();
|
|
|
|
expect(monster.sumRain).toBe(6.5);
|
|
expect(monster.avgRain).toBe(3.25);
|
|
expect(output.sumRain).toBe(6.5);
|
|
expect(output.avgRain).toBe(3.25);
|
|
});
|
|
|
|
test('supports external prediction input and starts sampling safely', () => {
|
|
const monster = createMonster();
|
|
|
|
monster.setModelPrediction(120);
|
|
monster.q = 3600;
|
|
monster.i_start = true;
|
|
monster.flowTime = Date.now() - 1000;
|
|
|
|
monster.tick();
|
|
|
|
const output = monster.getOutput();
|
|
expect(output.running).toBe(true);
|
|
expect(output.predFlow).toBe(120);
|
|
expect(output.predM3PerSec).toBeCloseTo(120 / 3600, 6);
|
|
});
|
|
|
|
test('calculates the next AQUON date from monsternametijden input', () => {
|
|
const monster = createMonster();
|
|
const nextMonth = new Date();
|
|
nextMonth.setMonth(nextMonth.getMonth() + 1);
|
|
|
|
monster.monsternametijden = [
|
|
{
|
|
SAMPLE_NAME: '112100',
|
|
DESCRIPTION: 'future sample',
|
|
SAMPLED_DATE: null,
|
|
START_DATE: nextMonth.toISOString(),
|
|
END_DATE: nextMonth.toISOString(),
|
|
},
|
|
];
|
|
|
|
expect(monster.daysPerYear).toBeGreaterThanOrEqual(0);
|
|
expect(monster.nextDate).toBeGreaterThan(Date.now());
|
|
});
|
|
});
|