Intern: write the shift log as a reload keeps it, and drop opsTidy()
The day's log named every order that ran out of budget, and the week's tally got an empty list for a job with no place (a rushed repair, a route server); a reload keeps three places a kind and no empty lists, so opsTidy() trimmed live state after every shift. The shift now writes it that way itself: the broken orders are cut to three ([...X.broke].slice(0,3)), and W.wh[k] is made only for a job that names a place. tests/canonical-state.test.js passes without opsTidy() (a year of the big network with everything on, checked every day), so it is gone.
This commit is contained in:
parent
286ae48207
commit
02b6c24d7b
3 changed files with 25 additions and 7 deletions
|
|
@ -146,6 +146,26 @@ test('repairs: rush what has a price, as the Rush repair button would', t => {
|
|||
ev => on(ev, 'repair'), "ACT.fixInc({id:'amp'})", 'S.inc.length');
|
||||
});
|
||||
|
||||
test("the shift's log and the week's tally are what a reload keeps: three places a kind at most, no empty lists", t => {
|
||||
const { ev, errors } = game(t, "S.links=[{id:'f',a:'fra',b:'ams',kind:'df',sys:'lite',ch:['zr4'],km:450,sub:false,ready:0,cut:0,eqDown:10,mo:1}];S.inc=[{id:'amp',type:'amp',ref:'f',until:10,cost:3000,msg:'amp'}];S.pops.ams={day:0,bb:null,boost:0,down:0,routers:1,gen:false}");
|
||||
hire(ev);
|
||||
on(ev, 'repair');
|
||||
// Five orders that each find a job today's money cannot pay for.
|
||||
const K = ['transit', 'ports', 'routers', 'std', 'optics'];
|
||||
ev(`for(const k of ${lit(K)}){S.ops.on[k]=true;OPS_RUN[k]=function*(X){X.can(k,1e12);};}`);
|
||||
shift(ev);
|
||||
const r = JSON.parse(ev('JSON.stringify(S.ops.log[0].r)'));
|
||||
assert.deepEqual(r.find(x => x[0] === 'repair'), ['repair', 1, []], 'a rushed repair names no place');
|
||||
assert.deepEqual(r.find(x => x[0] === 'broke'), ['broke', 5, ['std', 'routers', 'transit']], 'five budgets ran out, the first three in the shift named');
|
||||
assert.equal(ev("own(S.ops.wk.wh,'repair')"), false, "no empty list in the week's tally");
|
||||
assert.equal(ev("S.ops.wk.wh.broke.length"), 3);
|
||||
// Straight from the shift (dayTick() is not in between): what a reload makes of it, key for key.
|
||||
const same = ev(`(()=>{const u0=uidN,r0=S.rng,k=v=>Array.isArray(v)?v.map(k):v&&typeof v==='object'?Object.keys(v).sort().reduce((o,x)=>(v[x]!==undefined&&(o[x]=k(v[x])),o),{}):v,
|
||||
pick=o=>JSON.stringify(k({log:o.log,wk:o.wk,rep:o.rep})),a=pick(JSON.parse(JSON.stringify(S.ops))),b=pick(migrate(JSON.parse(JSON.stringify(S))).ops);uidN=u0;S.rng=r0;return a===b||a+' vs '+b;})()`);
|
||||
assert.equal(same, true);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('optics: light hot fiber with the optic already in it, at the #177 batch price', t => {
|
||||
const extra = "ACT.buildPop({city:'ams'});S.pops.ams.rgen=1;S.links.push({id:'f',a:'fra',b:'ams',kind:'df',sys:'lite',ch:['zr4'],km:450,sub:false,ready:0,cut:0,mo:1,trench:'f'});compute();R.load.f=dfCap(S.links.at(-1))*0.95";
|
||||
const A = twins(t, extra, ev => on(ev, 'optics', { at: 70 }),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue