import { clamp01, lerp, smoothstep, damp, seeded } from "./math";

// The Logistics Brain scene intentionally keeps its own copy of these helpers
// (see the note in math.ts about Turbopack cross-folder const-arrow imports),
// so they are covered independently from optimization/math.

describe("logisticsbrain/math — clamp01() & lerp()", () => {
  it("clamps to [0,1]", () => {
    expect(clamp01(-1)).toBe(0);
    expect(clamp01(0.5)).toBe(0.5);
    expect(clamp01(2)).toBe(1);
  });

  it("interpolates linearly", () => {
    expect(lerp(0, 10, 0.5)).toBe(5);
    expect(lerp(-4, 4, 0.5)).toBe(0);
  });
});

describe("logisticsbrain/math — smoothstep()", () => {
  it("hits edges and midpoint", () => {
    expect(smoothstep(0, 1, 0)).toBe(0);
    expect(smoothstep(0, 1, 1)).toBe(1);
    expect(smoothstep(0, 1, 0.5)).toBeCloseTo(0.5, 10);
  });

  it("guards equal edges (no NaN)", () => {
    expect(Number.isNaN(smoothstep(2, 2, 2))).toBe(false);
  });
});

describe("logisticsbrain/math — damp()", () => {
  it("is a no-op at dt=0 and converges with large lambda*dt", () => {
    expect(damp(5, 20, 4, 0)).toBe(5);
    expect(damp(0, 100, 50, 1)).toBeCloseTo(100, 4);
  });
});

describe("logisticsbrain/math — seeded()", () => {
  it("is deterministic and bounded to [0,1)", () => {
    expect(seeded(42)).toBe(seeded(42));
    for (let i = 0; i < 100; i++) {
      const v = seeded(i);
      expect(v).toBeGreaterThanOrEqual(0);
      expect(v).toBeLessThan(1);
    }
  });
});
