m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/__tests__
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-08-30 16:36:40 -0400
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2017-08-30 16:36:40 -0400
commita7b971ef64f09a21902f34b6078b01d78dcf73e7 (patch)
treef3ed0e97fe3f31e8c7ca58e18a5835290e66c755 /__tests__
parent5b77a409c912f7251da8c170bd4a3aa8826d989b (diff)
Implement threshold under
Diffstat (limited to '__tests__')
-rw-r--r--__tests__/dice.test.js23
-rw-r--r--__tests__/lexer.test.js10
-rw-r--r--__tests__/parser.test.js10
3 files changed, 42 insertions, 1 deletions
diff --git a/__tests__/dice.test.js b/__tests__/dice.test.js
index 272f436..fb8a155 100644
--- a/__tests__/dice.test.js
+++ b/__tests__/dice.test.js
@@ -13,7 +13,8 @@ const {
keepLow,
again,
againUnder,
- threshold
+ threshold,
+ thresholdLow
} = require('../src/dice.js')
const defaultNumberRolls = 500
@@ -625,4 +626,24 @@ describe('threshold', () => {
}
})
})
+
+ describe('4t3d10', () => {
+ const die = thresholdLow(constant(4), d(constant(3), constant(10)))
+
+ testDie(die, {
+ diceCount: 3,
+ average: {
+ average: 1.2
+ },
+ variance: {
+ variance: 0.72
+ },
+ bounds: {
+ low: 0,
+ high: 3,
+ expectLow: true,
+ expectHigh: true
+ }
+ })
+ })
})
diff --git a/__tests__/lexer.test.js b/__tests__/lexer.test.js
index 25ef816..b51c0f9 100644
--- a/__tests__/lexer.test.js
+++ b/__tests__/lexer.test.js
@@ -225,5 +225,15 @@ describe('lex', () => {
{ type: 'constant', value: 10 }
])
})
+
+ test('8t3d10', () => {
+ expect(lex('8t3d10')).toEqual([
+ { type: 'constant', value: 8 },
+ { type: 't' },
+ { type: 'constant', value: 3 },
+ { type: 'd' },
+ { type: 'constant', value: 10 }
+ ])
+ })
})
})
diff --git a/__tests__/parser.test.js b/__tests__/parser.test.js
index ad67fc4..6e575b6 100644
--- a/__tests__/parser.test.js
+++ b/__tests__/parser.test.js
@@ -241,6 +241,16 @@ describe('parse', () => {
right: { type: 'constant', value: 8 }
}
})
+
+ expect(parse('7t4d8')).toEqual({
+ type: 't',
+ left: { type: 'constant', value: 7 },
+ right: {
+ type: 'd',
+ left: { type: 'constant', value: 4 },
+ right: { type: 'constant', value: 8 }
+ }
+ })
})
describe('parsing parentheses', () => {