From 5b77a409c912f7251da8c170bd4a3aa8826d989b Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Wed, 30 Aug 2017 16:30:23 -0400 Subject: Implement again under --- __tests__/dice.test.js | 24 ++++++++++++++++++++++++ __tests__/lexer.test.js | 10 ++++++++++ __tests__/parser.test.js | 10 ++++++++++ 3 files changed, 44 insertions(+) (limited to '__tests__') diff --git a/__tests__/dice.test.js b/__tests__/dice.test.js index d4e2802..272f436 100644 --- a/__tests__/dice.test.js +++ b/__tests__/dice.test.js @@ -12,6 +12,7 @@ const { keepHigh, keepLow, again, + againUnder, threshold } = require('../src/dice.js') @@ -579,6 +580,29 @@ describe('again', () => { } }) }) + + describe('1a1d6', () => { + const die = againUnder(constant(1), d(constant(1), constant(6))) + + testDie(die, { + variableDiceCount: { + min: 1, + max: Infinity + }, + average: { + average: 4.2 + }, + variance: { + variance: 2.24 + }, + bounds: { + low: 2, + high: Infinity, + expectLow: true, + expectHigh: false + } + }) + }) }) describe('threshold', () => { diff --git a/__tests__/lexer.test.js b/__tests__/lexer.test.js index 0336f44..25ef816 100644 --- a/__tests__/lexer.test.js +++ b/__tests__/lexer.test.js @@ -203,6 +203,16 @@ describe('lex', () => { { type: 'constant', value: 6 } ]) }) + + test('6a3d6', () => { + expect(lex('6a3d6')).toEqual([ + { type: 'constant', value: 6 }, + { type: 'a' }, + { type: 'constant', value: 3 }, + { type: 'd' }, + { type: 'constant', value: 6 } + ]) + }) }) describe('threshold', () => { diff --git a/__tests__/parser.test.js b/__tests__/parser.test.js index 765388d..ad67fc4 100644 --- a/__tests__/parser.test.js +++ b/__tests__/parser.test.js @@ -219,6 +219,16 @@ describe('parse', () => { right: { type: 'constant', value: 10 } } }) + + expect(parse('10a3d10')).toEqual({ + type: 'a', + left: { type: 'constant', value: 10 }, + right: { + type: 'd', + left: { type: 'constant', value: 3 }, + right: { type: 'constant', value: 10 } + } + }) }) it('parases dice with threshold', () => { -- cgit v1.2.3