Files
sudoku-tools/tests/state/session.test.ts
T

30 lines
1.0 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
createSession,
enterSelection,
eraseSelection,
maskValues,
valueForKey,
} from "../../src/state/session";
describe("play session", () => {
it("protects givens and toggles values and notes", () => {
const givens = [5, 0, 0, 0];
let state = createSession(givens);
state = enterSelection(state, new Set([0, 1]), "value", 3, givens);
expect(state.values).toEqual([5, 3, 0, 0]);
state = enterSelection(state, new Set([2]), "center", 2, givens);
state = enterSelection(state, new Set([2]), "center", 4, givens);
expect(maskValues(state.centerMarks[2]!, 4)).toEqual([2, 4]);
state = eraseSelection(state, new Set([0, 1]), "value", givens);
expect(state.values).toEqual([5, 0, 0, 0]);
});
it("maps keyboard symbols through hexadecimal-sized grids", () => {
expect(valueForKey("9", 9)).toBe(9);
expect(valueForKey("A", 16)).toBe(10);
expect(valueForKey("G", 16)).toBe(16);
expect(valueForKey("H", 16)).toBeNull();
});
});