From f07c5096999bf1a65d3082f8de42d3499b43e532 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Tue, 11 Jul 2017 12:18:54 -0400 Subject: Test compound dice --- __tests__/dice.test.js | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to '__tests__') diff --git a/__tests__/dice.test.js b/__tests__/dice.test.js index 04b1c84..fa2d2dc 100644 --- a/__tests__/dice.test.js +++ b/__tests__/dice.test.js @@ -89,6 +89,13 @@ const testDie = (die, testSpecs, numberRolls = defaultNumberRolls) => { }) } + if ('variableDiceCount' in testSpecs) { + const {min, max} = testSpecs.variableDiceCount + it(`rolls between ${min} and ${max} dice`, () => { + expect(pools.map((pool) => (pool.length))).toBeBetween(min, max) + }) + } + if ('average' in testSpecs) { let { average, error } = testSpecs.average @@ -275,5 +282,27 @@ describe('subtract', () => { { number: 3, sides: 6 }, { number: 2, sides: 8, negative: true }, { number: 1, sides: 1, negative: true } - ]) + ], defaultNumberRolls, { varianceError: 1 }) +}) + +describe('compound dice', () => { + describe('(1d4)d(1d6)', () => { + const die = d(d(constant(1), constant(4)), d(constant(1), constant(6))) + const testSpec = { + variableDiceCount: { + min: 1, + max: 4, + }, + average: { + average: 5.625 + }, + bounds: { + low: 1, + high: 24, + expectLow: true + } + } + + testDie(die, testSpec) + }) }) -- cgit v1.2.3