m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/__tests__
diff options
context:
space:
mode:
Diffstat (limited to '__tests__')
-rw-r--r--__tests__/dice.test.js22
-rw-r--r--__tests__/lexer.test.js24
-rw-r--r--__tests__/parser.test.js16
3 files changed, 62 insertions, 0 deletions
diff --git a/__tests__/dice.test.js b/__tests__/dice.test.js
index 4e89031..d397d4c 100644
--- a/__tests__/dice.test.js
+++ b/__tests__/dice.test.js
@@ -5,6 +5,7 @@ const {
add,
subtract,
multiply,
+ divide,
bonusAdd,
bonusSubtract,
negative,
@@ -338,6 +339,27 @@ describe('multiply', () => {
})
})
+describe('divide', () => {
+ describe('1d8 / 2', () => {
+ const die = divide(d(constant(1), constant(8)), constant(2))
+ testDie(die, {
+ diceCount: 1,
+ average: {
+ average: 2
+ },
+ variance: {
+ variance: 1.5
+ },
+ bounds: {
+ low: 0,
+ high: 4,
+ expectLow: true,
+ expectHigh: true
+ }
+ })
+ })
+})
+
describe('bonusAdd', () => {
describe('1d20+3', () => {
diff --git a/__tests__/lexer.test.js b/__tests__/lexer.test.js
index db7ab50..0c615d5 100644
--- a/__tests__/lexer.test.js
+++ b/__tests__/lexer.test.js
@@ -121,6 +121,30 @@ describe('lex', () => {
})
})
+ describe('lexes division', () => {
+ it('1d6 / 1d4', () => {
+ expect(lex('1d6 / 1d4')).toEqual([
+ { type: 'constant', value: 1 },
+ { type: 'd' },
+ { type: 'constant', value: 6 },
+ { type: 'bigDivide' },
+ { type: 'constant', value: 1 },
+ { type: 'd' },
+ { type: 'constant', value: 4 }
+ ])
+ })
+
+ it('2d17 / 4', () => {
+ expect(lex('2d17 / 4')).toEqual([
+ { type: 'constant', value: 2 },
+ { type: 'd' },
+ { type: 'constant', value: 17 },
+ { type: 'bigDivide' },
+ { type: 'constant', value: 4 }
+ ])
+ })
+ })
+
describe('lexes parentheses', () => {
it('(1d6)d6', () => {
expect(lex('(1d6)d6')).toEqual([
diff --git a/__tests__/parser.test.js b/__tests__/parser.test.js
index 5d4288d..bef11c5 100644
--- a/__tests__/parser.test.js
+++ b/__tests__/parser.test.js
@@ -113,6 +113,22 @@ describe('parse', () => {
})
})
+ it('parses dice division', () => {
+ expect(parse('1d6 / 2d8')).toEqual({
+ type: 'divide',
+ left: {
+ type: 'd',
+ left: { type: 'constant', value: 1 },
+ right: { type: 'constant', value: 6 }
+ },
+ right: {
+ type: 'd',
+ left: { type: 'constant', value: 2 },
+ right: { type: 'constant', value: 8 }
+ }
+ })
+ })
+
it('parses additive bonuses', () => {
expect(parse('3d4+1')).toEqual({
type: 'bonusAdd',