2020-12-31 00:47:31 +01:00
|
|
|
import {
|
|
|
|
rollCheckMultipleDice,
|
|
|
|
rollCheckSingleDie,
|
|
|
|
RollOptions,
|
|
|
|
RollResult,
|
|
|
|
RollResultStatus,
|
|
|
|
} from "../../src/module/rolls/roll-executor";
|
2020-12-30 21:50:12 +01:00
|
|
|
import { RollProvider } from "../../src/module/rolls/roll-provider";
|
2020-12-30 21:27:41 +01:00
|
|
|
|
2020-12-30 23:58:01 +01:00
|
|
|
describe("DS4 Rolls with one die and no modifications.", () => {
|
|
|
|
it("Should do a regular success roll.", () => {
|
2020-12-30 21:27:41 +01:00
|
|
|
const rollProvider: RollProvider = jasmine.createSpyObj("rollProvider", ["getNextRoll"]);
|
|
|
|
|
|
|
|
rollProvider.getNextRoll = jasmine.createSpy("getNextRoll").and.returnValue(4);
|
|
|
|
|
|
|
|
expect(rollCheckSingleDie(12, new RollOptions(), rollProvider)).toEqual(
|
|
|
|
new RollResult(4, RollResultStatus.SUCCESS, [4]),
|
|
|
|
);
|
|
|
|
});
|
2020-12-30 22:19:36 +01:00
|
|
|
|
2020-12-30 23:58:01 +01:00
|
|
|
it("Should do a single success roll on success upper edge case.", () => {
|
2020-12-30 22:19:36 +01:00
|
|
|
const rollProvider: RollProvider = jasmine.createSpyObj("rollProvider", ["getNextRoll"]);
|
|
|
|
|
|
|
|
rollProvider.getNextRoll = jasmine.createSpy("getNextRoll").and.returnValue(4);
|
|
|
|
|
|
|
|
expect(rollCheckSingleDie(4, new RollOptions(), rollProvider)).toEqual(
|
|
|
|
new RollResult(4, RollResultStatus.SUCCESS, [4]),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-12-30 23:58:01 +01:00
|
|
|
it("Should do a single failure roll on lower edge case.", () => {
|
2020-12-30 22:19:36 +01:00
|
|
|
const rollProvider: RollProvider = jasmine.createSpyObj("rollProvider", ["getNextRoll"]);
|
|
|
|
|
|
|
|
rollProvider.getNextRoll = jasmine.createSpy("getNextRoll").and.returnValue(5);
|
|
|
|
|
|
|
|
expect(rollCheckSingleDie(4, new RollOptions(), rollProvider)).toEqual(
|
|
|
|
new RollResult(0, RollResultStatus.FAILURE, [5]),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-12-30 23:58:01 +01:00
|
|
|
it("Should do a single failure roll on upper edge case '19'.", () => {
|
2020-12-30 22:19:36 +01:00
|
|
|
const rollProvider: RollProvider = jasmine.createSpyObj("rollProvider", ["getNextRoll"]);
|
|
|
|
|
|
|
|
rollProvider.getNextRoll = jasmine.createSpy("getNextRoll").and.returnValue(19);
|
|
|
|
|
|
|
|
expect(rollCheckSingleDie(4, new RollOptions(), rollProvider)).toEqual(
|
|
|
|
new RollResult(0, RollResultStatus.FAILURE, [19]),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-12-30 23:58:01 +01:00
|
|
|
it("Should do a single crit success roll on '1'.", () => {
|
2020-12-30 22:19:36 +01:00
|
|
|
const rollProvider: RollProvider = jasmine.createSpyObj("rollProvider", ["getNextRoll"]);
|
|
|
|
|
|
|
|
rollProvider.getNextRoll = jasmine.createSpy("getNextRoll").and.returnValue(1);
|
|
|
|
|
|
|
|
expect(rollCheckSingleDie(4, new RollOptions(), rollProvider)).toEqual(
|
|
|
|
new RollResult(4, RollResultStatus.CRITICAL_SUCCESS, [1]),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-12-30 23:58:01 +01:00
|
|
|
it("Should do a single crit failure roll on '20'.", () => {
|
2020-12-30 22:19:36 +01:00
|
|
|
const rollProvider: RollProvider = jasmine.createSpyObj("rollProvider", ["getNextRoll"]);
|
|
|
|
|
|
|
|
rollProvider.getNextRoll = jasmine.createSpy("getNextRoll").and.returnValue(20);
|
|
|
|
|
|
|
|
expect(rollCheckSingleDie(4, new RollOptions(), rollProvider)).toEqual(
|
|
|
|
new RollResult(0, RollResultStatus.CRITICAL_FAILURE, [20]),
|
|
|
|
);
|
|
|
|
});
|
2020-12-30 23:58:01 +01:00
|
|
|
});
|
2020-12-30 23:03:08 +01:00
|
|
|
|
2020-12-30 23:58:01 +01:00
|
|
|
describe("DS4 Rolls with one die and crit roll modifications.", () => {
|
|
|
|
it("Should do a crit success on `1`.", () => {
|
2020-12-30 23:03:08 +01:00
|
|
|
const rollProvider: RollProvider = jasmine.createSpyObj("rollProvider", ["getNextRoll"]);
|
|
|
|
|
|
|
|
rollProvider.getNextRoll = jasmine.createSpy("getNextRoll").and.returnValue(1);
|
2020-12-31 00:47:31 +01:00
|
|
|
|
2020-12-30 23:03:08 +01:00
|
|
|
expect(rollCheckSingleDie(4, { maxCritSucc: 2, minCritFail: 19 }, rollProvider)).toEqual(
|
|
|
|
new RollResult(4, RollResultStatus.CRITICAL_SUCCESS, [1]),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-12-30 23:58:01 +01:00
|
|
|
it("Should do a crit success on `maxCritSucc`.", () => {
|
2020-12-30 23:03:08 +01:00
|
|
|
const rollProvider: RollProvider = jasmine.createSpyObj("rollProvider", ["getNextRoll"]);
|
|
|
|
|
|
|
|
rollProvider.getNextRoll = jasmine.createSpy("getNextRoll").and.returnValue(2);
|
2020-12-31 00:47:31 +01:00
|
|
|
|
2020-12-30 23:03:08 +01:00
|
|
|
expect(rollCheckSingleDie(4, { maxCritSucc: 2, minCritFail: 19 }, rollProvider)).toEqual(
|
|
|
|
new RollResult(4, RollResultStatus.CRITICAL_SUCCESS, [2]),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-12-30 23:58:01 +01:00
|
|
|
it("Should do a success on lower edge case `3`.", () => {
|
2020-12-30 23:03:08 +01:00
|
|
|
const rollProvider: RollProvider = jasmine.createSpyObj("rollProvider", ["getNextRoll"]);
|
|
|
|
|
|
|
|
rollProvider.getNextRoll = jasmine.createSpy("getNextRoll").and.returnValue(3);
|
2020-12-31 00:47:31 +01:00
|
|
|
|
2020-12-30 23:03:08 +01:00
|
|
|
expect(rollCheckSingleDie(4, { maxCritSucc: 2, minCritFail: 19 }, rollProvider)).toEqual(
|
|
|
|
new RollResult(3, RollResultStatus.SUCCESS, [3]),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-12-30 23:58:01 +01:00
|
|
|
it("Should do a success on upper edge case `18`.", () => {
|
2020-12-30 23:03:08 +01:00
|
|
|
const rollProvider: RollProvider = jasmine.createSpyObj("rollProvider", ["getNextRoll"]);
|
|
|
|
|
|
|
|
rollProvider.getNextRoll = jasmine.createSpy("getNextRoll").and.returnValue(18);
|
2020-12-31 00:47:31 +01:00
|
|
|
|
2020-12-30 23:03:08 +01:00
|
|
|
expect(rollCheckSingleDie(4, { maxCritSucc: 2, minCritFail: 19 }, rollProvider)).toEqual(
|
|
|
|
new RollResult(0, RollResultStatus.FAILURE, [18]),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-12-30 23:58:01 +01:00
|
|
|
it("Should do a crit fail on `minCritFail`.", () => {
|
2020-12-30 23:03:08 +01:00
|
|
|
const rollProvider: RollProvider = jasmine.createSpyObj("rollProvider", ["getNextRoll"]);
|
|
|
|
|
|
|
|
rollProvider.getNextRoll = jasmine.createSpy("getNextRoll").and.returnValue(19);
|
2020-12-31 00:47:31 +01:00
|
|
|
|
2020-12-30 23:03:08 +01:00
|
|
|
expect(rollCheckSingleDie(4, { maxCritSucc: 2, minCritFail: 19 }, rollProvider)).toEqual(
|
|
|
|
new RollResult(0, RollResultStatus.CRITICAL_FAILURE, [19]),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-12-30 23:58:01 +01:00
|
|
|
it("Should do a crit fail on `20`", () => {
|
2020-12-30 23:03:08 +01:00
|
|
|
const rollProvider: RollProvider = jasmine.createSpyObj("rollProvider", ["getNextRoll"]);
|
|
|
|
|
|
|
|
rollProvider.getNextRoll = jasmine.createSpy("getNextRoll").and.returnValue(20);
|
2020-12-31 00:47:31 +01:00
|
|
|
|
2020-12-30 23:03:08 +01:00
|
|
|
expect(rollCheckSingleDie(4, { maxCritSucc: 2, minCritFail: 19 }, rollProvider)).toEqual(
|
|
|
|
new RollResult(0, RollResultStatus.CRITICAL_FAILURE, [20]),
|
|
|
|
);
|
|
|
|
});
|
2020-12-30 21:27:41 +01:00
|
|
|
});
|
2020-12-31 00:47:31 +01:00
|
|
|
|
|
|
|
describe("DS4 Rools with multiple dice and no modifiers.", () => {
|
|
|
|
it("Should do a crit fail on `20` for first roll.", () => {
|
|
|
|
const rollProvider: RollProvider = jasmine.createSpyObj("rollProvider", ["getNextRolls"]);
|
|
|
|
|
|
|
|
rollProvider.getNextRolls = jasmine.createSpy("getNextRolls").and.returnValue([20, 15, 6]);
|
|
|
|
|
|
|
|
expect(rollCheckMultipleDice(48, new RollOptions(), rollProvider)).toEqual(
|
|
|
|
new RollResult(0, RollResultStatus.CRITICAL_FAILURE, [20, 15, 6]),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Should succeed with all rolls crit successes.", () => {
|
|
|
|
const rollProvider: RollProvider = jasmine.createSpyObj("rollProvider", ["getNextRolls"]);
|
|
|
|
|
|
|
|
rollProvider.getNextRolls = jasmine.createSpy("getNextRolls").and.returnValue([1, 1, 1]);
|
|
|
|
|
|
|
|
expect(rollCheckMultipleDice(48, new RollOptions(), rollProvider)).toEqual(
|
|
|
|
new RollResult(48, RollResultStatus.SUCCESS, [1, 1, 1]),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Should succeed with the last roll not being suficient.", () => {
|
|
|
|
const rollProvider: RollProvider = jasmine.createSpyObj("rollProvider", ["getNextRolls"]);
|
|
|
|
|
|
|
|
rollProvider.getNextRolls = jasmine.createSpy("getNextRolls").and.returnValue([15, 15, 15]);
|
|
|
|
|
|
|
|
expect(rollCheckMultipleDice(48, new RollOptions(), rollProvider)).toEqual(
|
|
|
|
new RollResult(30, RollResultStatus.SUCCESS, [15, 15, 15]),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Should succeed with the last roll a crit success.", () => {
|
|
|
|
const rollProvider: RollProvider = jasmine.createSpyObj("rollProvider", ["getNextRolls"]);
|
|
|
|
|
|
|
|
rollProvider.getNextRolls = jasmine.createSpy("getNextRolls").and.returnValue([15, 15, 1]);
|
|
|
|
|
|
|
|
expect(rollCheckMultipleDice(48, new RollOptions(), rollProvider)).toEqual(
|
|
|
|
new RollResult(35, RollResultStatus.SUCCESS, [1, 15, 15]),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("Should succeed with the last roll being 20 and one crit success.", () => {
|
|
|
|
const rollProvider: RollProvider = jasmine.createSpyObj("rollProvider", ["getNextRolls"]);
|
|
|
|
|
|
|
|
rollProvider.getNextRolls = jasmine.createSpy("getNextRolls").and.returnValue([15, 1, 20]);
|
|
|
|
|
|
|
|
expect(rollCheckMultipleDice(48, new RollOptions(), rollProvider)).toEqual(
|
|
|
|
new RollResult(40, RollResultStatus.SUCCESS, [1, 20, 15]),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|