diff --git a/tests/repros/__snapshots__/repro-core-usbc-flashlight-long-ground-trace.snap.svg b/tests/repros/__snapshots__/repro-core-usbc-flashlight-long-ground-trace.snap.svg new file mode 100644 index 000000000..05b0cf392 --- /dev/null +++ b/tests/repros/__snapshots__/repro-core-usbc-flashlight-long-ground-trace.snap.svg @@ -0,0 +1,73 @@ + \ No newline at end of file diff --git a/tests/repros/assets/repro-core-usbc-flashlight-long-ground-trace.input.json b/tests/repros/assets/repro-core-usbc-flashlight-long-ground-trace.input.json new file mode 100644 index 000000000..15b59c477 --- /dev/null +++ b/tests/repros/assets/repro-core-usbc-flashlight-long-ground-trace.input.json @@ -0,0 +1,100 @@ +{ + "chips": [ + { + "chipId": "schematic_component_0", + "center": { "x": -4, "y": 0 }, + "width": 2.4000000000000004, + "height": 4, + "pins": [ + { "pinId": "schematic_port_0", "x": -4.6, "y": -2 }, + { "pinId": "schematic_port_1", "x": -4.4, "y": -2 }, + { "pinId": "schematic_port_2", "x": -2.8, "y": 1.4000000000000001 }, + { "pinId": "schematic_port_3", "x": -2.8, "y": 1.2 }, + { "pinId": "schematic_port_4", "x": -2.8, "y": -1.4000000000000001 }, + { "pinId": "schematic_port_5", "x": -2.8, "y": -0.6000000000000001 }, + { "pinId": "schematic_port_6", "x": -2.8, "y": 0 }, + { "pinId": "schematic_port_7", "x": -2.8, "y": 0.5999999999999999 }, + { "pinId": "schematic_port_8", "x": -2.8, "y": 0.19999999999999996 }, + { "pinId": "schematic_port_9", "x": -2.8, "y": 0.3999999999999999 }, + { "pinId": "schematic_port_10", "x": -2.8, "y": -1.2000000000000002 }, + { "pinId": "schematic_port_11", "x": -2.8, "y": -0.8 } + ] + }, + { + "chipId": "schematic_component_1", + "center": { "x": 0, "y": 2 }, + "width": 1.13, + "height": 1.1800000000000004, + "pins": [ + { "pinId": "schematic_port_12", "x": -0.565, "y": 2, "_facingDirection": "x-" }, + { "pinId": "schematic_port_13", "x": 0.565, "y": 2, "_facingDirection": "x+" } + ] + }, + { + "chipId": "schematic_component_2", + "center": { "x": 0, "y": -2 }, + "width": 0.94, + "height": 0.7189106999999988, + "pins": [ + { "pinId": "schematic_port_14", "x": -0.47, "y": -2.05, "_facingDirection": "x-" }, + { "pinId": "schematic_port_15", "x": -0.47, "y": -2.05, "_facingDirection": "x-" }, + { "pinId": "schematic_port_16", "x": 0.47, "y": -2.05, "_facingDirection": "x+" } + ] + }, + { + "chipId": "schematic_component_3", + "center": { "x": 0, "y": 0 }, + "width": 0.6, + "height": 0.6799999999999999, + "pins": [ + { "pinId": "schematic_port_17", "x": -0.3, "y": 0, "_facingDirection": "x-" }, + { "pinId": "schematic_port_18", "x": 0.3, "y": 0, "_facingDirection": "x+" } + ] + } + ], + "directConnections": [ + { + "netId": "direct_connection_0", + "pinIds": ["schematic_port_15", "schematic_port_17"] + }, + { + "netId": "direct_connection_1", + "pinIds": ["schematic_port_18", "schematic_port_12"] + } + ], + "netConnections": [ + { + "netId": "global_connection_0", + "netLabelWidth": 0.42, + "netLabelHeight": 0.48, + "pinIds": ["schematic_port_0", "schematic_port_1", "schematic_port_13"] + }, + { + "netId": "global_connection_1", + "netLabelWidth": 0.42, + "netLabelHeight": 0.6, + "pinIds": ["schematic_port_2", "schematic_port_3", "schematic_port_16"] + } + ], + "textBoxes": [ + { + "chipId": "schematic_component_0", + "center": { "x": -3.96, "y": 1.9500000000000002 }, + "width": 1.6799999999999997, + "height": 0.17999999999999994, + "text": "TYPE-C-31-M-12" + }, + { + "chipId": "schematic_component_0", + "center": { "x": -4.5600000000000005, "y": 1.7149999999999999 }, + "width": 0.5999999999999988, + "height": 0.24999999999999978, + "text": "USBC" + } + ], + "availableNetLabelOrientations": { + "global_connection_0": ["y-"], + "global_connection_1": ["y+"] + }, + "maxMspPairDistance": 2.4 +} diff --git a/tests/repros/repro-core-usbc-flashlight-long-ground-trace.test.ts b/tests/repros/repro-core-usbc-flashlight-long-ground-trace.test.ts new file mode 100644 index 000000000..0ab17eac7 --- /dev/null +++ b/tests/repros/repro-core-usbc-flashlight-long-ground-trace.test.ts @@ -0,0 +1,33 @@ +import { expect, test } from "bun:test" +import { SchematicTracePipelineSolver } from "lib/solvers/SchematicTracePipelineSolver/SchematicTracePipelineSolver" +import type { InputProblem } from "lib/types/InputProblem" +import "tests/fixtures/matcher" +import inputProblemJson from "./assets/repro-core-usbc-flashlight-long-ground-trace.input.json" + +const inputProblem = inputProblemJson as unknown as InputProblem + +test("reproduces the USB-C flashlight long ground trace", () => { + const downwardConnection = inputProblem.netConnections.find((connection) => { + const orientations = + inputProblem.availableNetLabelOrientations[connection.netId] + return orientations?.length === 1 && orientations[0] === "y-" + })! + const downwardConnectionPinIds = new Set(downwardConnection.pinIds) + const solver = new SchematicTracePipelineSolver(inputProblem) + + solver.solve() + + const longDownwardTraces = + solver.longDistancePairSolver!.solvedLongDistanceTraces.filter((trace) => + trace.pinIds.every((pinId) => downwardConnectionPinIds.has(pinId)), + ) + const downwardLabels = solver + .netLabelNetLabelCollisionSolver!.getOutput() + .netLabelPlacements.filter((placement) => + placement.pinIds.some((pinId) => downwardConnectionPinIds.has(pinId)), + ) + + expect(longDownwardTraces).toHaveLength(1) + expect(downwardLabels).toHaveLength(1) + expect(solver).toMatchSolverSnapshot(import.meta.path) +})