✨Feature: add character creation logic and tests
- Implement character creation functions to handle adventurer setup. - Add validation for adventurer name and selection of starting items. - Introduce new items in sample content pack: Flint and Steel, Pouch, Wax Sealing Kit, and Backpack. - Create tests for character creation functionality to ensure valid options and error handling. ✨Feature: implement dice rolling mechanics and tests - Add functions for rolling various dice types (d3, d6, 2d6, d66) with validation. - Implement modifier application with clamping for roll results. - Create tests to verify correct behavior of dice rolling functions. ✨Feature: add table lookup functionality and tests - Implement table lookup and resolution logic for defined tables. - Support for modified ranges and fallback to nearest entries. - Create tests to ensure correct table entry resolution based on roll results.
This commit is contained in:
46
src/rules/dice.test.ts
Normal file
46
src/rules/dice.test.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { applyRollModifier, roll2D6, rollD3, rollD66, rollDice } from "./dice";
|
||||
|
||||
function createSequenceRoller(values: number[]) {
|
||||
let index = 0;
|
||||
|
||||
return () => {
|
||||
const next = values[index];
|
||||
index += 1;
|
||||
return next;
|
||||
};
|
||||
}
|
||||
|
||||
describe("dice rules", () => {
|
||||
it("maps d3 rolls from a d6 source", () => {
|
||||
const result = rollD3(createSequenceRoller([5]));
|
||||
|
||||
expect(result.rolls).toEqual([5]);
|
||||
expect(result.total).toBe(3);
|
||||
expect(result.modifiedTotal).toBe(3);
|
||||
});
|
||||
|
||||
it("preserves primary and secondary dice for d66", () => {
|
||||
const result = rollD66(createSequenceRoller([4, 2]));
|
||||
|
||||
expect(result.primary).toBe(4);
|
||||
expect(result.secondary).toBe(2);
|
||||
expect(result.total).toBe(42);
|
||||
});
|
||||
|
||||
it("applies modifiers with clamping when limits are provided", () => {
|
||||
const roll = roll2D6(createSequenceRoller([6, 6]));
|
||||
const modified = applyRollModifier(roll, 3, { min: 2, max: 12 });
|
||||
|
||||
expect(modified.modifiedTotal).toBe(12);
|
||||
expect(modified.clamped).toBe(true);
|
||||
});
|
||||
|
||||
it("routes dice kinds through the shared roller", () => {
|
||||
const result = rollDice("d6", createSequenceRoller([2]));
|
||||
|
||||
expect(result.total).toBe(2);
|
||||
expect(result.diceKind).toBe("d6");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user