Files
DiceCloud/app/imports/api/engine/action/functions/inputProviderForTests.testFn.ts
2024-03-18 20:40:20 +02:00

42 lines
1.3 KiB
TypeScript

import InputProvider from '/imports/api/engine/action/functions/InputProvider';
const inputProviderForTests: InputProvider = {
/**
* For testing, randomness is hard to deal with
* rollDice function returns the average roll for every dice rolled
* [5d10, 1d4] => [[6,6,6,6,6], [3]]
*/
async rollDice(dice = []) {
const result: number[][] = [];
for (const diceRoll of dice) {
const averageRoll = Math.round(diceRoll.diceSize / 2);
// Return an array full of averagely rolled dice, increasing by 1 for every dice
result.push(
new Array(diceRoll.number)
.fill(averageRoll)
.map((value, index) => (value + index - 1) % diceRoll.diceSize + 1)
)
}
return result;
},
/**
* For testing, always return the minimum number of choices, always choosing the first options
*/
async choose(choices, quantity = [1, 1]) {
const chosen: string[] = [];
const choiceQuantity = quantity[0] <= 0 ? 1 : quantity[0];
for (let i = 0; i < choiceQuantity && i < choices.length; i += 1) {
chosen.push(choices[i]._id);
}
return chosen;
},
/**
* For testing, always return the suggested advantage, as if the user never chose differently
*/
async advantage(suggestedAdvantage) {
return suggestedAdvantage;
}
}
export default inputProviderForTests;