|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- import { Asphodice } from "../dice";
- import { Outcomes } from "../dice";
- import { expect } from 'chai';
- import 'mocha';
-
- let asphodice = new Asphodice;
-
- interface TestCandidate {
- dice: Array<number>;
- aboveCutOff?: boolean;
- belowCutOff?: boolean;
- reroll?: boolean;
- cancelled?: Array<number>;
- outcomeBalance?: number,
- outcome?: Outcomes,
- }
-
- const testCandidates: Array<TestCandidate> = [
- { 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);
- });
-
- });
- });
|