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/ground-pour-selection.test.ts

import { expect, test } from "bun:test";
import { installGroundPourFinalization, selectConnectedGroundPours } from "../routing/ground-pour-selection";

const pour = (id: string, x: number) => ({
  type: "pcb_copper_pour", pcb_copper_pour_id: id, layer: "top", source_net_id: "ground",
  brep_shape: { outer_ring: {vertices: [{x,y:0},{x:x+1,y:0},{x,y:1}]}, inner_rings: [] },
});

test("only the independently audited floating copper is removed", () => {
  const connected= pour("connected",0), floating=pour("floating",3);
  const regions=[{geometry:connected,keep:true},{geometry:floating,keep:false}];
  expect(selectConnectedGroundPours([floating,connected],regions)).toEqual(["floating"]);
  expect(selectConnectedGroundPours([{...connected,pcb_copper_pour_id:"new-id"},floating],regions)).toEqual(["floating"]);
});

test("changed copper geometry, layer, net or count requires a fresh ground audit", () => {
  const original=pour("connected",0), regions=[{geometry:original,keep:true}];
  for(const changed of [pour("connected",0.01),{...original,layer:"bottom"},{...original,source_net_id:"other"}]) {
    expect(()=>selectConnectedGroundPours([changed],regions)).toThrow("Ground pour geometry changed");
  }
  expect(()=>selectConnectedGroundPours([],regions)).toThrow();
  expect(()=>selectConnectedGroundPours([original,pour("extra",3)],regions)).toThrow();
});

test("placement-only CLI renders still run normal DRC without applying a routed-pour selection", () => {
  let checked=false;
  const board={
    root:{pcbDisabled:false,pcbRoutingDisabled:true,db:{toArray(){throw new Error("Placement has no routed pours");}}},
    doInitialPcbDesignRuleChecks(){checked=true;},
  };
  installGroundPourFinalization(board);
  board.doInitialPcbDesignRuleChecks();
  expect(checked).toBe(true);
});