Expand reactor demo telemetry and stability handling
This commit is contained in:
@@ -1,45 +1,45 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
|
||||
const { Reactor_CSTR, Reactor_PFR } = require('../../src/specificClass');
|
||||
const { makeReactorConfig } = require('../helpers/factories');
|
||||
|
||||
test('CSTR getGridProfile returns null', () => {
|
||||
const reactor = new Reactor_CSTR(makeReactorConfig({ reactor_type: 'CSTR' }));
|
||||
assert.equal(reactor.getGridProfile, null);
|
||||
});
|
||||
|
||||
test('PFR getGridProfile returns state matrix with correct dimensions', () => {
|
||||
const n_x = 8;
|
||||
const length = 40;
|
||||
const reactor = new Reactor_PFR(
|
||||
makeReactorConfig({ reactor_type: 'PFR', resolution_L: n_x, length }),
|
||||
);
|
||||
|
||||
const profile = reactor.getGridProfile;
|
||||
assert.notEqual(profile, null);
|
||||
assert.equal(profile.n_x, n_x);
|
||||
assert.equal(profile.d_x, length / n_x);
|
||||
assert.equal(profile.length, length);
|
||||
assert.equal(profile.grid.length, n_x, 'grid should have n_x rows');
|
||||
assert.equal(profile.grid[0].length, 13, 'each row should have 13 species');
|
||||
assert.ok(Array.isArray(profile.species), 'species list should be an array');
|
||||
assert.equal(profile.species.length, 13);
|
||||
assert.equal(profile.species[3], 'S_NH');
|
||||
assert.equal(typeof profile.timestamp, 'number');
|
||||
});
|
||||
|
||||
test('PFR getGridProfile is mutation-safe', () => {
|
||||
const reactor = new Reactor_PFR(
|
||||
makeReactorConfig({ reactor_type: 'PFR', resolution_L: 5, length: 10 }),
|
||||
);
|
||||
|
||||
const profile = reactor.getGridProfile;
|
||||
const originalValue = reactor.state[0][3]; // S_NH at cell 0
|
||||
|
||||
// Mutate the returned grid
|
||||
profile.grid[0][3] = 999;
|
||||
|
||||
// Reactor internal state should be unchanged
|
||||
assert.equal(reactor.state[0][3], originalValue, 'mutating grid copy must not affect reactor state');
|
||||
});
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
|
||||
const { Reactor_CSTR, Reactor_PFR } = require('../../src/specificClass');
|
||||
const { makeReactorConfig } = require('../helpers/factories');
|
||||
|
||||
test('CSTR getGridProfile returns null', () => {
|
||||
const reactor = new Reactor_CSTR(makeReactorConfig({ reactor_type: 'CSTR' }));
|
||||
assert.equal(reactor.getGridProfile, null);
|
||||
});
|
||||
|
||||
test('PFR getGridProfile returns state matrix with correct dimensions', () => {
|
||||
const n_x = 8;
|
||||
const length = 40;
|
||||
const reactor = new Reactor_PFR(
|
||||
makeReactorConfig({ reactor_type: 'PFR', resolution_L: n_x, length }),
|
||||
);
|
||||
|
||||
const profile = reactor.getGridProfile;
|
||||
assert.notEqual(profile, null);
|
||||
assert.equal(profile.n_x, n_x);
|
||||
assert.equal(profile.d_x, length / n_x);
|
||||
assert.equal(profile.length, length);
|
||||
assert.equal(profile.grid.length, n_x, 'grid should have n_x rows');
|
||||
assert.equal(profile.grid[0].length, 13, 'each row should have 13 species');
|
||||
assert.ok(Array.isArray(profile.species), 'species list should be an array');
|
||||
assert.equal(profile.species.length, 13);
|
||||
assert.equal(profile.species[3], 'S_NH');
|
||||
assert.equal(typeof profile.timestamp, 'number');
|
||||
});
|
||||
|
||||
test('PFR getGridProfile is mutation-safe', () => {
|
||||
const reactor = new Reactor_PFR(
|
||||
makeReactorConfig({ reactor_type: 'PFR', resolution_L: 5, length: 10 }),
|
||||
);
|
||||
|
||||
const profile = reactor.getGridProfile;
|
||||
const originalValue = reactor.state[0][3]; // S_NH at cell 0
|
||||
|
||||
// Mutate the returned grid
|
||||
profile.grid[0][3] = 999;
|
||||
|
||||
// Reactor internal state should be unchanged
|
||||
assert.equal(reactor.state[0][3], originalValue, 'mutating grid copy must not affect reactor state');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user