imrishabh18/rp2040-motor-controller

An RP2040-based NEMA17 stepper-motor controller with USB-C programming and PD motor-power negotiation, DRV8825 dual H-bridge drive, current/temperature telemetry, protected power filtering, status RGB LED, buzzer alarm, and optional magnetic encoder.

Version
1.0.41
License
unset
Stars
3

tests/saved-routing.test.ts

import { expect, test } from "bun:test";
import plan from "../routing/route-plan.json";
import { savedRouting } from "../routing/saved-routing";

test("saved routing refuses moved terminals, changed connections and changed clearances", async () => {
  for (const mutate of [
    (input: any) => { input.connections[0].pointsToConnect[0].x += 0.1; },
    (input: any) => { input.connections[0].pointsToConnect.pop(); },
    (input: any) => { input.minTraceToPadEdgeClearance += 0.05; },
  ]) {
    const input = structuredClone(plan.expectedInput);
    mutate(input);
    await expect(savedRouting(input)).rejects.toThrow("Regenerate and validate");
  }
});

test("saved routing supplies a fresh copy of the complete route geometry", async () => {
  const router = await savedRouting(structuredClone(plan.expectedInput));
  let routes: any[] = [];
  router.on("complete", event => { routes = event.traces; });
  router.start();
  expect(routes.length).toBe(plan.traces.length);
  expect(routes).toEqual(plan.traces);
  routes[0].route[0].x += 1;
  expect(routes[0].route[0].x).not.toBe(plan.traces[0].route[0].x);
});

test("saved routing accepts deduplicated connectivity IDs from newer core", async () => {
  const input = structuredClone(plan.expectedInput);
  for (const obstacle of input.obstacles) {
    obstacle.connectedTo = [...new Set(obstacle.connectedTo)].reverse();
  }
  const router = await savedRouting(input);
  let routes: unknown;
  router.on("complete", event => { routes = event.traces; });
  router.start();
  expect(routes).toEqual(plan.traces);
});

test("saved routing still rejects changed obstacle connectivity", async () => {
  for (const change of ["add", "remove"]) {
    const input = structuredClone(plan.expectedInput);
    const ids = [...new Set(input.obstacles[0].connectedTo)];
    if (change === "add") ids.push("pcb_port_unexpected");
    else ids.pop();
    input.obstacles[0].connectedTo = ids;
    await expect(savedRouting(input)).rejects.toThrow("Regenerate and validate");
  }
});