|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- import { Asphodice } 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>;
- }
-
- const testCandidates: Array<TestCandidate> = [
- { dice: [ 6, 6, 6 ], aboveCutOff: true, belowCutOff: false,
- reroll: false, cancelled: [6,6,6] },
- { dice: [ 2, 2, 2 ], aboveCutOff: false, belowCutOff: true,
- reroll: false, cancelled: [2,2,2] },
- { dice: [ 1 ], aboveCutOff: false, belowCutOff: true,
- reroll: true, cancelled: [1] },
- { dice: [ 10 ], aboveCutOff: true, belowCutOff: false,
- reroll: true, cancelled: [10] },
- { dice: [ 6, 10, 6, 9 ], aboveCutOff: true, belowCutOff: false,
- reroll: false, cancelled: [6, 10, 6, 9] },
- { dice: [ 4, 1, 6, 9 ], aboveCutOff: false, belowCutOff: false,
- reroll: true, cancelled: [4, 1, 6, 9] },
- { dice: [ 10, 10, 1, 1, 1, 6], reroll: true, cancelled: [1,6] },
- { dice: [ 10, 10, 1, 1, 1, 2], reroll: false, cancelled: [1,2] },
- { dice: [ 10, 1, 2], reroll: false, cancelled: [2] },
- ];
-
-
-
- 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(`rerollNeeded() says ${dice} → ${cancelled}`, function() {
- const result = asphodice.cancelRerollDice(dice).sort();
- cancelled?.sort();
- expect(result).to.deep.equal(cancelled);
- });
-
- });
- });
|