diff options
author | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2017-07-19 22:38:24 -0400 |
---|---|---|
committer | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2017-07-19 23:14:36 -0400 |
commit | ba07c4d236d2a03f5f7647cf4e724f853703172f (patch) | |
tree | 8d1c4baa59a0ee22e8448157eb3b8e43ed361225 | |
parent | 3d394316505d7c64975e1d5a9d1e04b8da1903c3 (diff) |
Create failing explode tests
-rw-r--r-- | __tests__/dice.test.js | 48 | ||||
-rw-r--r-- | src/dice.js | 7 |
2 files changed, 54 insertions, 1 deletions
diff --git a/__tests__/dice.test.js b/__tests__/dice.test.js index 527db81..1274b3d 100644 --- a/__tests__/dice.test.js +++ b/__tests__/dice.test.js @@ -1,4 +1,12 @@ -const { pool, constant, d, add, subtract, negative } = require('../src/dice.js') +const { + pool, + constant, + d, + add, + subtract, + negative, + explode +} = require('../src/dice.js') const defaultNumberRolls = 500 const defaultError = 0.2 @@ -332,3 +340,41 @@ describe('compound dice', () => { testDie(die, basicDieTestSpecs(2, 2)) }) }) + +describe('exploding dice', () => { + describe('6E1d6', () => { + const die = explode(constant(6), d(constant(1), constant(6))) + testDie(die, { + diceCount: 1, + average: { + average: 4.2 + }, + variance: { + variance: 10.64 + }, + bounds: { + low: 1, + expectLow: true, + high: Infinity + } + }) + }) + + describe('6E2d6', () => { + const die = explode(constant(6), d(constant(2), constant(6))) + testDie(die, { + diceCount: 2, + average: { + average: 2 * 4.2 + }, + variance: { + variance: 2 * 10.64 + }, + bounds: { + low: 2, + expectLow: true, + high: Infinity + } + }) + }) +}) diff --git a/src/dice.js b/src/dice.js index 1587eef..cbc7325 100644 --- a/src/dice.js +++ b/src/dice.js @@ -41,6 +41,12 @@ const subtract = (die1, die2) => { } } +const explode = (die1, die2) => { + return () => { + return die1() + } +} + exports.pool = pool exports.roll = roll exports.constant = constant @@ -48,3 +54,4 @@ exports.d = d exports.add = add exports.subtract = subtract exports.negative = negative +exports.explode = explode |