import { Asphodice } from "../asphodice"; import { Outcomes } from "../asphodice"; import { expect } from 'chai'; import 'mocha'; let asphodice = new Asphodice; interface TestCandidate { dice: Array; aboveCutOff?: boolean; belowCutOff?: boolean; reroll?: boolean; cancelled?: Array; outcomeBalance?: number, outcome?: Outcomes, } const testCandidates: Array = [ { dice: [ 6, 6, 6 ], aboveCutOff: true, belowCutOff: false, reroll: false, cancelled: [6,6,6], outcome: Outcomes.Success, outcomeBalance: 3 }, { dice: [ 2, 2, 2 ], aboveCutOff: false, belowCutOff: true, reroll: false, cancelled: [2,2,2], outcome: Outcomes.Fail, outcomeBalance: -3 }, { dice: [ 1 ], aboveCutOff: false, belowCutOff: true, reroll: false, cancelled: [1], outcomeBalance: -1 }, // TODO: temporary behaviour until we handle crits { dice: [ 10 ], aboveCutOff: true, belowCutOff: false, reroll: false, cancelled: [10], outcomeBalance: 1 },// TODO: temporary behaviour until we handle crits { dice: [ 6, 10, 6, 9 ], aboveCutOff: true, belowCutOff: false, reroll: false, cancelled: [6, 10, 6, 9], outcomeBalance: 4 }, { dice: [ 4, 1, 6, 9 ], aboveCutOff: false, belowCutOff: false, reroll: true, cancelled: [4, 1, 6, 9], outcomeBalance: 0 }, { dice: [ 10, 10, 1, 1, 1, 6], reroll: true, cancelled: [1,6], outcomeBalance: 0 }, { dice: [ 10, 10, 1, 1, 1, 2], reroll: false, cancelled: [1,2], outcomeBalance: -2}, { dice: [ 10, 1, 2], reroll: false, cancelled: [2], outcome: Outcomes.Success, outcomeBalance: -1 }, ]; describe("allAboveCutOff() says are all above cutoff correctly", function() { testCandidates.filter(candidate => candidate.aboveCutOff !== undefined) .forEach( ({dice, aboveCutOff}) => { it(`allAboveCutOff() says ${dice} → ${aboveCutOff}`, function() { const result = asphodice.allAboveCutOff(dice); expect(result).to.equal(aboveCutOff); }); }); }); describe("allBelowCutOff() says are all above cutoff correctly", function() { testCandidates.filter(candidate => candidate.belowCutOff !== undefined) .forEach( ({dice, belowCutOff}) => { it(`allBelowAboveCutOff() says ${dice} → ${belowCutOff}`, function() { const result = asphodice.allBelowCutOff(dice); expect(result).to.equal(belowCutOff); }); }); }); // TODO: single dice behaviour describe("rerollNeeded() determines re-roll correctly", function() { testCandidates.filter(candidate => candidate.reroll!== undefined) .forEach( ({dice, reroll}) => { it(`rerollNeeded() says ${dice} → ${reroll}`, function() { const result = asphodice.rerollNeeded(dice); expect(result).to.equal(reroll); }); }); }); describe("cancelRerollDice() filters correctly", function() { const tests = [ { dice: [ 6, 6, 6 ], out: [6,6,6] }, { dice: [ 2, 2, 2 ], out: [2,2,2] }, { dice: [ 6, 10, 6, 9 ], out: [6, 10, 6, 9] }, { dice: [ 6, 1, 6, 9 ], out: [ 6, 1, 6, 9 ] }, { dice: [ 10, 1, 2], out: [2] }, { dice: [ 10, 10, 1, 1, 1, 6], out: [1,6] }, { dice: [ 10, 10, 1, 1, 1, 2], out: [1,2] }, ]; tests.forEach(({dice, out}) => { it(`correctly filters ${dice} to ${out}`, function () { const result = asphodice.cancelRerollDice(dice); expect(result.sort()).to.deep.equal(out.sort()); }); }); testCandidates.filter(candidate => candidate.cancelled!== undefined) .forEach( ({dice, cancelled}) => { it(`cancelRerollDice() says ${dice} → ${cancelled}`, function() { const result = asphodice.cancelRerollDice(dice).sort(); cancelled?.sort(); expect(result).to.deep.equal(cancelled); }); }); }); describe("countOutComeBalance() gets the right total", function() { testCandidates.filter(candidate => candidate.outcomeBalance!== undefined) .forEach( ({dice, outcomeBalance}) => { it(`countOutcomeBalance() says ${dice} → ${outcomeBalance}`, function() { const result = asphodice.countOutcomeBalance(dice); expect(result).to.equal(outcomeBalance); }); }); }); describe("checkOutcome() gets the right outcome", function() { testCandidates.filter(candidate => candidate.outcome!== undefined) .forEach( ({dice, outcome}) => { it(`checkOutcome() says ${dice} → ${outcome}`, function() { const result = asphodice.checkOutcome(dice); expect(result).to.equal(outcome); }); }); });