Tests for Pie in the Sky, and rules O1, O5 and O7
This commit is contained in:
parent
7fb7be305d
commit
2729779501
3 changed files with 344 additions and 1 deletions
|
|
@ -78,3 +78,12 @@ These are what the game promises, held up by `tests/gameplay-rules.test.js` (one
|
|||
| D2 | A flood enters on every port the internet reaches you on, by each network's share, and a port carries only what fits: everyone on a full port loses the same share. | Real floods are spread by geography; one fat port at a single POP is the weak spot (#242). |
|
||||
| D3 | Only upstream tools (RTBH, clean pipe) and an engaged scrubbing center keep a flood off your ports. Flowspec acts on the ingress router, after the port, within that router's own rule budget. | Flowspec protects customers, not the external connections; TCAM is finite. |
|
||||
| D4 | RTBH costs only the target: it goes dark (and its mood drops once), everyone else is saved, and the attack counts as sacrificed, not held. | RTBH is the tool that saves the network and is bad for that one customer, so it must be a real choice. |
|
||||
|
||||
## Orbit (Pie in the Sky, `docs/plans/pie-in-the-sky.md`)
|
||||
|
||||
| Id | Rule | Why |
|
||||
| --- | --- | --- |
|
||||
| O1 | The rocket company unlocks only on the Tier 1 win of a save started on its version (`S.pieV>=1`, set by `newGame()`; a save without it loads as 0), or from day 0 with open gates (sandbox). Never in puzzles, the Architect or scenarios. Losing Tier 1 keeps everything flying but builds nothing new. | An endgame for people who earned it; old won saves must not change under their players. |
|
||||
| O5 | Launches fail only with chaos on (`rule('chaos')`), and never in the first 90 days after the unlock; heavy test flights explode by design, not by chance. (The incidents built later follow the same rule.) | Like F1: learn the thing before it punishes you. |
|
||||
| O7 | A fresh Tier 1 cannot afford a full Shortcrust from its first year's money: even a big network's yearly profit plus the largest loan a bank would offer stays below the cheapest full build (`pieFullCost('short')`). | Obscenely expensive is the joke and the goal; a constellation in year one would be a cheat code. |
|
||||
|
||||
|
|
|
|||
|
|
@ -116,6 +116,8 @@ const REAL_NAMES = [
|
|||
'2Africa', 'Amitié', 'BDSNi', 'CADMOS', 'CARCIP', 'Ceiba-1', 'Ceiba-2', 'DARE1', 'Darwin-Jakarta-Singapore Cable', 'Deep Blue One', 'Dunant', 'East Micronesia Cable', 'Eastern Caribbean Fiber System', 'EllaLink', 'Epic Malta-Sicily Cable System', 'Equiano', 'FALCON', 'Fibralink', 'GO-1', 'Grace Hopper', 'Greenland Connect', 'Greenland Connect North', 'Hibernia Express', 'ICN1', 'Interchange Cable Network 1', 'Jupiter', 'MAREA', 'MedNautilus', 'Melita 1', 'North West Cable System', 'PEACE', 'SEA-ME-WE 6', 'SG-SCS', 'Southern Caribbean Fiber', 'TLSSC', 'Tuvalu Vaka Cable', 'UGARIT', 'Vaka', 'X-Link',
|
||||
// cable ships, their operators and maintenance clubs
|
||||
'ACMA', 'ASEAN Explorer', 'ASEAN Protector', 'ASEAN Restorer', 'Cable Innovator', 'Cable Retriever', 'Global Marine', 'Léon Thévenin', 'MECMA', 'Orange Marine', 'Pierre de Fermat', 'René Descartes', 'SEAIOCMA', 'Sophie Germain', 'Sovereign', 'Wave Sentinel', 'Yokohama Zone',
|
||||
// rockets and satellite networks (Pie in the Sky)
|
||||
'Blue Origin', 'Falcon 9', 'Falcon Heavy', 'Iridium', 'Kuiper', 'OneWeb', 'Project Kuiper', 'SpaceX', 'Starship', 'Starlink',
|
||||
// vendors
|
||||
'Arista', 'Brocade', 'Ciena', 'Cisco', 'Extreme Networks', 'Huawei', 'Infinera', 'Juniper', 'MikroTik', 'Nokia',
|
||||
];
|
||||
|
|
@ -180,7 +182,7 @@ test('N2: names are puns: no network, cable, exchange, data center, router, opti
|
|||
const norm = (s) => String(s).toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g, '').replace(/[’`]/g, "'").replace(/\s+/g, ' ').trim();
|
||||
const real = new Set(REAL_NAMES.map(norm));
|
||||
const names = J(`[...NETS.map(n=>['network',n.name]),...CABLES.map(c=>['cable',c.name]),...XIX.map(x=>['exchange',x.name]),
|
||||
...CITIES.flatMap(c=>[['exchange',c.ix],['data center',c.dc],['data center',c.dc2]]),...RG.map(r=>['router',r.n]),...Object.values(OPT).map(o=>['optic',o.n]),...Object.values(SEAT_ROUTES).flat().map(r=>['cable',r[2]]),...SHIPS.map(x=>['cable ship',x.n]),...LAY_SHIPS.map(n=>['cable ship',n]),...Object.values(SHIP_CLUBS).map(c=>['maintenance club',c.n])].filter(x=>x[1])`);
|
||||
...CITIES.flatMap(c=>[['exchange',c.ix],['data center',c.dc],['data center',c.dc2]]),...RG.map(r=>['router',r.n]),...Object.values(OPT).map(o=>['optic',o.n]),...Object.values(SEAT_ROUTES).flat().map(r=>['cable',r[2]]),...SHIPS.map(x=>['cable ship',x.n]),...LAY_SHIPS.map(n=>['cable ship',n]),...Object.values(SHIP_CLUBS).map(c=>['maintenance club',c.n]),...PIE_NAMES.map(n=>['rocket company',tr(n)]),...Object.values(ROCKETS).map(r=>['rocket',tr(r.n)]),...Object.values(CRUSTS).map(c=>['constellation',tr(c.n)])].filter(x=>x[1])`);
|
||||
fail('N2', names.filter(([, n]) => real.has(norm(n))).map(([k, n]) => `${k} “${n}” is a real name`), 'find a pun');
|
||||
fail('N2', names.filter(([, n]) => /-ish\b/i.test(n)).map(([k, n]) => `${k} “${n}”`), 'no lazy -ish names: find a real pun, or keep the plain word');
|
||||
});
|
||||
|
|
@ -509,6 +511,66 @@ test('D4: RTBH costs only the target', () => {
|
|||
assert.deepEqual(g.errors, []);
|
||||
});
|
||||
|
||||
// ---------- Orbit ----------
|
||||
|
||||
// A Tier 1 one step from the win (as in tests/pie-in-the-sky.test.js).
|
||||
const pieT1 = (g) => {
|
||||
g.ev("S.cash=1e11;S.lvl=6;for(const x of GOALS)S.done[x.id]=0;delete S.done.t1;ACT.launchBB({city:'fra'});S.pops.fra.bb.d=500;S.transit=[];S.ixp={};S.peers={};S.pni=[];S.grace=null;S.nextFail=1e9;S.nextEvent=1e9");
|
||||
g.ev("for(const n of t1Need())S.pni.push({id:'p'+n.id,net:n.id,city:'fra',tier:2});compute();for(const n of NETS)if(!R.reachable[n.id]){if(!S.pops[n.pops[0]])S.pops[n.pops[0]]={day:0,bb:null,boost:0,down:0,routers:1,gen:false};S.pni.push({id:'i'+n.id,net:n.id,city:n.pops[0],tier:0});}compute()");
|
||||
};
|
||||
test('O1: the rocket company unlocks only on a Tier 1 win of its version, or in sandbox', () => {
|
||||
const g = load();
|
||||
g.ev("beginGame('Pie','fra',{mode:'normal',preset:'oncall'});if(UI.pendGame)ACT.pitchSkip()");
|
||||
assert.equal(g.ev('S.pieV'), 1, 'O1: newGame() sets pieV');
|
||||
pieT1(g);
|
||||
assert.equal(g.ev('pieOn()'), false, 'O1: locked before the win');
|
||||
g.ev('checkGoals()');
|
||||
assert.equal(g.ev('pieOn()&&pieCanBuild()'), true, 'O1: open on the win');
|
||||
g.ev("const o=JSON.parse(JSON.stringify(S));delete o.pieV;delete o.pie;S=migrate(o);compute();checkGoals()");
|
||||
assert.equal(g.ev('pieOn()'), false, 'O1: an old won save stays locked');
|
||||
g.ev("const o=JSON.parse(JSON.stringify(S));o.pieV=1;o.pie={};o.scn={id:'redsea'};S=migrate(o)");
|
||||
assert.equal(g.ev('pieOn()'), false, 'O1: never in a scenario');
|
||||
const sb = load();
|
||||
sb.ev("ACT.modeSet({m:'sandbox'});ACT.start({});if(UI.pendGame)ACT.pitchSkip()");
|
||||
assert.equal(sb.ev('S.day===0&&pieOn()&&pieCanBuild()'), true, 'O1: sandbox from day 0');
|
||||
const won = load();
|
||||
won.ev("beginGame('Pie','fra',{mode:'normal',preset:'oncall'});if(UI.pendGame)ACT.pitchSkip()");
|
||||
pieT1(won);
|
||||
won.ev("checkGoals();ACT.buildPop({city:'sin'});S.transit.push({id:'tt',city:'fra',net:'cog',tier:1,n:1,down:0});compute()");
|
||||
assert.equal(won.ev('pieCanBuild()'), false, 'O1: no longer Tier 1, nothing new');
|
||||
assert.deepEqual([...g.errors, ...sb.errors, ...won.errors], []);
|
||||
});
|
||||
|
||||
test('O5: launches fail only with chaos on, never in the first 90 days after the unlock', () => {
|
||||
const fly = (setup, after) => {
|
||||
const g = load();
|
||||
g.ev(setup);
|
||||
if (!g.ev('gatesOpen()')) { pieT1(g); g.ev('checkGoals()'); }
|
||||
g.ev("ACT.buildPop({city:'sin'});ACT.pieFound();ACT.pieFactory();ACT.piePad({city:'sin'});S.pie.stock=100");
|
||||
g.ev(`S.day=S.pie.born+${after};S.pie.pads[0].next=0;Math.random=()=>0;ACT.pieLaunch({rk:'falcon',cr:'short'});S.pie.q[0].day=S.day;pieDay(S.day)`);
|
||||
assert.deepEqual(g.errors, []);
|
||||
return g.ev("pieLive('short')");
|
||||
};
|
||||
const oncall = "beginGame('Pie','fra',{mode:'normal',preset:'oncall'});if(UI.pendGame)ACT.pitchSkip()";
|
||||
assert.equal(fly(oncall, 89), 20, 'O5: quiet for 90 days');
|
||||
assert.equal(fly(oncall, 90), 0, 'O5: then chaos can take a launch');
|
||||
assert.equal(fly("ACT.modeSet({m:'sandbox'});ACT.start({});if(UI.pendGame)ACT.pitchSkip()", 400), 20, 'O5: chaos none, nothing fails');
|
||||
});
|
||||
|
||||
test('O7: a fresh Tier 1 cannot afford a full Shortcrust in its first year', () => {
|
||||
// Reference: the big-network benchmark save, a won network far larger than a fresh Tier 1. A year of its profit at
|
||||
// today's revenue (costs ignored, so generously) plus the largest loan any bank offers (12x monthly revenue).
|
||||
const g = load();
|
||||
const save = fs.readFileSync(path.join(__dirname, 'fixtures', 'big-network.json'), 'utf8');
|
||||
g.ev(`S=migrate(JSON.parse(${JSON.stringify(save)}));compute()`);
|
||||
const rev = g.ev('R.revMo'), loan = g.ev('Math.max(...Object.values(BANKS).map(b=>b.amt[1]))') * rev, cash = Math.max(0, g.ev('S.cash'));
|
||||
const year = 12 * rev + loan + Math.min(cash, 12 * rev);
|
||||
const full = g.ev("pieFullCost('short')");
|
||||
assert.ok(full > 5e9, `O7: a full Shortcrust costs ${Math.round(full / 1e6)}M`);
|
||||
assert.ok(year < full, `O7: ${Math.round(year / 1e6)}M in a year buys a full Shortcrust (${Math.round(full / 1e6)}M); make orbit dearer`);
|
||||
assert.deepEqual(g.errors, []);
|
||||
});
|
||||
|
||||
test('no page errors while checking the rules', () => {
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
|
|
|||
272
tests/pie-in-the-sky.test.js
Normal file
272
tests/pie-in-the-sky.test.js
Normal file
|
|
@ -0,0 +1,272 @@
|
|||
// Pie in the Sky (docs/plans/pie-in-the-sky.md): the rocket-company endgame. Seeded; state is set directly where luck would decide.
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { load } = require('./harness');
|
||||
|
||||
// A transit-free network in Frankfurt with a PNI to every Tier 1 it needs (as in tier1-cone.test.js), one goal short of the win.
|
||||
const t1Club = (ev) => {
|
||||
ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();S.cash=1e11;S.lvl=6;for(const g of GOALS)S.done[g.id]=0;delete S.done.t1;ACT.launchBB({city:'fra'});S.pops.fra.bb.d=500");
|
||||
ev("S.transit=[];S.ixp={};S.peers={};S.pni=[];S.grace=null;for(const n of t1Need())S.pni.push({id:'p'+n.id,net:n.id,city:'fra',tier:2});S.nextFail=1e9;S.nextEvent=1e9;compute()");
|
||||
// and peer directly with the networks in nobody's cone (tier1-cone.test.js)
|
||||
ev("for(const n of NETS)if(!R.reachable[n.id]){if(!S.pops[n.pops[0]])S.pops[n.pops[0]]={day:0,bb:null,boost:0,down:0,routers:1,gen:false};S.pni.push({id:'i'+n.id,net:n.id,city:n.pops[0],tier:0});}compute()");
|
||||
};
|
||||
const won = (ev) => { t1Club(ev); ev('checkGoals()'); };
|
||||
// A company with a factory, a pad in Singapore (1.4°N) and pies on the shelf.
|
||||
const company = (ev) => ev("ACT.buildPop({city:'sin'});ACT.pieFound();ACT.pieFactory();ACT.piePad({city:'sin'});S.pie.stock=400");
|
||||
const sandbox = (ev) => ev("ACT.modeSet({m:'sandbox'});ACT.start({});if(UI.pendGame)ACT.pitchSkip()");
|
||||
|
||||
test('unlocks once, on the Tier 1 win, in a save of this version', () => {
|
||||
const { ev, errors } = load();
|
||||
t1Club(ev);
|
||||
assert.equal(ev('S.pieV'), 1);
|
||||
assert.equal(ev('S.pie'), null, 'locked before the win');
|
||||
assert.equal(ev('pieOn()'), false);
|
||||
ev('checkGoals()');
|
||||
assert.equal(ev('S.won'), true);
|
||||
assert.equal(ev('!!S.pie&&pieOn()&&pieCanBuild()'), true, 'unlocked on the transition');
|
||||
assert.ok(ev("S.log.some(e=>/Pie in the Sky is unlocked/.test(e.t))"), 'the player is told');
|
||||
const born = ev('S.pie.born');
|
||||
ev('S.day+=5;checkGoals();pieUnlock()');
|
||||
assert.equal(ev('S.pie.born'), born, 'only once');
|
||||
// reachable from the NOC tab
|
||||
ev("UI.started=true;UI.left='noc';UI.leftOpen=true;renderLeft()");
|
||||
assert.ok(ev("!!document.querySelector('[data-act=pieOpen]')"), 'the NOC tab has the Pie Control card');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('an old won save stays locked, and so do puzzles and scenarios', () => {
|
||||
const { ev, errors } = load();
|
||||
won(ev);
|
||||
ev("window.__old=JSON.parse(JSON.stringify(S));delete __old.pieV;delete __old.pie");
|
||||
ev('S=migrate(JSON.parse(JSON.stringify(__old)));compute();checkGoals()');
|
||||
assert.equal(ev('S.pieV'), 0, 'missing pieV loads as 0');
|
||||
assert.equal(ev('S.pie'), null);
|
||||
assert.equal(ev('pieOn()'), false, 'already won: never unlocks');
|
||||
// even a hand-made pie in an old save is dropped
|
||||
ev("__old.pie={co:{name:'x'}};S=migrate(JSON.parse(JSON.stringify(__old)))");
|
||||
assert.equal(ev('S.pie'), null);
|
||||
// a scenario save never has it
|
||||
ev("const o=JSON.parse(JSON.stringify(__old));o.pieV=1;o.pie={};o.scn={id:'redsea'};S=migrate(o)");
|
||||
assert.equal(ev('S.pie'), null);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('sandbox has it from day 0, at real prices, counting what it would have cost', () => {
|
||||
const { ev, errors } = load();
|
||||
sandbox(ev);
|
||||
assert.equal(ev('S.day'), 0);
|
||||
assert.equal(ev('pieOn()&&pieCanBuild()'), true);
|
||||
assert.equal(ev('S.pie'), null, 'created on the first action');
|
||||
const c0 = ev('S.cash');
|
||||
ev('ACT.pieFound()');
|
||||
assert.equal(ev('S.cash'), c0, 'no real money');
|
||||
assert.equal(ev('S.pie.book.wouldHave'), ev('piePrice(PIE_CO)'));
|
||||
assert.equal(ev('S.pie.book.spent'), 0);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('actions cost what they should', () => {
|
||||
const { ev, errors } = load();
|
||||
won(ev);
|
||||
ev("ACT.buildPop({city:'sin'})");
|
||||
const step = (code) => { const c = ev('S.cash'); ev(code); return Math.round(c - ev('S.cash')); };
|
||||
assert.equal(step('ACT.pieFound()'), ev('piePrice(PIE_CO)'));
|
||||
assert.equal(ev('S.pie.co.name'), 'pie.co_mid_life_crisis_aerospace', 'the default name, kept as a label');
|
||||
assert.equal(step('ACT.pieFactory()'), ev('piePrice(PIE_FAC)'));
|
||||
assert.equal(step("ACT.piePad({city:'sin'})"), ev('piePrice(PIE_PAD)'));
|
||||
assert.equal(step("ACT.piePad({city:'fra'})"), 0, 'Frankfurt is not on the coast');
|
||||
assert.equal(step("ACT.pieRd({k:'reuse'})"), ev('piePrice(PIE_REUSE)'));
|
||||
assert.equal(step("ACT.pieDish({city:'fra'})"), ev('piePrice(PIE_DISH+PIE_ANT)'));
|
||||
const id = ev('S.pie.dishes[0].id');
|
||||
assert.equal(step(`ACT.pieAnt({id:'${id}'})`), ev('piePrice(PIE_ANT)'));
|
||||
assert.equal(step("ACT.pieLic({cc:'DE'})"), ev("pieLicPrice('DE')"));
|
||||
assert.ok(ev("pieLicPrice('US')") > ev("pieLicPrice('LU')"), 'big markets cost more');
|
||||
assert.ok(ev("pieLicPrice('US')") <= 200e6 && ev("pieLicPrice('MH')") >= 10e6);
|
||||
assert.equal(ev("pieLicOk('DE')&&pieDishes().length"), 1, 'a licensed dish is live');
|
||||
// a launch: rocket with the equatorial discount, 20 pies, the party later
|
||||
ev('S.pie.stock=100');
|
||||
const want = ev("Math.round(piePrice(60e6)*(1-pieEq('sin'))+20*piePrice(PIE_PIE))");
|
||||
assert.equal(step("ACT.pieLaunch({rk:'falcon',cr:'short'})"), want);
|
||||
assert.ok(ev("pieEq('sin')") > 0.14 && ev("pieEq('lon')") === 0, 'near the equator is cheaper');
|
||||
assert.equal(ev('S.pie.stock'), 80, 'pies come off the shelf');
|
||||
// the pad is busy: the next launch waits for it
|
||||
ev("ACT.pieLaunch({rk:'falcon',cr:'short'})");
|
||||
assert.ok(ev('S.pie.q[1].day') >= ev('S.pie.q[0].day') + ev('leadDays(ROCKETS.falcon.gap)'), 'pad cadence');
|
||||
// insurance adds 8%
|
||||
ev('UI.pieIns=true');
|
||||
const q = JSON.parse(ev("JSON.stringify(pieQuote('falcon','short',{ins:true}))"));
|
||||
assert.equal(q.cost - q.insured, Math.round(q.insured * 0.08));
|
||||
// running costs show up in the monthly bill
|
||||
ev('compute()');
|
||||
assert.equal(ev('R.cost.pie'), ev('PIE_CO_MO+PIE_FAC_MO+PIE_PAD_MO+PIE_DISH_MO'));
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('launches fill crusts, the party is billed, heavy test flights explode', () => {
|
||||
const { ev, errors } = load();
|
||||
won(ev);
|
||||
company(ev);
|
||||
ev("ACT.pieLaunch({rk:'falcon',cr:'short'})");
|
||||
const due = ev('S.pie.q[0].day');
|
||||
const spent = ev('S.pie.book.spent');
|
||||
ev(`while(S.day<${due})dayTick()`);
|
||||
assert.equal(ev('S.pie.q.length'), 0);
|
||||
assert.equal(ev("pieLive('short')"), 20, 'the pies are up (no failures in the first 90 days)');
|
||||
assert.ok(ev('S.pie.book.spent') - spent >= 2e6, 'the launch party is billed');
|
||||
assert.ok(ev('S.pie.founder.posts.length') >= 1);
|
||||
// the heavy rocket's first three flights carry nothing and explode
|
||||
ev("ACT.pieRd({k:'heavy'})");
|
||||
for (let i = 0; i < 3; i++) { ev("S.pie.pads[0].next=S.day;ACT.pieLaunch({rk:'heavy',cr:'short'})"); }
|
||||
assert.equal(ev('S.pie.q.filter(L=>L.test).length'), 3);
|
||||
ev("S.pie.pads[0].next=S.day;ACT.pieLaunch({rk:'heavy',cr:'short'})");
|
||||
assert.equal(ev('S.pie.q.filter(L=>L.test).length'), 3, 'the fourth is a real one');
|
||||
assert.equal(ev('S.pie.q[3].n'), 100);
|
||||
ev('for(let i=0;i<60;i++)dayTick()');
|
||||
assert.equal(ev('S.pie.rd.heavyTests'), 3);
|
||||
assert.equal(ev("pieLive('short')"), 120);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('O5: launches only fail with chaos on, and never in the first 90 days', () => {
|
||||
const run = (after) => {
|
||||
const { ev } = load();
|
||||
won(ev); company(ev);
|
||||
ev(`S.day=S.pie.born+${after};Math.random=()=>0`); // the unluckiest dice there are
|
||||
ev("ACT.pieLaunch({rk:'falcon',cr:'short'});S.pie.q[0].day=S.day;pieDay(S.day)");
|
||||
return ev("pieLive('short')");
|
||||
};
|
||||
assert.equal(run(10), 20, 'quiet days');
|
||||
assert.equal(run(120), 0, 'chaos can lose a launch');
|
||||
const { ev } = load();
|
||||
sandbox(ev);
|
||||
company(ev);
|
||||
ev("S.day=500;S.pie.pads[0].next=0;Math.random=()=>0;ACT.pieLaunch({rk:'falcon',cr:'short'});S.pie.q[0].day=S.day;pieDay(S.day)");
|
||||
assert.equal(ev("pieLive('short')"), 20, 'chaos none: nothing fails');
|
||||
});
|
||||
|
||||
test('cohorts decay past their life, and a crust is half-baked under 60%', () => {
|
||||
const { ev, errors } = load();
|
||||
won(ev);
|
||||
company(ev);
|
||||
ev("S.pie.crusts.short.cohorts.push({n:900,day:S.day,las:false})");
|
||||
assert.equal(ev("pieBaked('short')"), false, `${ev("pct(pieCov('short'))")} is half-baked`);
|
||||
ev("S.pie.crusts.short.cohorts.push({n:60,day:S.day,las:true})");
|
||||
assert.equal(ev("pieBaked('short')&&pieUp('short')"), true, '60% bakes it');
|
||||
assert.deepEqual(JSON.parse(ev('JSON.stringify(pieHubs())')), ['short']);
|
||||
ev('S.pie.safe=true');
|
||||
assert.equal(ev("pieUp('short')"), false, 'safe mode parks it');
|
||||
ev('S.pie.safe=false;pieDay(S.day)');
|
||||
assert.equal(ev('S.pie.crusts.short.bk'), 1);
|
||||
const g = JSON.parse(ev('JSON.stringify(pieGlobeData())'));
|
||||
assert.equal(g.crusts.find((c) => c.id === 'short').n, 960);
|
||||
assert.equal(g.crusts.find((c) => c.id === 'short').las, 60);
|
||||
assert.equal(g.pads[0].city, 'sin');
|
||||
ev("S.day+=CRUSTS.short.life;pieDay(S.day)");
|
||||
assert.equal(ev("pieLive('short')"), 0, 'old pies deorbit');
|
||||
assert.equal(ev('S.pie.crusts.short.cohorts.length'), 0);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('promises slip a year and get broken', () => {
|
||||
const { ev, errors } = load();
|
||||
won(ev);
|
||||
company(ev);
|
||||
assert.equal(ev('S.pie.founder.promises'), 1);
|
||||
ev('for(let i=0;i<361;i++)dayTick()');
|
||||
assert.equal(ev('S.pie.founder.broken'), 1);
|
||||
assert.ok(ev("S.pie.founder.posts.some(p=>p.k==='pie.fp_slip')"));
|
||||
assert.match(ev('pieFpText(S.pie.founder.posts[0])'), /\w/);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('sanitize repairs a hand-broken S.pie', () => {
|
||||
const { ev, errors } = load();
|
||||
won(ev);
|
||||
company(ev);
|
||||
ev("S.pie.crusts.bogus={cohorts:[{n:5,day:0}]};S.pie.crusts.short.cohorts=[{n:'lots',day:-5},{n:1e9,day:S.day},null,{n:20,day:S.day,las:1}]");
|
||||
ev("S.pie.pads.push({city:'atlantis'},{city:'fra',next:'soon'},{city:'sin'},'x');S.pie.dishes=[{city:'fra',ant:999},{city:'fra',ant:2},{city:'ber'},{city:'zzz'}]");
|
||||
ev("S.pie.q=[{rk:'warp',cr:'short',pad:'sin'},{rk:'heavy',cr:'short',pad:'sin'},{rk:'falcon',cr:'nope',pad:'sin'},{rk:'falcon',cr:'short',pad:'sin',n:9999,day:'x'}]");
|
||||
ev("S.pie.lic={DE:{state:'ok',until:1e12},XX:{state:'ok'},FR:{state:'weird'}};S.pie.founder.posts=[{k:'evil.label',d:0},{k:'pie.fp_launch',n:-4,c:'hack'}];S.pie.book={spent:NaN,earned:'1'};S.pie.co={name:' My Rockets '}");
|
||||
ev("S.pie.spat={nothing:{until:9}};S.pie.stock=1e9;S.pie.rd={heavyTests:99}");
|
||||
ev('S=migrate(JSON.parse(JSON.stringify(S)));compute()');
|
||||
const P = JSON.parse(ev('JSON.stringify(S.pie)'));
|
||||
assert.deepEqual(Object.keys(P.crusts).sort(), ['flaky', 'frozen', 'short', 'upper']);
|
||||
assert.ok(P.crusts.short.cohorts.every((k) => Number.isInteger(k.n) && k.n <= 3168 && k.n >= 1));
|
||||
assert.deepEqual(P.pads.map((p) => p.city), ['sin'], 'only pads at your coastal POPs');
|
||||
assert.deepEqual(P.dishes.map((d) => [d.city, d.ant]), [['fra', 16]], 'one dish per POP city, antennas capped');
|
||||
assert.deepEqual(P.q.map((L) => [L.rk, L.n]), [['falcon', 20]], 'no unknown rockets or crusts, no heavy without its research');
|
||||
assert.equal(P.lic.DE.until <= ev('S.day') + 3600, true);
|
||||
assert.equal(P.lic.XX, undefined);
|
||||
assert.equal(P.lic.FR.state, 'ok');
|
||||
assert.deepEqual(P.founder.posts.map((p) => p.k), ['pie.fp_launch']);
|
||||
assert.equal(P.founder.posts[0].c, undefined);
|
||||
assert.equal(P.book.spent, 0);
|
||||
assert.equal(P.co.name, 'My Rockets');
|
||||
assert.deepEqual(P.spat, {});
|
||||
assert.equal(P.stock, 480);
|
||||
assert.equal(P.rd.heavyTests, 0, 'no tests without the research');
|
||||
assert.equal(P.crusts.short.queued, 20);
|
||||
// a save from this version without a company loads too, and garbage becomes nothing
|
||||
ev("S.pie='pie';S=migrate(JSON.parse(JSON.stringify(S)))");
|
||||
assert.equal(ev('S.pie'), null);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('losing Tier 1 blocks new building, keeps what flies, and earns the Listening Tour', () => {
|
||||
const { ev, errors } = load();
|
||||
won(ev);
|
||||
company(ev);
|
||||
ev("ACT.pieLaunch({rk:'falcon',cr:'short'});dayTick()");
|
||||
ev("S.transit.push({id:'tt',city:'fra',net:'cog',tier:1,n:1,down:0});compute()");
|
||||
assert.equal(ev('pieCanBuild()'), false);
|
||||
const c = ev('S.cash');
|
||||
ev("ACT.piePad({city:'sin'});ACT.pieDish({city:'sin'});ACT.pieLaunch({rk:'falcon',cr:'short'});ACT.pieRd({k:'heavy'})");
|
||||
assert.equal(ev('S.cash'), c, 'nothing new');
|
||||
assert.equal(ev('S.pie.q.length'), 1, 'the queued launch stays');
|
||||
ev('dayTick()');
|
||||
assert.equal(ev('S.stats.pieTour'), 1);
|
||||
ev('checkBadges()');
|
||||
assert.ok(ev("S.ach.tour!==undefined"), 'Listening Tour');
|
||||
ev('for(let i=0;i<20;i++)dayTick()');
|
||||
assert.equal(ev("pieLive('short')"), 20, 'it still flies');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('Burned a Billion and Fully Baked', () => {
|
||||
const { ev, errors } = load();
|
||||
won(ev);
|
||||
company(ev);
|
||||
ev('checkBadges()');
|
||||
assert.ok(ev("S.ach.billion!==undefined"), 'a company, a factory and a pad cost over a billion');
|
||||
ev("S.pie.crusts.frozen.cohorts.push({n:520,day:S.day,las:false});checkBadges()");
|
||||
assert.ok(ev("S.ach.baked!==undefined"));
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('saves without a rocket company pay nothing', () => {
|
||||
const { ev, errors } = load();
|
||||
ev("ACT.start({});if(UI.pendGame)ACT.pitchSkip();compute()");
|
||||
assert.equal(ev('R.cost.pie'), undefined);
|
||||
assert.equal(ev("pieDay(S.day)"), undefined);
|
||||
assert.equal(ev('pieDishes().length+pieHubs().length'), 0);
|
||||
assert.deepEqual(JSON.parse(ev('JSON.stringify(pieGlobeData())')), { crusts: [], dishes: [], pads: [], launches: [] });
|
||||
assert.equal(ev("pieCard()"), '', 'no card while locked');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('Pie Control renders every tab on a phone', () => {
|
||||
const { dom, ev, errors } = load();
|
||||
ev('window.innerWidth=360');
|
||||
won(ev);
|
||||
company(ev);
|
||||
for (const t of ['co', 'fly', 'dish', 'book']) {
|
||||
ev(`ACT.pieTab({t:'${t}'})`);
|
||||
assert.equal(ev("$('modal').hidden"), false);
|
||||
assert.ok(dom.window.document.querySelectorAll('#modalCard [data-act]').length > 2, t);
|
||||
}
|
||||
ev("ACT.pieTab({t:'co'});ACT.pieName()");
|
||||
assert.equal(ev('S.pie.co.name'), 'pie.co_hubris_heavy_industries');
|
||||
ev("$('pieNm').value='Rocket Pie Co';ACT.pieRename()");
|
||||
assert.equal(ev('pieCoName()'), 'Rocket Pie Co');
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue