|
|
@@ -1,4 +1,5 @@ |
|
|
|
import { Asphodice } from "../dice"; |
|
|
|
import { Outcomes } from "../dice"; |
|
|
|
import { expect } from 'chai'; |
|
|
|
import 'mocha'; |
|
|
|
|
|
|
@@ -10,28 +11,29 @@ interface TestCandidate { |
|
|
|
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] }, |
|
|
|
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] }, |
|
|
|
reroll: false, cancelled: [2,2,2], outcome: Outcomes.Fail, outcomeBalance: -3 }, |
|
|
|
{ dice: [ 1 ], aboveCutOff: false, belowCutOff: true, |
|
|
|
reroll: true, cancelled: [1] }, |
|
|
|
reroll: false, cancelled: [1], outcomeBalance: -1 }, // TODO: temporary behaviour until we handle crits |
|
|
|
{ dice: [ 10 ], aboveCutOff: true, belowCutOff: false, |
|
|
|
reroll: true, cancelled: [10] }, |
|
|
|
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] }, |
|
|
|
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] }, |
|
|
|
{ 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] }, |
|
|
|
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}) => { |
|
|
@@ -85,7 +87,7 @@ describe("cancelRerollDice() filters correctly", function() { |
|
|
|
}); |
|
|
|
testCandidates.filter(candidate => candidate.cancelled!== undefined) |
|
|
|
.forEach( ({dice, cancelled}) => { |
|
|
|
it(`rerollNeeded() says ${dice} → ${cancelled}`, function() { |
|
|
|
it(`cancelRerollDice() says ${dice} → ${cancelled}`, function() { |
|
|
|
const result = asphodice.cancelRerollDice(dice).sort(); |
|
|
|
cancelled?.sort(); |
|
|
|
expect(result).to.deep.equal(cancelled); |
|
|
@@ -93,3 +95,25 @@ describe("cancelRerollDice() filters correctly", function() { |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
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); |
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |