import assert from 'node:assert/strict'; import { readdirSync, readFileSync } from 'node:fs'; import { test } from 'node:test'; import { loadCards } from '../src/load.ts'; import { randomDeck, validateDeck } from '../src/deck.ts'; import { makeRng } from '../src/rng.ts'; import { DEFAULT_RULES } from '../src/rules.ts'; import { staleScripts } from '../src/scripts.ts'; const pool = loadCards(); test('cards.csv loads every playable card', () => { const count = (kind: string) => pool.all.filter((c) => c.kind === kind).length; assert.equal(count('anomaly'), 8); assert.equal(count('server'), 13); assert.equal(count('program'), 28); assert.equal(count('hardware'), 16); assert.equal(count('execution'), 18); assert.equal(pool.byName.get('Broken Bits')?.cores, 4); assert.equal(pool.byName.get('Carbon NanoBots')?.slots, 4); assert.equal(pool.byName.get('Quantum Coprocessor')?.bandwidth, 9); }); test('every card has a script written for its current text', () => { assert.deepEqual(staleScripts(pool), []); }); test('every card has its own test', () => { const dir = new URL('.', import.meta.url); const tested = new Set(); for (const file of readdirSync(dir).filter((f) => f.endsWith('.test.ts'))) { for (const m of readFileSync(new URL(file, dir), 'utf8').matchAll(/\bcard\('([^']+)'/g)) tested.add(m[1]); } assert.deepEqual(pool.all.map((c) => c.name).filter((n) => !tested.has(n)), []); }); test('set 2 loads on request, is well formed, and is unscripted', () => { const two = loadCards(undefined, [2]); const count = (kind: string) => two.all.filter((c) => c.kind === kind).length; assert.equal(count('anomaly'), 12); assert.equal(count('server'), 7); assert.equal(count('program'), 17); assert.equal(count('hardware'), 8); assert.equal(count('execution'), 8); for (const c of two.all) { assert.equal(c.set, 2, c.name); assert.ok(!pool.byName.has(c.name), `${c.name} clashes with a set 1 card`); assert.ok(c.text || c.ability, `${c.name} has text`); if (c.kind === 'anomaly') { assert.equal(c.cores + c.slots, 6, `${c.name}: Cores + Slots = 6`); assert.equal(c.health, { 4: 9, 3: 10, 2: 12 }[c.cores], `${c.name}: Health by Cores`); assert.ok(c.type && c.ability && c.ability.cost >= 3 && c.ability.cost <= 5, `${c.name}: typed, Ability 3-5 Gb`); } else if (c.kind === 'program') { assert.ok(c.type && c.bandwidth >= 4 && c.bandwidth <= 6, `${c.name}: typed, 4-6 Gb`); } else if (c.kind === 'execution') { assert.ok(c.bandwidth >= 3 && c.bandwidth <= 5, `${c.name}: 3-5 Gb`); } else if (c.kind === 'hardware') { assert.ok(c.bandwidth >= 4 && c.bandwidth <= 7, `${c.name}: 4-7 Gb`); } } const all = loadCards(undefined, 'all'); assert.equal(all.all.length, pool.all.length + two.all.length); const warnings = staleScripts(all); assert.equal(warnings.length, two.all.length, 'one warning per set 2 card'); assert.ok(warnings.every((w) => w.endsWith('no script yet')), 'the only warnings are missing scripts'); }); test('random decks are legal', () => { const rng = makeRng(3); for (let i = 0; i < 50; i++) { assert.deepEqual(validateDeck(pool, randomDeck(pool, rng, DEFAULT_RULES), DEFAULT_RULES), []); } }); test('deck validation catches size, kind and copy problems', () => { const deck = randomDeck(pool, makeRng(1), DEFAULT_RULES); deck.main[0] = deck.main[1] = deck.main[2] = 'Execute: Fork'; deck.servers.pop(); deck.anomalies[0] = 'Cloud Compute'; const errors = validateDeck(pool, deck, DEFAULT_RULES).join('\n'); assert.match(errors, /Servers: 19 cards/); assert.match(errors, /"Cloud Compute" is a server/); assert.match(errors, /copies of "Execute: Fork"/); });