import { describe, it } from "@suaveplan/testing/runner"; import * as fc from "fast-check"; import { createCommand, executeCommand, undoCommand, } from "../../src/command/command.js"; interface State { x: number; y: number; label: string; } describe("property: command round-trip", () => { it("execute then undo restores state for arbitrary closures", { timeout: 30000, }, () => { fc.assert( fc.property( fc.record({ x: fc.integer(), y: fc.integer(), label: fc.string(), }), fc.integer({ min: 1, max: 100 }), (initial, delta) => { const cmd = createCommand( "Transform", (s) => ({ ...s, x: s.x + delta }), (s) => ({ ...s, x: s.x - delta }) ); const after = executeCommand(initial, cmd); const back = undoCommand(after, cmd); return ( back.x === initial.x && back.y === initial.y && back.label === initial.label ); } ), { numRuns: 200 } ); }); });