Synchronizing workflow monster
This commit is contained in:
@@ -1,121 +0,0 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
|
||||
const Monster = require('../src/specificClass');
|
||||
|
||||
function createConfig(overrides = {}) {
|
||||
return {
|
||||
general: {
|
||||
name: 'monster-test',
|
||||
logging: { enabled: false, logLevel: 'error' },
|
||||
},
|
||||
asset: {
|
||||
emptyWeightBucket: 3,
|
||||
...overrides.asset,
|
||||
},
|
||||
constraints: {
|
||||
samplingtime: 24,
|
||||
minVolume: 5,
|
||||
maxWeight: 23,
|
||||
...overrides.constraints,
|
||||
},
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
test('constructor derives boundaries and targets from config', () => {
|
||||
const monster = new Monster(createConfig());
|
||||
|
||||
assert.equal(monster.maxVolume, 20);
|
||||
assert.equal(monster.minPuls, 100);
|
||||
assert.equal(monster.maxPuls, 400);
|
||||
assert.equal(monster.absMaxPuls, 1100);
|
||||
assert.equal(monster.targetVolume, 10);
|
||||
assert.equal(monster.targetPuls, 200);
|
||||
assert.equal(monster.running, false);
|
||||
});
|
||||
|
||||
test('bucket volume updates output and bucket weight', () => {
|
||||
const monster = new Monster(createConfig());
|
||||
monster.bucketVol = 1.5;
|
||||
|
||||
assert.equal(monster.bucketVol, 1.5);
|
||||
assert.equal(monster.bucketWeight, 4.5);
|
||||
|
||||
const out = monster.getOutput();
|
||||
assert.equal(out.bucketVol, 1.5);
|
||||
assert.equal(out.bucketWeight, 4.5);
|
||||
});
|
||||
|
||||
test('monsternametijden setter registers next date for matching sample', () => {
|
||||
const monster = new Monster(createConfig());
|
||||
const future = new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString();
|
||||
|
||||
monster.monsternametijden = [
|
||||
{
|
||||
SAMPLE_NAME: monster.aquonSampleName,
|
||||
DESCRIPTION: 'test',
|
||||
SAMPLED_DATE: future,
|
||||
START_DATE: future,
|
||||
END_DATE: future,
|
||||
},
|
||||
];
|
||||
|
||||
assert.ok(monster.nextDate >= Date.now());
|
||||
assert.ok(monster.daysPerYear >= 1);
|
||||
});
|
||||
|
||||
test('sampling_program starts and emits pulses based on m3PerTick', () => {
|
||||
const monster = new Monster(
|
||||
createConfig({
|
||||
constraints: {
|
||||
samplingtime: 1,
|
||||
minVolume: 0.1,
|
||||
maxWeight: 23,
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
monster.nextDate = Date.now() + 60_000;
|
||||
monster.i_start = true;
|
||||
monster.q = 28; // => predFlow = 28 m3 for 1 hour (fallback)
|
||||
monster.m3PerTick = 1; // with m3PerPuls ~1 this should trigger a pulse
|
||||
|
||||
monster.sampling_program();
|
||||
|
||||
assert.equal(monster.running, true);
|
||||
assert.equal(monster.sumPuls, 1);
|
||||
assert.equal(monster.pulse, true);
|
||||
assert.equal(monster.bucketVol, 0.05);
|
||||
|
||||
// Next loop without flow should stop pulsing
|
||||
monster.m3PerTick = 0;
|
||||
monster.sampling_program();
|
||||
assert.equal(monster.pulse, false);
|
||||
});
|
||||
|
||||
test('sampling_program stops and resets after stop_time has passed', () => {
|
||||
const monster = new Monster(
|
||||
createConfig({
|
||||
constraints: { samplingtime: 1, minVolume: 0.1, maxWeight: 23 },
|
||||
})
|
||||
);
|
||||
|
||||
monster.running = true;
|
||||
monster.stop_time = Date.now() - 1;
|
||||
monster.sumPuls = 10;
|
||||
monster.bucketVol = 0.5;
|
||||
monster.predFlow = 123;
|
||||
monster.predM3PerSec = 1;
|
||||
monster.m3Total = 10;
|
||||
|
||||
monster.sampling_program();
|
||||
|
||||
assert.equal(monster.running, false);
|
||||
assert.equal(monster.sumPuls, 0);
|
||||
assert.equal(monster.bucketVol, 0);
|
||||
assert.equal(monster.predFlow, 0);
|
||||
assert.equal(monster.predM3PerSec, 0);
|
||||
assert.equal(monster.m3Total, 0);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user