extended and improved tests for function rollForInitiative()
This commit is contained in:
parent
e9c163ea2a
commit
41c5437ec4
@ -1,16 +1,27 @@
|
||||
const s = require("../src/js/sr2ini.js");
|
||||
const sr2ini = require("../src/js/sr2ini.js");
|
||||
|
||||
describe ("test function rollForInitiative()", () => {
|
||||
test("function should accept numbes as integers as well as strings", () => {
|
||||
expect(typeof s.rollForInitiative("1", "5")).toBe("number");
|
||||
expect(typeof s.rollForInitiative(1, 5)).toBe("number");
|
||||
test("function should accept integers and strings as parameters", () => {
|
||||
expect(typeof sr2ini.rollForInitiative("1", "5")).toBe("number");
|
||||
expect(typeof sr2ini.rollForInitiative(1, 5)).toBe("number");
|
||||
expect(typeof sr2ini.rollForInitiative(1, "5")).toBe("number");
|
||||
expect(typeof sr2ini.rollForInitiative("1", 5)).toBe("number");
|
||||
});
|
||||
|
||||
test("result should be greater than zero", () => {
|
||||
expect(s.rollForInitiative("1", "5")).toBeGreaterThan(0);
|
||||
test("return value should be zero for bad parameters", () => {
|
||||
// one or zero parameters
|
||||
expect(sr2ini.rollForInitiative(1)).toBe(0);
|
||||
expect(sr2ini.rollForInitiative()).toBe(0);
|
||||
// non-number strings
|
||||
expect(sr2ini.rollForInitiative("qwerty", 12)).toBe(0);
|
||||
expect(sr2ini.rollForInitiative(1, "six")).toBe(0);
|
||||
// parameters as an array
|
||||
expect(sr2ini.rollForInitiative(new Array(1, 2))).toBe(0);
|
||||
expect(sr2ini.rollForInitiative(new Array("1", "2"))).toBe(0);
|
||||
});
|
||||
|
||||
test("should return zero for bad parameters", () => {
|
||||
expect(s.rollForInitiative("a", 2)).toBe(0);
|
||||
test("should return a value within the possible range of dice rolls", () => {
|
||||
expect(sr2ini.rollForInitiative(1, 0)).toBeGreaterThanOrEqual(1);
|
||||
expect(sr2ini.rollForInitiative(1, 0)).toBeLessThanOrEqual(6);
|
||||
expect(sr2ini.rollForInitiative(5, 20)).toBeGreaterThanOrEqual(25);
|
||||
expect(sr2ini.rollForInitiative(5, 20)).toBeLessThanOrEqual(50);
|
||||
});
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user