Fix simulation bugs found in review, faster routing, deterministic tests

This commit is contained in:
Frederic Jung 2026-10-23 17:50:31 +02:00
parent 8b64570b8e
commit f51c68a8ac
No known key found for this signature in database
4 changed files with 57 additions and 50 deletions

View file

@ -25,6 +25,8 @@ function load(opts = {}) {
},
});
const ev = (src) => dom.window.eval(src);
// Deterministic by default so a test never passes or fails by luck; pass {seed:false} to opt out.
if (opts.seed !== false) seed(ev, opts.seed || 12345);
return { dom, ev, errors };
}

View file

@ -16,7 +16,7 @@ test('sandbox: endless money, every unlock, nothing breaks, no badges', () => {
});
test('scenarios: rules apply, goals complete, deadlines fail, seeds repeat', () => {
const { ev, errors } = load();
const { ev, errors } = load({ seed: false });
ev("ACT.scenarios()");
assert.match(ev("document.getElementById('modalCard').textContent"), /Weekly challenge/);
ev("ACT.startScn({id:'stg'})");

View file

@ -107,13 +107,13 @@ test('metro diversity: a second site keeps half the POP up and uplinks follow th
ev("ACT.siteSet({k:'t',id:S.transit[1].id,s:'b'})");
assert.equal(ev("S.transit[1].site"), 'b');
// a power cut in site A: the POP stays up at half capacity, only site-B transit works
ev("S.pops.fra.sdown={until:S.day+3,s:'a'};compute()");
ev("addInc({type:'site',ref:'fra',site:'a',until:S.day+3,msg:'x',cost:0});compute()");
assert.equal(ev("popUp('fra')"), true);
assert.equal(ev("nodeCap('fra')"), cap0 / 2);
assert.equal(ev("R.useT[S.transit[0].id]||0"), 0, 'site A transit is dark');
assert.ok(ev("R.useT[S.transit[1].id]") > 0, 'site B transit carries traffic');
// the incident path also uses the second site
ev("S.pops.fra.sdown=null;S.pops.fra.gen=false;for(let i=0;i<500&&!S.inc.some(x=>x.type==='site'||x.type==='ring');i++){fireFailure();S.inc=S.inc.filter(x=>x.type==='site'||x.type==='ring');for(const c in S.pops)S.pops[c].down=0;}");
ev("S.inc=[];S.pops.fra.gen=false;for(let i=0;i<500&&!S.inc.some(x=>x.type==='site'||x.type==='ring');i++){fireFailure();S.inc=S.inc.filter(x=>x.type==='site'||x.type==='ring');for(const c in S.pops)S.pops[c].down=0;}");
assert.ok(ev("S.inc.some(x=>x.type==='site'||x.type==='ring')"), 'site outages and ring cuts happen');
ev("selectCity('fra');ACT.tab({t:'infra'})");
assert.match(ev("document.getElementById('panelBody').textContent"), /Metro diversity/);