import assert from "node:assert/strict"; import { readFileSync } from "node:fs"; import { firstAtLeast } from "./debugging-boundary.mjs"; const cases = [ { values: [], target: 3, expected: -1, note: "empty input" }, { values: [5], target: 5, expected: 0, note: "single exact value" }, { values: [5], target: 6, expected: -1, note: "target after end" }, { values: [1, 3, 3, 7], target: 3, expected: 1, note: "first duplicate" }, { values: [1, 3, 3, 7], target: 4, expected: 3, note: "insertion boundary" }, { values: [1, 3, 3, 7], target: 0, expected: 0, note: "target before start" }, { values: [1, 3, 3, 7], target: 8, expected: -1, note: "target after all values" } ]; for (const item of cases) { const before = [...item.values]; assert.equal(firstAtLeast(item.values, item.target), item.expected, item.note); assert.deepStrictEqual(item.values, before, item.note + " must not mutate input"); } assert.throws(() => firstAtLeast([2, 1], 1), /sorted/); assert.throws(() => firstAtLeast("1,2", 1), /array/); const pages = JSON.parse(readFileSync(new URL("../../../includes/recovered-learning-pages.json", import.meta.url), "utf8")); assert.equal(pages["debugging-techniques-fixing-code-errors"].examples[0].code, readFileSync(new URL("./debugging-boundary.mjs", import.meta.url), "utf8")); console.log("PASS: 7 boundary cases, sortedness/type failures, immutability and displayed-code consistency");