Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/pcb/pcb_hole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,29 @@ const pcb_hole_oval = z.object({
pcb_hole_id: getZodPrefixedIdWithDefault("pcb_hole"),
pcb_group_id: z.string().optional(),
subcircuit_id: z.string().optional(),
hole_shape: z.literal("oval"),
hole_shape: z.enum(["oval", "pill"]),
hole_width: z.number(),
hole_height: z.number(),
x: distance,
y: distance,
})

export const pcb_hole_oval_shape = pcb_hole_oval.describe(
"Defines an oval hole on the PCB",
"Defines an oval or pill-shaped hole on the PCB",
)

export type PcbHoleOvalInput = z.input<typeof pcb_hole_oval>
type InferredPcbHoleOval = z.infer<typeof pcb_hole_oval>

/**
* Defines an oval hole on the PCB
* Defines an oval or pill-shaped hole on the PCB
*/
export interface PcbHoleOval {
type: "pcb_hole"
pcb_hole_id: string
pcb_group_id?: string
subcircuit_id?: string
hole_shape: "oval"
hole_shape: "oval" | "pill"
hole_width: number
hole_height: number
x: Distance
Expand Down
83 changes: 83 additions & 0 deletions tests/pcb_hole.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { expect, test } from "bun:test"
import {
pcb_hole,
type PcbHoleCircleOrSquare,
type PcbHoleOval,
} from "../src/pcb/pcb_hole"

test("parse circle hole", () => {
const hole = pcb_hole.parse({
type: "pcb_hole",
hole_shape: "circle",
hole_diameter: 1.5,
x: 0,
y: 0,
}) as PcbHoleCircleOrSquare

expect(hole.hole_shape).toBe("circle")
expect(hole.hole_diameter).toBe(1.5)
})

test("parse square hole", () => {
const hole = pcb_hole.parse({
type: "pcb_hole",
hole_shape: "square",
hole_diameter: 2.0,
x: 0,
y: 0,
}) as PcbHoleCircleOrSquare

expect(hole.hole_shape).toBe("square")
expect(hole.hole_diameter).toBe(2.0)
})

test("parse oval hole", () => {
const hole = pcb_hole.parse({
type: "pcb_hole",
hole_shape: "oval",
hole_width: 3.0,
hole_height: 1.5,
x: 0,
y: 0,
}) as PcbHoleOval

expect(hole.hole_shape).toBe("oval")
expect(hole.hole_width).toBe(3.0)
expect(hole.hole_height).toBe(1.5)
})

test("parse pill hole", () => {
const hole = pcb_hole.parse({
type: "pcb_hole",
hole_shape: "pill",
hole_width: 2.5,
hole_height: 1.0,
x: 0,
y: 0,
}) as PcbHoleOval

expect(hole.hole_shape).toBe("pill")
expect(hole.hole_width).toBe(2.5)
expect(hole.hole_height).toBe(1.0)
})

test("parse pill hole with optional properties", () => {
const hole = pcb_hole.parse({
type: "pcb_hole",
hole_shape: "pill",
hole_width: 2.5,
hole_height: 1.0,
x: 1.5,
y: -1.0,
pcb_group_id: "group_1",
subcircuit_id: "subcircuit_1",
}) as PcbHoleOval

expect(hole.hole_shape).toBe("pill")
expect(hole.hole_width).toBe(2.5)
expect(hole.hole_height).toBe(1.0)
expect(hole.x).toBe(1.5)
expect(hole.y).toBe(-1.0)
expect(hole.pcb_group_id).toBe("group_1")
expect(hole.subcircuit_id).toBe("subcircuit_1")
})
Comment on lines +8 to +83
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test file contains 5 test functions, exceeding the limit of one test function per *.test.ts file. Split this file into separate numbered files: pcb_hole1.test.ts, pcb_hole2.test.ts, pcb_hole3.test.ts, pcb_hole4.test.ts, and pcb_hole5.test.ts, with each file containing exactly one test function.

Spotted by Diamond (based on custom rule: Custom rule)

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.