ds4/spec/rolls/check-evaluation.spec.ts

270 lines
16 KiB
TypeScript
Raw Permalink Normal View History

2021-03-13 18:43:23 +01:00
import evaluateCheck from "../../src/module/rolls/check-evaluation";
Object.defineProperty(globalThis, "game", { value: { i18n: { localize: (key: string) => key } } });
2021-03-13 18:43:23 +01:00
describe("evaluateCheck with no dice", () => {
2021-03-13 02:32:28 +01:00
it("should throw an error.", () => {
2021-03-13 18:43:23 +01:00
expect(() => evaluateCheck([], 10)).toThrow("DS4.ErrorInvalidNumberOfDice");
});
});
2021-03-13 18:43:23 +01:00
describe("evaluateCheck with more dice than required by the checkTargetNumber", () => {
2021-03-13 02:32:28 +01:00
it("should throw an error.", () => {
2021-03-13 18:43:23 +01:00
expect(() => evaluateCheck([10, 10], 10)).toThrow("DS4.ErrorInvalidNumberOfDice");
});
});
2021-03-13 18:43:23 +01:00
describe("evaluateCheck with less dice than required by the checkTargetNumber", () => {
2021-03-13 02:32:28 +01:00
it("should throw an error.", () => {
2021-03-13 18:43:23 +01:00
expect(() => evaluateCheck([10], 21)).toThrow("DS4.ErrorInvalidNumberOfDice");
});
});
2021-03-13 18:43:23 +01:00
describe("evaluateCheck with a single die", () => {
it("should assign the checkTargetNumber to the single die and be successful.", () => {
expect(evaluateCheck([4], 12)).toEqual([{ result: 4, checkTargetNumber: 12, active: true, discarded: false }]);
});
2021-03-13 18:43:23 +01:00
it("should assign the checkTargetNumber to the single die on upper edge case and be successful.", () => {
expect(evaluateCheck([4], 4)).toEqual([{ result: 4, checkTargetNumber: 4, active: true, discarded: false }]);
});
2021-03-13 18:43:23 +01:00
it("should assign the checkTargetNumber to the single die on lower edge case not be successful.", () => {
expect(evaluateCheck([5], 4)).toEqual([{ result: 5, checkTargetNumber: 4, active: false, discarded: true }]);
});
2021-03-13 18:43:23 +01:00
it("should assign the checkTargetNumber to the single die and not be successful on upper edge case '19'", () => {
expect(evaluateCheck([19], 4)).toEqual([{ result: 19, checkTargetNumber: 4, active: false, discarded: true }]);
});
2021-03-13 18:43:23 +01:00
it("should assign the checkTargetNumber to the single die and coup on '1'", () => {
expect(evaluateCheck([1], 4)).toEqual([
{ result: 1, checkTargetNumber: 4, active: true, discarded: false, success: true, count: 4 },
]);
});
2021-03-13 18:43:23 +01:00
it("should assign the checkTargetNumber to the single die and fumble on '20'", () => {
expect(evaluateCheck([20], 4)).toEqual([
{ result: 20, checkTargetNumber: 4, active: false, discarded: true, failure: true },
]);
});
});
2021-03-13 18:43:23 +01:00
describe("evaluateCheck with a single die and coup / fumble modification", () => {
it("should assign the checkTargetNumber to the single die and coup on 'maximumCoupResult'", () => {
expect(evaluateCheck([2], 4, { maximumCoupResult: 2 })).toEqual([
{ result: 2, checkTargetNumber: 4, active: true, discarded: false, success: true, count: 4 },
]);
});
it("should assign the checkTargetNumber to the single die and not coup on lower edge case '3'", () => {
expect(evaluateCheck([3], 4, { maximumCoupResult: 2 })).toEqual([
{ result: 3, checkTargetNumber: 4, active: true, discarded: false },
]);
});
2021-03-13 18:43:23 +01:00
it("should assign the checkTargetNumber to the single die and fumble on 'minimumFUmbleResultResult'", () => {
expect(evaluateCheck([19], 20, { minimumFumbleResult: 19 })).toEqual([
{ result: 19, checkTargetNumber: 20, active: true, discarded: false, failure: true },
]);
});
it("should assign the checkTargetNumber to the single die and not fumble on upper edge case '18'", () => {
expect(evaluateCheck([18], 20, { minimumFumbleResult: 19 })).toEqual([
{ result: 18, checkTargetNumber: 20, active: true, discarded: false },
]);
});
});
2021-03-13 18:43:23 +01:00
describe("evaluateCheck with multiple dice", () => {
it("should assign the checkTargetNumber for the last sub check to the lowest non coup, even if the first is '20'.", () => {
2021-03-13 18:43:23 +01:00
expect(evaluateCheck([20, 6, 15], 48)).toEqual([
{ result: 20, checkTargetNumber: 20, active: true, discarded: false, failure: true },
{ result: 6, checkTargetNumber: 8, active: true, discarded: false },
{ result: 15, checkTargetNumber: 20, active: true, discarded: false },
]);
});
it("should assign the checkTargetNumber for the last sub check to the first coup if there are only coups.", () => {
2021-03-13 18:43:23 +01:00
expect(evaluateCheck([1, 1, 1], 48)).toEqual([
{ result: 1, checkTargetNumber: 8, active: true, discarded: false, success: true, count: 8 },
{ result: 1, checkTargetNumber: 20, active: true, discarded: false, success: true, count: 20 },
{ result: 1, checkTargetNumber: 20, active: true, discarded: false, success: true, count: 20 },
]);
});
it("should assign the checkTargetNumber for the last sub check to the first lowest die, even if it is higher than that value.", () => {
2021-03-13 18:43:23 +01:00
expect(evaluateCheck([15, 15, 15], 48)).toEqual([
{ result: 15, checkTargetNumber: 8, active: false, discarded: true },
{ result: 15, checkTargetNumber: 20, active: true, discarded: false },
{ result: 15, checkTargetNumber: 20, active: true, discarded: false },
]);
});
it("should assign the checkTargetNumber for the last sub check to the first coup if its sum with the lowest non coup is high enough.", () => {
2021-03-13 18:43:23 +01:00
expect(evaluateCheck([15, 15, 1], 48)).toEqual([
{ result: 15, checkTargetNumber: 20, active: true, discarded: false },
{ result: 15, checkTargetNumber: 20, active: true, discarded: false },
{ result: 1, checkTargetNumber: 8, active: true, discarded: false, success: true, count: 8 },
]);
});
it("should assign the checkTargetNumber for the last sub check to the first coup if its sum with the lowest non coup is high enough, even if the last die is '20'.", () => {
2021-03-13 18:43:23 +01:00
expect(evaluateCheck([15, 1, 20], 48)).toEqual([
{ result: 15, checkTargetNumber: 20, active: true, discarded: false },
{ result: 1, checkTargetNumber: 8, active: true, discarded: false, success: true, count: 8 },
{ result: 20, checkTargetNumber: 20, active: true, discarded: false },
]);
});
it("should assign the checkTargetNumber for the last sub check to properly maximize the result when all dice are successes.", () => {
2021-03-13 18:43:23 +01:00
expect(evaluateCheck([15, 4, 12], 46)).toEqual([
{ result: 15, checkTargetNumber: 20, active: true, discarded: false },
{ result: 4, checkTargetNumber: 6, active: true, discarded: false },
{ result: 12, checkTargetNumber: 20, active: true, discarded: false },
]);
});
it("should assign the checkTargetNumber for the last sub check to properly maximize the result when one dice is a failure.", () => {
2021-03-13 18:43:23 +01:00
expect(evaluateCheck([15, 8, 12], 46)).toEqual([
{ result: 15, checkTargetNumber: 20, active: true, discarded: false },
{ result: 8, checkTargetNumber: 6, active: false, discarded: true },
{ result: 12, checkTargetNumber: 20, active: true, discarded: false },
]);
});
it("should assign the checkTargetNumber for the last sub check to properly maximize the result on 'lowest dice higher than last check target number and coups thrown'-edge case, coup not used for last sub CTN.", () => {
2021-03-13 18:43:23 +01:00
expect(evaluateCheck([15, 1, 8], 46)).toEqual([
{ result: 15, checkTargetNumber: 20, active: true, discarded: false },
{ result: 1, checkTargetNumber: 20, active: true, discarded: false, success: true, count: 20 },
{ result: 8, checkTargetNumber: 6, active: false, discarded: true },
]);
});
it("should assign the checkTargetNumber for the last sub check to properly maximize the result on 2-dice 'lowest dice higher than last check target number and coups thrown'-edge case, coup not used for last sub CTN.", () => {
2021-03-13 18:43:23 +01:00
expect(evaluateCheck([1, 8], 24)).toEqual([
{ result: 1, checkTargetNumber: 20, active: true, discarded: false, success: true, count: 20 },
{ result: 8, checkTargetNumber: 4, active: false, discarded: true },
]);
});
it("should assign the checkTargetNumber for the last sub check to properly maximize the result on 2-dice 'lowest dice higher than last check target number and coups thrown'-edge case, coup used for last sub CTN.", () => {
2021-03-13 18:43:23 +01:00
expect(evaluateCheck([1, 19], 38)).toEqual([
{ result: 1, checkTargetNumber: 18, active: true, discarded: false, success: true, count: 18 },
{ result: 19, checkTargetNumber: 20, active: true, discarded: false },
]);
});
it("should assign the checkTargetNumber for the last sub check to properly maximize the result when there is more than one coup and a coup is used for the last sub CTN", () => {
2021-03-13 18:43:23 +01:00
expect(evaluateCheck([1, 1, 15], 48)).toEqual([
{ result: 1, checkTargetNumber: 8, active: true, discarded: false, success: true, count: 8 },
{ result: 1, checkTargetNumber: 20, active: true, discarded: false, success: true, count: 20 },
{ result: 15, checkTargetNumber: 20, active: true, discarded: false },
]);
});
});
2021-03-13 18:43:23 +01:00
describe("evaluateCheck with multiple dice and coup / fumble modification", () => {
it("should assign the checkTargetNumber for the last sub check to the lowest non coup and fumble if the first is '19'.", () => {
expect(evaluateCheck([19, 15, 6], 48, { maximumCoupResult: 2, minimumFumbleResult: 19 })).toEqual([
{ result: 19, checkTargetNumber: 20, active: true, discarded: false, failure: true },
{ result: 15, checkTargetNumber: 20, active: true, discarded: false },
{ result: 6, checkTargetNumber: 8, active: true, discarded: false },
]);
});
it("should assign the checkTargetNumber for the last sub check to the first coup if there are only coups ('1' and '2').", () => {
2021-03-13 18:43:23 +01:00
expect(evaluateCheck([2, 1, 2], 48, { maximumCoupResult: 2, minimumFumbleResult: 19 })).toEqual([
{ result: 2, checkTargetNumber: 8, active: true, discarded: false, success: true, count: 8 },
{ result: 1, checkTargetNumber: 20, active: true, discarded: false, success: true, count: 20 },
{ result: 2, checkTargetNumber: 20, active: true, discarded: false, success: true, count: 20 },
]);
});
it("should assign the checkTargetNumber for the last sub check to the first lowest die, even if it is higher than that value.", () => {
2021-03-13 18:43:23 +01:00
expect(evaluateCheck([15, 15, 15], 48, { maximumCoupResult: 2, minimumFumbleResult: 19 })).toEqual([
{ result: 15, checkTargetNumber: 8, active: false, discarded: true },
{ result: 15, checkTargetNumber: 20, active: true, discarded: false },
{ result: 15, checkTargetNumber: 20, active: true, discarded: false },
]);
});
it("should assign the checkTargetNumber for the last sub check to the first coup ('2') if its sum with the lowest non coup is high enough.", () => {
2021-03-13 18:43:23 +01:00
expect(evaluateCheck([15, 15, 2], 48, { maximumCoupResult: 2, minimumFumbleResult: 19 })).toEqual([
{ result: 15, checkTargetNumber: 20, active: true, discarded: false },
{ result: 15, checkTargetNumber: 20, active: true, discarded: false },
{ result: 2, checkTargetNumber: 8, active: true, discarded: false, success: true, count: 8 },
]);
});
it("should assign the checkTargetNumber for the last sub check to the first coup ('2') if its sum with the lowest non coup is high enough, even if the last die is '20'.", () => {
2021-03-13 18:43:23 +01:00
expect(evaluateCheck([15, 2, 20], 48, { maximumCoupResult: 2, minimumFumbleResult: 19 })).toEqual([
{ result: 15, checkTargetNumber: 20, active: true, discarded: false },
{ result: 2, checkTargetNumber: 8, active: true, discarded: false, success: true, count: 8 },
{ result: 20, checkTargetNumber: 20, active: true, discarded: false },
]);
});
it("should assign the checkTargetNumber for the last sub check to the first coup ('2') if its sum with the lowest non coup is high enough, even if the last die is '19'.", () => {
2021-03-13 18:43:23 +01:00
expect(evaluateCheck([15, 2, 19], 48, { maximumCoupResult: 2, minimumFumbleResult: 19 })).toEqual([
{ result: 15, checkTargetNumber: 20, active: true, discarded: false },
{ result: 2, checkTargetNumber: 8, active: true, discarded: false, success: true, count: 8 },
{ result: 19, checkTargetNumber: 20, active: true, discarded: false },
]);
});
it("should assign the checkTargetNumber for the last sub check to properly maximize the result when all dice are successes.", () => {
2021-03-13 18:43:23 +01:00
expect(evaluateCheck([15, 4, 12], 46, { maximumCoupResult: 2, minimumFumbleResult: 19 })).toEqual([
{ result: 15, checkTargetNumber: 20, active: true, discarded: false },
{ result: 4, checkTargetNumber: 6, active: true, discarded: false },
{ result: 12, checkTargetNumber: 20, active: true, discarded: false },
]);
});
it("should assign the checkTargetNumber for the last sub check to properly maximize the result when one dice is a failure.", () => {
2021-03-13 18:43:23 +01:00
expect(evaluateCheck([15, 8, 12], 46, { maximumCoupResult: 2, minimumFumbleResult: 19 })).toEqual([
{ result: 15, checkTargetNumber: 20, active: true, discarded: false },
{ result: 8, checkTargetNumber: 6, active: false, discarded: true },
{ result: 12, checkTargetNumber: 20, active: true, discarded: false },
]);
});
it("should assign the checkTargetNumber for the last sub check to properly maximize the result on 'lowest dice higher than last check target number and coups ('2') thrown'-edge case, coup not used for last sub CTN.", () => {
2021-03-13 18:43:23 +01:00
expect(evaluateCheck([15, 2, 8], 46, { maximumCoupResult: 2 })).toEqual([
{ result: 15, checkTargetNumber: 20, active: true, discarded: false },
{ result: 2, checkTargetNumber: 20, active: true, discarded: false, success: true, count: 20 },
{ result: 8, checkTargetNumber: 6, active: false, discarded: true },
]);
});
it("should assign the checkTargetNumber for the last sub check to properly maximize the result on 2-dice 'lowest dice higher than last check target number and coups ('2') thrown'-edge case, coup not used for last sub CTN.", () => {
2021-03-13 18:43:23 +01:00
expect(evaluateCheck([2, 8], 24, { maximumCoupResult: 2 })).toEqual([
{ result: 2, checkTargetNumber: 20, active: true, discarded: false, success: true, count: 20 },
{ result: 8, checkTargetNumber: 4, active: false, discarded: true },
]);
});
it("should assign the checkTargetNumber for the last sub check to properly maximize the result on 2-dice 'lowest dice higher than last check target number and coups ('2') thrown'-edge case, coup used for last sub CTN.", () => {
2021-03-13 18:43:23 +01:00
expect(evaluateCheck([2, 19], 38, { maximumCoupResult: 2 })).toEqual([
{ result: 2, checkTargetNumber: 18, active: true, discarded: false, success: true, count: 18 },
{ result: 19, checkTargetNumber: 20, active: true, discarded: false },
]);
});
it("should assign the checkTargetNumber for the last sub check to properly maximize the result when there is more than one coup ('1' and '2') and a coup is used for the last sub CTN", () => {
2021-03-13 18:43:23 +01:00
expect(evaluateCheck([1, 2, 15], 48, { maximumCoupResult: 2 })).toEqual([
{ result: 1, checkTargetNumber: 8, active: true, discarded: false, success: true, count: 8 },
{ result: 2, checkTargetNumber: 20, active: true, discarded: false, success: true, count: 20 },
{ result: 15, checkTargetNumber: 20, active: true, discarded: false },
]);
});
it("should use all the dice if they are coups, even if they are higher than the checkTargetNumber", () => {
expect(evaluateCheck([18, 19, 17], 48, { maximumCoupResult: 19 })).toEqual([
{ result: 18, checkTargetNumber: 8, active: true, discarded: false, success: true, count: 8 },
{ result: 19, checkTargetNumber: 20, active: true, discarded: false, success: true, count: 20 },
{ result: 17, checkTargetNumber: 20, active: true, discarded: false, success: true, count: 20 },
]);
});
});