|
|
@@ -4,33 +4,37 @@ import 'mocha'; |
|
|
|
|
|
|
|
let asphodice = new Asphodice; |
|
|
|
|
|
|
|
const testCandidates = [ |
|
|
|
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, cacncelled: [2,2,2] }, |
|
|
|
reroll: false, cancelled: [2,2,2] }, |
|
|
|
{ dice: [ 1 ], aboveCutOff: false, belowCutOff: true, |
|
|
|
reroll: true, cacncelled: [1] }, |
|
|
|
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() { |
|
|
|
const tests = [ |
|
|
|
{ dice: [ 6, 6, 6 ], expected: true }, |
|
|
|
{ dice: [ 2, 2, 2 ], expected: false }, |
|
|
|
{ dice: [ 1 ], expected: false }, |
|
|
|
{ dice: [ 10 ], expected: true }, |
|
|
|
{ dice: [ 6, 10, 6, 9 ], expected: true} |
|
|
|
]; |
|
|
|
|
|
|
|
tests.forEach(({dice, expected}) => { |
|
|
|
it(`correctly determines ${dice} are above cutoff`, function () { |
|
|
|
const result = asphodice.allAboveCutOff(dice); |
|
|
|
expect(result).to.equal(expected); |
|
|
|
}); |
|
|
|
}); |
|
|
|
testCandidates.forEach( ({dice, aboveCutOff}) => { |
|
|
|
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); |
|
|
@@ -39,41 +43,26 @@ describe("allAboveCutOff() says are all above cutoff correctly", function() { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
describe("Are all below cutoff?", function() { |
|
|
|
const tests = [ |
|
|
|
{ dice: [ 6, 6, 6 ], expected: false }, |
|
|
|
{ dice: [ 2, 2, 2 ], expected: true }, |
|
|
|
{ dice: [ 1 ], expected: true }, |
|
|
|
{ dice: [ 10 ], expected: false }, |
|
|
|
{ dice: [ 6, 10, 6, 9 ], expected: false }, |
|
|
|
{ dice: [ 6, 1, 6, 9 ], expected: false } |
|
|
|
]; |
|
|
|
|
|
|
|
tests.forEach(({dice, expected}) => { |
|
|
|
it(`correctly determines ${dice} are above cutoff`, function () { |
|
|
|
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(expected); |
|
|
|
expect(result).to.equal(belowCutOff); |
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
// TODO: single dice behaviour |
|
|
|
describe("Does it need a re-roll?", function() { |
|
|
|
const tests = [ |
|
|
|
{ dice: [ 6, 6, 6 ], expected: false }, |
|
|
|
{ dice: [ 2, 2, 2 ], expected: false }, |
|
|
|
{ dice: [ 6, 10, 6, 9 ], expected: false }, |
|
|
|
{ dice: [ 6, 1, 6, 9 ], expected: true }, |
|
|
|
{ dice: [ 10, 1, 2], expected: false }, |
|
|
|
{ dice: [ 10, 10, 1, 1, 1, 6], expected: true }, |
|
|
|
{ dice: [ 10, 10, 1, 1, 1, 2], expected: false }, |
|
|
|
]; |
|
|
|
|
|
|
|
tests.forEach(({dice, expected}) => { |
|
|
|
it(`correctly determines ${dice} needs a re-roll`, function () { |
|
|
|
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(expected); |
|
|
|
expect(result).to.equal(reroll); |
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
@@ -94,4 +83,13 @@ describe("cancelRerollDice() filters correctly", function() { |
|
|
|
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); |
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |