forked from WikiDeck/wikideck
53 lines
2.8 KiB
TypeScript
53 lines
2.8 KiB
TypeScript
// DESIGN §2.1 starter decks (PR #18). Owner: engine-b.
|
|
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {
|
|
DEFAULT_DERIVATION, DEFAULT_RULESET, FACTION_KEYWORD, STARTER_DECKS, createMatch, starterDeckById, validateDeck,
|
|
} from '../shared/game/index.ts';
|
|
|
|
const countBy = (keys: string[]) => keys.reduce<Record<string, number>>((m, k) => ({ ...m, [k]: (m[k] ?? 0) + 1 }), {});
|
|
|
|
test('four starter decks, each with the frozen curve, 6+6 factions and 4 cards per home stat', () => {
|
|
assert.deepEqual(STARTER_DECKS.map(d => d.id), ['stargazers', 'field-guide', 'headliners', 'pioneers']);
|
|
for (const def of STARTER_DECKS) {
|
|
const deck = starterDeckById(def.id);
|
|
assert.deepEqual(deck.map(c => c.cost), [1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6], def.id);
|
|
const factions = Object.values(countBy(deck.map(c => c.faction)));
|
|
assert.deepEqual(factions, [6, 6], `${def.id} factions`);
|
|
const homes = Object.values(countBy(deck.map(c => c.home)));
|
|
assert.deepEqual(homes, [4, 4, 4], `${def.id} homes`);
|
|
}
|
|
});
|
|
|
|
test('starter cards follow §10.1 and the power curve like owned cards', () => {
|
|
for (const def of STARTER_DECKS) for (const card of starterDeckById(def.id)) {
|
|
assert.equal(card.source, 'loaner');
|
|
assert.equal(card.rarity, 'Common');
|
|
assert.equal(card.trend, 0);
|
|
assert.match(card.cardId, /^loaner:[a-z0-9-]+$/);
|
|
if (card.cost === 1) assert.deepEqual([card.keyword, card.power], [null, 2]);
|
|
else assert.deepEqual([card.keyword, card.power], [FACTION_KEYWORD[card.faction], DEFAULT_DERIVATION.powerByCost[card.cost]]);
|
|
}
|
|
});
|
|
|
|
test('all 6 factions and all 4 shared/catalog.ts cards (with real pageIds) are covered', () => {
|
|
const all = STARTER_DECKS.flatMap(d => starterDeckById(d.id));
|
|
assert.equal(new Set(all.map(c => c.faction)).size, 6);
|
|
const ids = Object.fromEntries(all.map(c => [c.title, c.pageId]));
|
|
assert.deepEqual([ids.Moon, ids['Periodic table'], ids.Octopus, ids['Albert Einstein']], [19331, 23053, 22780, 736]);
|
|
for (const c of all) if (!['Moon', 'Periodic table', 'Octopus', 'Albert Einstein'].includes(c.title)) assert.equal(c.pageId, null, c.title);
|
|
});
|
|
|
|
test('every starter deck passes engine deck validation and starts a match against every other', () => {
|
|
for (const a of STARTER_DECKS) {
|
|
assert.deepEqual(validateDeck(DEFAULT_RULESET, starterDeckById(a.id)), [], a.id);
|
|
for (const b of STARTER_DECKS) assert.doesNotThrow(() => createMatch(DEFAULT_RULESET, [starterDeckById(a.id), starterDeckById(b.id)], 1));
|
|
}
|
|
});
|
|
|
|
test('modes changing the curve change loaners too; unknown ids are rejected', () => {
|
|
const flat = starterDeckById('pioneers', { ...DEFAULT_DERIVATION, powerByCost: [0, 3, 3, 3, 3, 3, 3], vanillaBonus: 0 });
|
|
assert.ok(flat.every(c => c.power === 3));
|
|
assert.throws(() => starterDeckById('nope'), RangeError);
|
|
});
|