import { describe, expect, it } from "vitest"; import { deepestSoFar, lengthAtDepth } from "./thread"; describe("deepestSoFar", () => { it("keeps the lowest point the line has reached at each sample", () => { // The line goes down, loops back up, and goes down again. expect(deepestSoFar([10, 5, 20, 15, 30])).toEqual([10, 10, 20, 20, 30]); }); it("is empty for an empty line", () => { expect(deepestSoFar([])).toEqual([]); }); it("works above the top of the page", () => { expect(deepestSoFar([-20, -30, -10])).toEqual([-20, -20, -10]); }); }); describe("lengthAtDepth", () => { const depths = [10, 10, 20, 20, 30]; it("draws nothing above the start of the line", () => { expect(lengthAtDepth(depths, 8, 9)).toBe(0); }); it("draws everything the line needed to reach that depth, loops included", () => { expect(lengthAtDepth(depths, 8, 10)).toBe(16); expect(lengthAtDepth(depths, 8, 19)).toBe(16); expect(lengthAtDepth(depths, 8, 20)).toBe(32); }); it("draws the whole line below its end", () => { expect(lengthAtDepth(depths, 8, 1000)).toBe(40); }); it("draws nothing of an empty line", () => { expect(lengthAtDepth([], 8, 1000)).toBe(0); }); });