const sr2ini = require("../src/js/sr2ini.js");

describe ("test function rollForInitiative()", () => {
	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("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 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);
	});
});