adds testing to DSARoll function
parent
0e0fd22fad
commit
add7ceb144
|
|
@ -10,5 +10,6 @@
|
|||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="@types/jest" level="application" />
|
||||
</component>
|
||||
</module>
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -8,7 +8,7 @@
|
|||
},
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "true",
|
||||
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
|
||||
"build": "gulp",
|
||||
"localBuild": "VERSION=0.0.1 gulp",
|
||||
"installToFoundry": "node installToFoundry.mjs"
|
||||
|
|
@ -21,6 +21,7 @@
|
|||
"gulp": "^5.0.1",
|
||||
"gulp-replace": "^1.1.4",
|
||||
"gulp-sass": "^6.0.1",
|
||||
"jest": "^30.2.0",
|
||||
"merge-stream": "^2.0.0",
|
||||
"nedb": "^1.8.0",
|
||||
"sass": "^1.93.2",
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
* @param {Number} upperThreshold this is the threshold against a critical fumble is counted against
|
||||
* @param {Number} countToMeisterlich amount of critical success are needed for the dice roll to be a critical success
|
||||
* @param {Number} countToPatzer amount of critical fumbles are needed for the dice roll to be a critical failure
|
||||
* @param {*} rollObject the foundry Roll Object
|
||||
* @returns {{tap: number, meisterlich: boolean, patzer: boolean, evaluated: Roll.Evaluated}}
|
||||
*/
|
||||
|
||||
|
|
@ -19,16 +20,23 @@ const evaluateRoll = async (rolledDice, {
|
|||
upperThreshold = 20,
|
||||
countToMeisterlich = 3,
|
||||
countToPatzer = 3,
|
||||
}) => {
|
||||
}, rollObject = Roll) => {
|
||||
let tap = value;
|
||||
let meisterlichCounter = 0;
|
||||
let patzerCounter = 0;
|
||||
let failCounter = 0;
|
||||
let evaluated = null
|
||||
|
||||
// normalise counts
|
||||
if (countToMeisterlich > werte.length) {
|
||||
countToMeisterlich = werte.length
|
||||
}
|
||||
if (countToPatzer > werte.length) {
|
||||
countToPatzer = werte.length
|
||||
}
|
||||
|
||||
if (typeof rolledDice == "string") { // we need to roll it ourself
|
||||
let roll1 = new Roll(rolledDice, owner.getRollData());
|
||||
if (typeof rolledDice == "string") { // we need to roll it ourselves
|
||||
let roll1 = new rollObject(rolledDice, owner.getRollData());
|
||||
evaluated = await roll1.evaluate()
|
||||
rolledDice = evaluated.terms[0].results
|
||||
}
|
||||
|
|
@ -56,9 +64,13 @@ const evaluateRoll = async (rolledDice, {
|
|||
failCounter++;
|
||||
}
|
||||
if (rolledDie.result <= lowerThreshold) meisterlichCounter++;
|
||||
if (rolledDie.result > upperThreshold) patzerCounter++;
|
||||
if (rolledDie.result >= upperThreshold) patzerCounter++;
|
||||
})
|
||||
|
||||
if (meisterlichCounter >= countToMeisterlich) {
|
||||
tap = value
|
||||
}
|
||||
|
||||
return {
|
||||
tap,
|
||||
meisterlich: meisterlichCounter === countToMeisterlich,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,197 @@
|
|||
import { evaluateRoll } from './DSARoll'
|
||||
|
||||
const RollWithMockResults = (a, b, c) => {
|
||||
return class Roll {
|
||||
|
||||
constructor(formula, actorData) {
|
||||
|
||||
}
|
||||
|
||||
async evaluate() {
|
||||
|
||||
return new Promise(resolve => {
|
||||
|
||||
resolve({
|
||||
terms: [{
|
||||
results: [
|
||||
{
|
||||
result: a,
|
||||
active: true
|
||||
},
|
||||
{
|
||||
result: b,
|
||||
active: true
|
||||
},
|
||||
{
|
||||
result: c,
|
||||
active: true
|
||||
}
|
||||
]
|
||||
}]
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
const owner = {
|
||||
getRollData: () => {
|
||||
}
|
||||
}
|
||||
|
||||
describe('Attribute Checks', () => {
|
||||
|
||||
it('should yield a success when the Roll is below the used attribute', async () => {
|
||||
|
||||
let actual = await evaluateRoll("1d20",{
|
||||
value: 0,
|
||||
werte: [12],
|
||||
owner
|
||||
}, RollWithMockResults(12))
|
||||
|
||||
expect(actual.tap).toBeGreaterThanOrEqual(0)
|
||||
})
|
||||
|
||||
it('should yield a failure when the Roll is above the used attribute', async () => {
|
||||
|
||||
let actual = await evaluateRoll("1d20",{
|
||||
value: 0,
|
||||
werte: [12],
|
||||
owner
|
||||
}, RollWithMockResults(13))
|
||||
|
||||
expect(actual.tap).toBeLessThan(0)
|
||||
})
|
||||
|
||||
it('should yield a Patzer when the Roll does meet the Patzer Threshold', async () => {
|
||||
|
||||
let actual = await evaluateRoll("1d20",{
|
||||
value: 0,
|
||||
werte: [12],
|
||||
owner
|
||||
}, RollWithMockResults(20))
|
||||
|
||||
expect(actual.tap).toBeLessThan(0)
|
||||
expect(actual.patzer).toBe(true)
|
||||
})
|
||||
|
||||
it('should yield a Meisterlich when the Roll does meet the Meisterlich Threshold', async () => {
|
||||
|
||||
let actual = await evaluateRoll("1d20",{
|
||||
value: 0,
|
||||
werte: [12],
|
||||
owner
|
||||
}, RollWithMockResults(1))
|
||||
|
||||
expect(actual.tap).toBeGreaterThanOrEqual(0)
|
||||
expect(actual.meisterlich).toBe(true)
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
describe('Skill Checks', () => {
|
||||
|
||||
it('should yield positive TAP when the die roll matches values of used attributes', async () => {
|
||||
|
||||
let actual = await evaluateRoll("3d20",{
|
||||
value: 1,
|
||||
werte: [12, 12, 12],
|
||||
owner
|
||||
}, RollWithMockResults(12, 12, 12))
|
||||
|
||||
expect(actual.tap).toBeGreaterThan(0)
|
||||
})
|
||||
|
||||
it('should succeed with a TaP* of 1 when the die roll are exactly the values of used attributes', async () => {
|
||||
|
||||
let actual = await evaluateRoll("3d20",{
|
||||
value: 0,
|
||||
werte: [12, 12, 12],
|
||||
owner
|
||||
}, RollWithMockResults(12, 12, 12))
|
||||
|
||||
expect(actual.tap).toBe(0)
|
||||
expect(actual.patzer).toBe(false)
|
||||
})
|
||||
|
||||
it('should fail with negative TaP* when the die roll are above the values of used attributes', async () => {
|
||||
|
||||
let actual = await evaluateRoll("3d20",{
|
||||
value: 0,
|
||||
werte: [12, 12, 12],
|
||||
owner
|
||||
}, RollWithMockResults(13, 13, 13))
|
||||
|
||||
expect(actual.tap).toBe(-3)
|
||||
})
|
||||
|
||||
it('should yield a Patzer when the die roll does meet the Patzer Threshold', async () => {
|
||||
|
||||
let actual = await evaluateRoll("3d20",{
|
||||
value: 1,
|
||||
werte: [12, 12, 12],
|
||||
owner
|
||||
}, RollWithMockResults(20, 20, 20))
|
||||
|
||||
expect(actual.tap).toBeLessThan(0)
|
||||
expect(actual.patzer).toBe(true)
|
||||
})
|
||||
|
||||
it('should yield a Patzer when the die roll does meet a modified Patzer Threshold', async () => {
|
||||
|
||||
let actual = await evaluateRoll("3d20",{
|
||||
value: 1,
|
||||
werte: [12, 12, 12],
|
||||
countToPatzer: 2,
|
||||
owner
|
||||
}, RollWithMockResults(20, 20, 1))
|
||||
|
||||
expect(actual.tap).toBeLessThan(0)
|
||||
expect(actual.patzer).toBe(true)
|
||||
})
|
||||
|
||||
it('should yield a Meisterlich when the die roll does meet the Meisterlich Threshold', async () => {
|
||||
|
||||
const tap = 5
|
||||
|
||||
let actual = await evaluateRoll("3d20",{
|
||||
value: tap,
|
||||
werte: [12, 12, 12],
|
||||
owner
|
||||
}, RollWithMockResults(1, 1, 1))
|
||||
|
||||
expect(actual.tap).toBe(tap)
|
||||
expect(actual.meisterlich).toBe(true)
|
||||
})
|
||||
|
||||
it('should yield a Meisterlich when the die roll does meet the modified Meisterlich Threshold', async () => {
|
||||
|
||||
const tap = 5
|
||||
|
||||
let actual = await evaluateRoll("3d20",{
|
||||
value: tap,
|
||||
werte: [12, 12, 12],
|
||||
countToMeisterlich: 2,
|
||||
owner
|
||||
}, RollWithMockResults(1, 20, 1))
|
||||
|
||||
expect(actual.tap).toBe(tap)
|
||||
expect(actual.meisterlich).toBe(true)
|
||||
})
|
||||
|
||||
it('should yield a success when the die roll can be buffered with TaP', async () => {
|
||||
|
||||
let actual = await evaluateRoll("3d20",{
|
||||
value: 8,
|
||||
werte: [12, 12, 12],
|
||||
owner
|
||||
}, RollWithMockResults(15, 15, 8))
|
||||
|
||||
expect(actual.tap).toBe(2)
|
||||
})
|
||||
|
||||
})
|
||||
Loading…
Reference in New Issue