import assert from 'node:assert/strict'; import { test } from 'node:test'; import { rollOdds, winChance } from '../src/odds.ts'; test('equal Cores are a coin flip and odds are complementary', () => { for (let a = 1; a <= 8; a++) { assert.ok(Math.abs(winChance(a, a) - 0.5) < 1e-12); for (let d = 1; d <= 8; d++) assert.ok(Math.abs(winChance(a, d) + winChance(d, a) - 1) < 1e-12); } }); test('matches the table in rules.md', () => { assert.equal(Math.round(100 * winChance(2, 1)), 90); assert.equal(Math.round(100 * winChance(3, 4)), 21); assert.equal(Math.round(100 * winChance(2, 4)), 4); assert.equal(Math.round(100 * winChance(6, 4)), 91); assert.equal(Math.round(100 * winChance(8, 7)), 71); }); test('one-roll odds add up, agree with winChance, and 1 Core vs 1 Core deals 35/36 damage on average', () => { for (let a = 1; a <= 6; a++) { for (let d = 1; d <= 6; d++) { const o = rollOdds(a, d); assert.ok(Math.abs(o.win + o.tie + o.lose - 1) < 1e-12); assert.ok(Math.abs(o.win / (o.win + o.lose) - winChance(a, d)) < 1e-12); } } const one = rollOdds(1, 1); assert.ok(Math.abs(one.tie - 1 / 6) < 1e-12); assert.ok(Math.abs(one.damageDealt - 35 / 36) < 1e-12); assert.ok(Math.abs(one.damageDealt - one.damageTaken) < 1e-12); });