From bea2bb5c660ff0859ac4d192526b0bd8afa46ca1 Mon Sep 17 00:00:00 2001 From: bertieb Date: Thu, 11 Feb 2021 18:19:09 +0000 Subject: [PATCH] Add outcomes + outcomeBalance tests --- test/test-dice.spec.ts | 46 ++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/test/test-dice.spec.ts b/test/test-dice.spec.ts index d9db506..d8ae43c 100644 --- a/test/test-dice.spec.ts +++ b/test/test-dice.spec.ts @@ -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; + outcomeBalance?: number, + outcome?: Outcomes, } const testCandidates: Array = [ { 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); + }); + + }); +});