From 7efea0582dda35cd7dc0c370ef3b56c84b2f2291 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Wed, 30 Aug 2017 16:25:34 -0400 Subject: Implement explode under --- __tests__/dice.test.js | 19 +++++++++++++++++++ __tests__/lexer.test.js | 10 ++++++++++ __tests__/parser.test.js | 10 ++++++++++ 3 files changed, 39 insertions(+) (limited to '__tests__') diff --git a/__tests__/dice.test.js b/__tests__/dice.test.js index 12d9130..d4e2802 100644 --- a/__tests__/dice.test.js +++ b/__tests__/dice.test.js @@ -8,6 +8,7 @@ const { bonusSubtract, negative, explode, + explodeUnder, keepHigh, keepLow, again, @@ -483,6 +484,24 @@ describe('exploding dice', () => { } }) }) + + describe('1e1d6', () => { + const die = explodeUnder(constant(1), d(constant(1), constant(6))) + testDie(die, { + diceCount: 1, + average: { + average: 4.2 + }, + variance: { + variance: 2.24 + }, + bounds: { + low: 2, + expectLow: true, + high: Infinity + } + }) + }) }) describe('keep', () => { diff --git a/__tests__/lexer.test.js b/__tests__/lexer.test.js index 21ae3b0..0336f44 100644 --- a/__tests__/lexer.test.js +++ b/__tests__/lexer.test.js @@ -148,6 +148,16 @@ describe('lex', () => { { type: 'constant', value: 6 } ]) }) + + test('1e1d6', () => { + expect(lex('1e1d6')).toEqual([ + { type: 'constant', value: 1 }, + { type: 'e' }, + { type: 'constant', value: 1 }, + { type: 'd' }, + { type: 'constant', value: 6 } + ]) + }) }) describe('keep', () => { diff --git a/__tests__/parser.test.js b/__tests__/parser.test.js index 70ad98d..765388d 100644 --- a/__tests__/parser.test.js +++ b/__tests__/parser.test.js @@ -173,6 +173,16 @@ describe('parse', () => { right: { type: 'constant', value: 6 } } }) + + expect(parse('1e1d6')).toEqual({ + type: 'e', + left: { type: 'constant', value: 1 }, + right: { + type: 'd', + left: { type: 'constant', value: 1 }, + right: { type: 'constant', value: 6 } + } + }) }) it('parses dice with keep high', () => { -- cgit v1.2.3