chore: establish formatting baseline and verification scripts
This commit is contained in:
+46
-32
@@ -1,41 +1,55 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {awardsFor, rankFor, completeMissions, activeMission, POINTS, RANKS} from '../src/scoring.js';
|
||||
import {createState, purchase} from '../src/game-state.js';
|
||||
import {machineById} from '../src/locations.js';
|
||||
import {
|
||||
awardsFor,
|
||||
rankFor,
|
||||
completeMissions,
|
||||
activeMission,
|
||||
POINTS,
|
||||
RANKS,
|
||||
} from '../src/scoring.js';
|
||||
import { createState, purchase } from '../src/game-state.js';
|
||||
import { machineById } from '../src/locations.js';
|
||||
|
||||
const total = awards => awards.reduce((s, a) => s + a.points, 0);
|
||||
const total = (awards) => awards.reduce((s, a) => s + a.points, 0);
|
||||
|
||||
test('Discovery, combo and all-category bonuses are paid once', () => {
|
||||
const state = createState(), park = machineById('mellat-park');
|
||||
const buy = (machine, product) => {
|
||||
const before = state.purchases.slice();
|
||||
return awardsFor(before, purchase(state, machine, product));
|
||||
};
|
||||
assert.equal(total(buy(park, 'water')), POINTS.purchase + POINTS.discovery);
|
||||
assert.equal(total(buy(park, 'juice')), POINTS.purchase, 'same type: no combo');
|
||||
assert.equal(total(buy(park, 'cake')), POINTS.purchase + POINTS.combo);
|
||||
assert.equal(total(buy(park, 'water')), POINTS.purchase, 'combo only once');
|
||||
buy(machineById('factory'), 'water');
|
||||
buy(machineById('school-rahil'), 'water');
|
||||
buy(machineById('ferdowsi-university'), 'water');
|
||||
buy(machineById('azadi-metro'), 'water');
|
||||
state.minutes = 11 * 60;
|
||||
const last = buy(machineById('mashhad-mall'), 'water');
|
||||
assert.ok(last.some(a => a.points === POINTS.allCategories));
|
||||
const state = createState(),
|
||||
park = machineById('mellat-park');
|
||||
const buy = (machine, product) => {
|
||||
const before = state.purchases.slice();
|
||||
return awardsFor(before, purchase(state, machine, product));
|
||||
};
|
||||
assert.equal(total(buy(park, 'water')), POINTS.purchase + POINTS.discovery);
|
||||
assert.equal(total(buy(park, 'juice')), POINTS.purchase, 'same type: no combo');
|
||||
assert.equal(total(buy(park, 'cake')), POINTS.purchase + POINTS.combo);
|
||||
assert.equal(total(buy(park, 'water')), POINTS.purchase, 'combo only once');
|
||||
buy(machineById('factory'), 'water');
|
||||
buy(machineById('school-rahil'), 'water');
|
||||
buy(machineById('ferdowsi-university'), 'water');
|
||||
buy(machineById('azadi-metro'), 'water');
|
||||
state.minutes = 11 * 60;
|
||||
const last = buy(machineById('mashhad-mall'), 'water');
|
||||
assert.ok(last.some((a) => a.points === POINTS.allCategories));
|
||||
});
|
||||
|
||||
test('Ranks and missions advance with progress', () => {
|
||||
assert.equal(rankFor(0).name, RANKS[0].name);
|
||||
assert.equal(rankFor(RANKS[1].xp).index, 1);
|
||||
assert.equal(rankFor(1e6).progress, 1);
|
||||
const state = createState();
|
||||
assert.equal(activeMission(state).id, 'factory');
|
||||
purchase(state, machineById('factory'), 'water');
|
||||
assert.deepEqual(completeMissions(state).map(m => m.id), ['factory']);
|
||||
assert.equal(state.balance, 500 - 8 + 20, 'factory sells at half price');
|
||||
purchase(state, machineById('mellat-park'), 'water');
|
||||
assert.deepEqual(completeMissions(state).map(m => m.id), ['first']);
|
||||
assert.deepEqual(completeMissions(state), [], 'rewards are not repeated');
|
||||
assert.equal(activeMission(state).id, 'school');
|
||||
assert.equal(rankFor(0).name, RANKS[0].name);
|
||||
assert.equal(rankFor(RANKS[1].xp).index, 1);
|
||||
assert.equal(rankFor(1e6).progress, 1);
|
||||
const state = createState();
|
||||
assert.equal(activeMission(state).id, 'factory');
|
||||
purchase(state, machineById('factory'), 'water');
|
||||
assert.deepEqual(
|
||||
completeMissions(state).map((m) => m.id),
|
||||
['factory'],
|
||||
);
|
||||
assert.equal(state.balance, 500 - 8 + 20, 'factory sells at half price');
|
||||
purchase(state, machineById('mellat-park'), 'water');
|
||||
assert.deepEqual(
|
||||
completeMissions(state).map((m) => m.id),
|
||||
['first'],
|
||||
);
|
||||
assert.deepEqual(completeMissions(state), [], 'rewards are not repeated');
|
||||
assert.equal(activeMission(state).id, 'school');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user