120 lines
5.3 KiB
TypeScript
120 lines
5.3 KiB
TypeScript
import { rollCheckSingleDie, RollOptions, RollResult, RollResultStatus } from "../../src/module/rolls/roll-executor";
|
|
import { RollProvider } from "../../src/module/rolls/roll-provider";
|
|
|
|
describe("DS4 Rolls with one die and no modifications.", () => {
|
|
it("Should do a regular success roll.", () => {
|
|
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]),
|
|
);
|
|
});
|
|
|
|
it("Should do a single success roll on success upper edge case.", () => {
|
|
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]),
|
|
);
|
|
});
|
|
|
|
it("Should do a single failure roll on lower edge case.", () => {
|
|
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]),
|
|
);
|
|
});
|
|
|
|
it("Should do a single failure roll on upper edge case '19'.", () => {
|
|
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]),
|
|
);
|
|
});
|
|
|
|
it("Should do a single crit success roll on '1'.", () => {
|
|
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]),
|
|
);
|
|
});
|
|
|
|
it("Should do a single crit failure roll on '20'.", () => {
|
|
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]),
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("DS4 Rolls with one die and crit roll modifications.", () => {
|
|
it("Should do a crit success on `1`.", () => {
|
|
const rollProvider: RollProvider = jasmine.createSpyObj("rollProvider", ["getNextRoll"]);
|
|
|
|
rollProvider.getNextRoll = jasmine.createSpy("getNextRoll").and.returnValue(1);
|
|
expect(rollCheckSingleDie(4, { maxCritSucc: 2, minCritFail: 19 }, rollProvider)).toEqual(
|
|
new RollResult(4, RollResultStatus.CRITICAL_SUCCESS, [1]),
|
|
);
|
|
});
|
|
|
|
it("Should do a crit success on `maxCritSucc`.", () => {
|
|
const rollProvider: RollProvider = jasmine.createSpyObj("rollProvider", ["getNextRoll"]);
|
|
|
|
rollProvider.getNextRoll = jasmine.createSpy("getNextRoll").and.returnValue(2);
|
|
expect(rollCheckSingleDie(4, { maxCritSucc: 2, minCritFail: 19 }, rollProvider)).toEqual(
|
|
new RollResult(4, RollResultStatus.CRITICAL_SUCCESS, [2]),
|
|
);
|
|
});
|
|
|
|
it("Should do a success on lower edge case `3`.", () => {
|
|
const rollProvider: RollProvider = jasmine.createSpyObj("rollProvider", ["getNextRoll"]);
|
|
|
|
rollProvider.getNextRoll = jasmine.createSpy("getNextRoll").and.returnValue(3);
|
|
expect(rollCheckSingleDie(4, { maxCritSucc: 2, minCritFail: 19 }, rollProvider)).toEqual(
|
|
new RollResult(3, RollResultStatus.SUCCESS, [3]),
|
|
);
|
|
});
|
|
|
|
it("Should do a success on upper edge case `18`.", () => {
|
|
const rollProvider: RollProvider = jasmine.createSpyObj("rollProvider", ["getNextRoll"]);
|
|
|
|
rollProvider.getNextRoll = jasmine.createSpy("getNextRoll").and.returnValue(18);
|
|
expect(rollCheckSingleDie(4, { maxCritSucc: 2, minCritFail: 19 }, rollProvider)).toEqual(
|
|
new RollResult(0, RollResultStatus.FAILURE, [18]),
|
|
);
|
|
});
|
|
|
|
it("Should do a crit fail on `minCritFail`.", () => {
|
|
const rollProvider: RollProvider = jasmine.createSpyObj("rollProvider", ["getNextRoll"]);
|
|
|
|
rollProvider.getNextRoll = jasmine.createSpy("getNextRoll").and.returnValue(19);
|
|
expect(rollCheckSingleDie(4, { maxCritSucc: 2, minCritFail: 19 }, rollProvider)).toEqual(
|
|
new RollResult(0, RollResultStatus.CRITICAL_FAILURE, [19]),
|
|
);
|
|
});
|
|
|
|
it("Should do a crit fail on `20`", () => {
|
|
const rollProvider: RollProvider = jasmine.createSpyObj("rollProvider", ["getNextRoll"]);
|
|
|
|
rollProvider.getNextRoll = jasmine.createSpy("getNextRoll").and.returnValue(20);
|
|
expect(rollCheckSingleDie(4, { maxCritSucc: 2, minCritFail: 19 }, rollProvider)).toEqual(
|
|
new RollResult(0, RollResultStatus.CRITICAL_FAILURE, [20]),
|
|
);
|
|
});
|
|
});
|