diff options
author | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2017-09-11 15:47:50 -0400 |
---|---|---|
committer | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2017-09-11 15:47:50 -0400 |
commit | 9368b1c33db290d7c80c93db5c867cdb7fcaf14d (patch) | |
tree | c6170c157985624b373a13bb540bd4070321c18c /__tests__ | |
parent | da6582f328c17e1842a4632d88e06d851e7c4b5f (diff) |
Implement collecting
Diffstat (limited to '__tests__')
-rw-r--r-- | __tests__/dice.test.js | 43 | ||||
-rw-r--r-- | __tests__/lexer.test.js | 12 | ||||
-rw-r--r-- | __tests__/parser.test.js | 19 |
3 files changed, 73 insertions, 1 deletions
diff --git a/__tests__/dice.test.js b/__tests__/dice.test.js index 9c03a48..56572d2 100644 --- a/__tests__/dice.test.js +++ b/__tests__/dice.test.js @@ -19,7 +19,8 @@ const { againUnder, thresholdHigh, thresholdLow, - repeat + repeat, + collect } = require('../src/dice.js') const defaultNumberRolls = 500 @@ -817,3 +818,43 @@ describe('repeat', () => { }) }) }) + +describe('collect', () => { + describe('[2d6]', () => { + const die = collect(d(constant(2), constant(6))) + + testDie(die, { + diceCount: 1, + average: { + average: 7 + }, + variance: { + variance: 5.83 + }, + bounds: { + low: 2, + high: 12, + expectLow: true, + expectHigh: true + } + }) + }) + + describe('[1d6 x 1d4]', () => { + const die = + collect(repeat(d(constant(1), constant(6)), d(constant(1), constant(4)))) + + testDie(die, { + diceCount: 1, + average: { + average: 8.75 + }, + bounds: { + low: 1, + high: 24, + expectLow: true, + expectHigh: false + } + }) + }) +}) diff --git a/__tests__/lexer.test.js b/__tests__/lexer.test.js index 7124746..b2cb77e 100644 --- a/__tests__/lexer.test.js +++ b/__tests__/lexer.test.js @@ -171,6 +171,18 @@ describe('lex', () => { { type: 'constant', value: 4 } ]) }) + + it('[2d8]+3', () => { + expect(lex('[2d8]+3')).toEqual([ + { type: '[' }, + { type: 'constant', value: 2 }, + { type: 'd' }, + { type: 'constant', value: 8 }, + { type: ']' }, + { type: 'plus' }, + { type: 'constant', value: 3 } + ]) + }) }) describe('lexes negatives', () => { diff --git a/__tests__/parser.test.js b/__tests__/parser.test.js index 3c9f6ec..cb89ad5 100644 --- a/__tests__/parser.test.js +++ b/__tests__/parser.test.js @@ -325,6 +325,25 @@ describe('parse', () => { }) }) + it('parses dice with collecting', () => { + expect(parse('[2d6] x 1d4')).toEqual({ + type: 'repeat', + left: { + type: 'collect', + value: { + type: 'd', + left: { type: 'constant', value: 2 }, + right: { type: 'constant', value: 6 } + } + }, + right: { + type: 'd', + left: { type: 'constant', value: 1 }, + right: { type: 'constant', value: 4 } + } + }) + }) + describe('parsing parentheses', () => { test('(1d6)d6', () => { expect(parse('(1d6)d6')).toEqual({ |