ds4/spec/rolls/check-evaluation.spec.ts
2021-03-13 02:32:28 +01:00

241 lines
12 KiB
TypeScript

import { assignSubChecksToDice } from "../../src/module/rolls/check-evaluation";
Object.defineProperty(globalThis, "game", { value: { i18n: { localize: (key: string) => key } } });
describe("assignSubChecksToDice with no dice", () => {
it("should throw an error.", () => {
expect(() => assignSubChecksToDice([], 10)).toThrow("DS4.ErrorInvalidNumberOfDice");
});
});
describe("assignSubChecksToDice with more dice than required by the checkTargetNumber", () => {
it("should throw an error.", () => {
expect(() => assignSubChecksToDice([10, 10], 10)).toThrow("DS4.ErrorInvalidNumberOfDice");
});
});
describe("assignSubChecksToDice with less dice than required by the checkTargetNumber", () => {
it("should throw an error.", () => {
expect(() => assignSubChecksToDice([10], 21)).toThrow("DS4.ErrorInvalidNumberOfDice");
});
});
describe("assignSubChecksToDice with a single die", () => {
it("should assign the checkTargetNumber to the single die.", () => {
expect(assignSubChecksToDice([4], 12)).toEqual([{ result: 4, checkTargetNumber: 12 }]);
});
it("should assign the checkTargetNumber to the single die on upper edge case.", () => {
expect(assignSubChecksToDice([4], 4)).toEqual([{ result: 4, checkTargetNumber: 4 }]);
});
it("should assign the checkTargetNumber to the single die on lower edge case.", () => {
expect(assignSubChecksToDice([5], 4)).toEqual([{ result: 5, checkTargetNumber: 4 }]);
});
it("should assign the checkTargetNumber to the single die on upper edge case '19'", () => {
expect(assignSubChecksToDice([19], 4)).toEqual([{ result: 19, checkTargetNumber: 4 }]);
});
it("should assign the checkTargetNumber to the single die on '1'", () => {
expect(assignSubChecksToDice([1], 4)).toEqual([{ result: 1, checkTargetNumber: 4 }]);
});
it("should assign the checkTargetNumber to the single die on '20'", () => {
expect(assignSubChecksToDice([20], 4)).toEqual([{ result: 20, checkTargetNumber: 4 }]);
});
});
describe("assignSubChecksToDice with a single die and coup modification", () => {
it("should assign the checkTargetNumber to the single die on 'maximumCoupResult'", () => {
expect(assignSubChecksToDice([2], 4, { maximumCoupResult: 2 })).toEqual([{ result: 2, checkTargetNumber: 4 }]);
});
it("should assign the checkTargetNumber to the single die on lower edge case '3'", () => {
expect(assignSubChecksToDice([3], 4, { maximumCoupResult: 2 })).toEqual([{ result: 3, checkTargetNumber: 4 }]);
});
});
describe("assignSubChecksToDice with multiple dice", () => {
it("should assign the checkTargetNumber for the last sub check to the lowest non coup, even if the first is '20'.", () => {
expect(assignSubChecksToDice([20, 6, 15], 48)).toEqual([
{ result: 20, checkTargetNumber: 20 },
{ result: 6, checkTargetNumber: 8 },
{ result: 15, checkTargetNumber: 20 },
]);
});
it("should assign the checkTargetNumber for the last sub check to the first coup if there are only coups.", () => {
expect(assignSubChecksToDice([1, 1, 1], 48)).toEqual([
{ result: 1, checkTargetNumber: 8 },
{ result: 1, checkTargetNumber: 20 },
{ result: 1, checkTargetNumber: 20 },
]);
});
it("should assign the checkTargetNumber for the last sub check to the first lowest die, even if it is higher than that value.", () => {
expect(assignSubChecksToDice([15, 15, 15], 48)).toEqual([
{ result: 15, checkTargetNumber: 8 },
{ result: 15, checkTargetNumber: 20 },
{ result: 15, checkTargetNumber: 20 },
]);
});
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.", () => {
expect(assignSubChecksToDice([15, 15, 1], 48)).toEqual([
{ result: 15, checkTargetNumber: 20 },
{ result: 15, checkTargetNumber: 20 },
{ result: 1, checkTargetNumber: 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'.", () => {
expect(assignSubChecksToDice([15, 1, 20], 48)).toEqual([
{ result: 15, checkTargetNumber: 20 },
{ result: 1, checkTargetNumber: 8 },
{ result: 20, checkTargetNumber: 20 },
]);
});
it("should assign the checkTargetNumber for the last sub check to properly maximize the result when all dice are successes.", () => {
expect(assignSubChecksToDice([15, 4, 12], 46)).toEqual([
{ result: 15, checkTargetNumber: 20 },
{ result: 4, checkTargetNumber: 6 },
{ result: 12, checkTargetNumber: 20 },
]);
});
it("should assign the checkTargetNumber for the last sub check to properly maximize the result when one dice is a failure.", () => {
expect(assignSubChecksToDice([15, 8, 12], 46)).toEqual([
{ result: 15, checkTargetNumber: 20 },
{ result: 8, checkTargetNumber: 6 },
{ result: 12, checkTargetNumber: 20 },
]);
});
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.", () => {
expect(assignSubChecksToDice([15, 1, 8], 46)).toEqual([
{ result: 15, checkTargetNumber: 20 },
{ result: 1, checkTargetNumber: 20 },
{ result: 8, checkTargetNumber: 6 },
]);
});
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.", () => {
expect(assignSubChecksToDice([1, 8], 24)).toEqual([
{ result: 1, checkTargetNumber: 20 },
{ result: 8, checkTargetNumber: 4 },
]);
});
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.", () => {
expect(assignSubChecksToDice([1, 19], 38)).toEqual([
{ result: 1, checkTargetNumber: 18 },
{ result: 19, checkTargetNumber: 20 },
]);
});
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", () => {
expect(assignSubChecksToDice([1, 1, 15], 48)).toEqual([
{ result: 1, checkTargetNumber: 8 },
{ result: 1, checkTargetNumber: 20 },
{ result: 15, checkTargetNumber: 20 },
]);
});
});
describe("assignSubChecksToDice with multiple dice and coup modification", () => {
it("should assign the checkTargetNumber for the last sub check to the lowest non coup, even if the first is '19'.", () => {
expect(assignSubChecksToDice([19, 15, 6], 48, { maximumCoupResult: 2 })).toEqual([
{ result: 19, checkTargetNumber: 20 },
{ result: 15, checkTargetNumber: 20 },
{ result: 6, checkTargetNumber: 8 },
]);
});
it("should assign the checkTargetNumber for the last sub check to the first coup if there are only coups ('1' and '2').", () => {
expect(assignSubChecksToDice([2, 1, 2], 48, { maximumCoupResult: 2 })).toEqual([
{ result: 2, checkTargetNumber: 8 },
{ result: 1, checkTargetNumber: 20 },
{ result: 2, checkTargetNumber: 20 },
]);
});
it("should assign the checkTargetNumber for the last sub check to the first lowest die, even if it is higher than that value.", () => {
expect(assignSubChecksToDice([15, 15, 15], 48, { maximumCoupResult: 2 })).toEqual([
{ result: 15, checkTargetNumber: 8 },
{ result: 15, checkTargetNumber: 20 },
{ result: 15, checkTargetNumber: 20 },
]);
});
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.", () => {
expect(assignSubChecksToDice([15, 15, 2], 48, { maximumCoupResult: 2 })).toEqual([
{ result: 15, checkTargetNumber: 20 },
{ result: 15, checkTargetNumber: 20 },
{ result: 2, checkTargetNumber: 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'.", () => {
expect(assignSubChecksToDice([15, 2, 20], 48, { maximumCoupResult: 2 })).toEqual([
{ result: 15, checkTargetNumber: 20 },
{ result: 2, checkTargetNumber: 8 },
{ result: 20, checkTargetNumber: 20 },
]);
});
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'.", () => {
expect(assignSubChecksToDice([15, 2, 19], 48, { maximumCoupResult: 2 })).toEqual([
{ result: 15, checkTargetNumber: 20 },
{ result: 2, checkTargetNumber: 8 },
{ result: 19, checkTargetNumber: 20 },
]);
});
it("should assign the checkTargetNumber for the last sub check to properly maximize the result when all dice are successes.", () => {
expect(assignSubChecksToDice([15, 4, 12], 46, { maximumCoupResult: 2 })).toEqual([
{ result: 15, checkTargetNumber: 20 },
{ result: 4, checkTargetNumber: 6 },
{ result: 12, checkTargetNumber: 20 },
]);
});
it("should assign the checkTargetNumber for the last sub check to properly maximize the result when one dice is a failure.", () => {
expect(assignSubChecksToDice([15, 8, 12], 46, { maximumCoupResult: 2 })).toEqual([
{ result: 15, checkTargetNumber: 20 },
{ result: 8, checkTargetNumber: 6 },
{ result: 12, checkTargetNumber: 20 },
]);
});
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.", () => {
expect(assignSubChecksToDice([15, 2, 8], 46, { maximumCoupResult: 2 })).toEqual([
{ result: 15, checkTargetNumber: 20 },
{ result: 2, checkTargetNumber: 20 },
{ result: 8, checkTargetNumber: 6 },
]);
});
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.", () => {
expect(assignSubChecksToDice([2, 8], 24, { maximumCoupResult: 2 })).toEqual([
{ result: 2, checkTargetNumber: 20 },
{ result: 8, checkTargetNumber: 4 },
]);
});
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.", () => {
expect(assignSubChecksToDice([2, 19], 38, { maximumCoupResult: 2 })).toEqual([
{ result: 2, checkTargetNumber: 18 },
{ result: 19, checkTargetNumber: 20 },
]);
});
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", () => {
expect(assignSubChecksToDice([1, 2, 15], 48, { maximumCoupResult: 2 })).toEqual([
{ result: 1, checkTargetNumber: 8 },
{ result: 2, checkTargetNumber: 20 },
{ result: 15, checkTargetNumber: 20 },
]);
});
});