From 522654d5bf68636a39477f67fa4fd04961f5a6d0 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Sat, 15 Jul 2017 21:53:00 -0400 Subject: Test negative dice --- __tests__/dice.test.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to '__tests__') 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 }, -- cgit v1.2.3