m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--__tests__/dice.test.js48
-rw-r--r--src/dice.js7
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