m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--__tests__/dice.test.js18
1 files changed, 14 insertions, 4 deletions
diff --git a/__tests__/dice.test.js b/__tests__/dice.test.js
index 9f3106e..527db81 100644
--- a/__tests__/dice.test.js
+++ b/__tests__/dice.test.js
@@ -1,4 +1,4 @@
-const { pool, constant, d, add, subtract } = require('../src/dice.js')
+const { pool, constant, d, add, subtract, negative } = require('../src/dice.js')
const defaultNumberRolls = 500
const defaultError = 0.2
@@ -187,10 +187,14 @@ const combinedDiceTestSpecs = (dieSpecs) => {
}
}
-const describeBasicDie = (number, sides, numberRolls = defaultNumberRolls) => {
+const describeBasicDie = (number, sides, numberRolls = defaultNumberRolls,
+ neg = false) => {
describe(`${number}d${sides}`, () => {
- const die = d(constant(number), constant(sides))
- testDie(die, basicDieTestSpecs(number, sides), numberRolls)
+ let die = d(constant(number), constant(sides))
+ if (neg) {
+ die = negative(die)
+ }
+ testDie(die, basicDieTestSpecs(number, sides, neg), numberRolls)
})
}
@@ -277,6 +281,12 @@ describe('add', () => {
])
})
+describe('negative', () => {
+ describeBasicDie(1, 6, defaultNumberRolls, true)
+ describeBasicDie(0, 6, defaultNumberRolls, true)
+ describeBasicDie(2, 8, defaultNumberRolls, true)
+})
+
describe('subtract', () => {
describeCompoundDice([
{ number: 1, sides: 6 },