diff options
author | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2017-09-05 22:29:24 -0400 |
---|---|---|
committer | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2017-09-05 22:29:24 -0400 |
commit | 83983efa99d910a97a72fc8b00dd9d7eb8829368 (patch) | |
tree | 17ac7dbb2332bdc7a5005264c591e894e674b0cf /__tests__ | |
parent | fb5cf866c56184dd615e4b7ec5cf6ed1a4703903 (diff) |
Implement multiplicative bonuses
Diffstat (limited to '__tests__')
-rw-r--r-- | __tests__/dice.test.js | 41 | ||||
-rw-r--r-- | __tests__/lexer.test.js | 12 | ||||
-rw-r--r-- | __tests__/parser.test.js | 12 |
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', |