m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/__tests__
diff options
context:
space:
mode:
Diffstat (limited to '__tests__')
-rw-r--r--__tests__/dice.test.js41
-rw-r--r--__tests__/lexer.test.js12
-rw-r--r--__tests__/parser.test.js12
3 files changed, 65 insertions, 0 deletions
diff --git a/__tests__/dice.test.js b/__tests__/dice.test.js
index 6a9ba46..375c9ad 100644
--- a/__tests__/dice.test.js
+++ b/__tests__/dice.test.js
@@ -8,6 +8,7 @@ const {
divide,
bonusAdd,
bonusSubtract,
+ bonusMultiply,
negative,
explodeAbove,
explodeUnder,
@@ -462,6 +463,46 @@ describe('bonusSubtract', () => {
})
})
+describe('bonusMultiply', () => {
+ describe('1d20*3', () => {
+ const die = bonusMultiply(d(constant(1), constant(20)), constant(3))
+ testDie(die, {
+ diceCount: 1,
+ average: {
+ average: 31.5
+ },
+ variance: {
+ variance: 299.25
+ },
+ bounds: {
+ low: 3,
+ high: 60,
+ expectLow: true,
+ expectHigh: true
+ }
+ })
+ })
+
+ describe('3d4*2', () => {
+ const die = bonusMultiply(d(constant(3), constant(4)), constant(2))
+ testDie(die, {
+ diceCount: 3,
+ average: {
+ average: 15
+ },
+ variance: {
+ variance: 15
+ },
+ bounds: {
+ low: 6,
+ high: 24,
+ expectLow: true,
+ expectHigh: true
+ }
+ })
+ })
+})
+
describe('negative', () => {
describeBasicDie(1, 6, defaultNumberRolls, true)
describeBasicDie(0, 6, defaultNumberRolls, true)
diff --git a/__tests__/lexer.test.js b/__tests__/lexer.test.js
index 6745715..31150bc 100644
--- a/__tests__/lexer.test.js
+++ b/__tests__/lexer.test.js
@@ -241,6 +241,18 @@ describe('lex', () => {
})
})
+ describe('bonusMultiply', () => {
+ test('3d4*1', () => {
+ expect(lex('3d4*1')).toEqual([
+ { type: 'constant', value: 3 },
+ { type: 'd' },
+ { type: 'constant', value: 4 },
+ { type: 'times' },
+ { type: 'constant', value: 1 }
+ ])
+ })
+ })
+
describe('again', () => {
test('6A3d6', () => {
expect(lex('6A3d6')).toEqual([
diff --git a/__tests__/parser.test.js b/__tests__/parser.test.js
index d696b3e..5580b4c 100644
--- a/__tests__/parser.test.js
+++ b/__tests__/parser.test.js
@@ -153,6 +153,18 @@ describe('parse', () => {
})
})
+ it('parses multiplicative bonuses', () => {
+ expect(parse('3d4*1')).toEqual({
+ type: 'bonusMultiply',
+ left: {
+ type: 'd',
+ left: { type: 'constant', value: 3 },
+ right: { type: 'constant', value: 4 }
+ },
+ right: { type: 'constant', value: 1 }
+ })
+ })
+
test('bonus binds stronger than addition', () => {
expect(parse('2d6 + 2d6+2d6')).toEqual({
type: 'add',