/** * @file Valide la table des éléments Aniimo et les calculs directionnels simples et doubles. */ import { readFile, access } from "node:fs/promises"; import { test } from "node:test"; import assert from "node:assert/strict"; import { calculateElementMatchups } from "../website/src/features/games/aniimo/elementMatchups.js"; const readJson = async (file) => JSON.parse(await readFile(`website/public/data/aniimo/${file}`, "utf8")); const chart = await readJson("elements.json"); test("element chart covers every catalogue element, translation and icon without implicit neutral cells", async () => { const catalogue = await readJson("aniimos.json"); const elements = [...new Set(catalogue.flatMap((aniimo) => aniimo.variations.flatMap((variant) => variant.elements)))].sort(); assert.deepEqual([...chart.elements].sort(), elements); assert.equal(chart.elements.length, 9); assert.deepEqual(Object.keys(chart.matchups).sort(), elements); assert.equal(chart.dualDefenseRule, "multiply"); assert.equal(new URL(chart.source.url).protocol, "https:"); assert.match(chart.source.checkedOn, /^\d{4}-\d{2}-\d{2}$/); for (const language of ["fr", "en"]) { const dictionary = await readJson(`i18n/${language}.json`); for (const element of elements) assert.ok(dictionary[element]?.trim()); } for (const element of elements) { await access(`website/public/static/img/aniimo/${element}.webp`); assert.deepEqual(Object.keys(chart.matchups[element]).sort(), elements); assert.ok(Object.values(chart.matchups[element]).every((value) => [0.625, 1, 1.6].includes(value))); } }); const row = (selected, element) => calculateElementMatchups(chart, selected).find((result) => result.element === element); test("single elements preserve directional matchups and Dark's neutral mirror", () => { assert.equal(row(["electric"], "water").attack[0].multiplier, 1.6); assert.equal(row(["electric"], "water").defense, 1); assert.equal(row(["dark"], "dark").defense, 1); assert.equal(row(["fire"], "fire").defense, 0.625); }); test("dual defense combines weaknesses, resistances and cancellation without floating point noise", () => { assert.equal(row(["dark", "grass"], "wind").defense, 2.56); assert.equal(row(["fire", "rock"], "ice").defense, 0.390625); assert.equal(row(["water", "ice"], "fire").defense, 1); assert.equal(row(["water", "ice"], "grass").defense, 1.6); assert.equal(row(["water", "ice"], "dark").defense, 0.625); assert.deepEqual(row(["ice", "water"], "fire").defense, row(["water", "ice"], "fire").defense); }); test("dual offense keeps each skill's element separate instead of multiplying them", () => { assert.deepEqual(row(["water", "ice"], "fire").attack, [ { element: "water", multiplier: 1.6 }, { element: "ice", multiplier: 0.625 } ]); }); test("empty and invalid selections cannot produce misleading multipliers", () => { assert.equal(calculateElementMatchups(chart, []), null); assert.deepEqual(calculateElementMatchups(chart, ["fire", "fire"]), calculateElementMatchups(chart, ["fire"])); assert.throws(() => calculateElementMatchups(chart, ["unknown"]), RangeError); assert.throws(() => calculateElementMatchups(chart, ["fire", "water", "ice"]), RangeError); });