imrishabh18/pedometer

This code defines and assembles a simple radio receiver hardware circuit using specific imported capacitors, inductors, RF connectors, and oscillator components with precise footprints and schematic attributes.

Version
1.1.3
License
unset
Stars
0

tests/usb-c.test.ts

import { expect, test } from "bun:test"
import { readFileSync } from "node:fs"
const c: any[] = JSON.parse(readFileSync("dist/index/circuit.json", "utf8"))
const component = (name: string) => c.find(e => e.type === "source_component" && e.name === name)
const port = (name: string, pin: number) => c.find(e => e.type === "source_port" && e.source_component_id === component(name).source_component_id && e.pin_number === pin)
const netOf = (name: string, pin: number) => {
  const id = port(name, pin).source_port_id
  const trace = c.find(e => e.type === "source_trace" && e.connected_source_port_ids.includes(id))
  return c.find(e => e.type === "source_net" && trace.connected_source_net_ids.includes(e.source_net_id))?.name
}
test("USB-C supports either orientation with independent Rd terminations", () => {
  expect(component("J2").supplier_part_numbers.jlcpcb).toContain("C456012")
  for (const pin of [9,12]) expect(netOf("J2",pin)).toBe("VIN5")
  for (const pin of [1,2,3,4,8,13]) expect(netOf("J2",pin)).toBe("GND")
  for (const [pin, resistor, net] of [[10,"R12","USB_CC1"],[11,"R13","USB_CC2"]] as const) {
    expect(netOf("J2",pin)).toBe(net)
    expect(netOf(resistor,1)).toBe(net)
    expect(netOf(resistor,2)).toBe("GND")
    expect(component(resistor).resistance).toBe(5100)
    expect(component(resistor).supplier_part_numbers.jlcpcb).toContain("C25905")
  }
  expect(netOf("D1",1)).toBe("VIN5") // Cathode
  expect(netOf("D1",2)).toBe("GND") // Anode
  expect(netOf("U2",1)).toBe("VIN5")
})
test("USB shell slots retain their drawing dimensions and separate grounded ports", () => {
  const pcb = c.find(e => e.type === "pcb_component" && e.source_component_id === component("J2").source_component_id)
  expect(pcb.insertion_direction).toBe("from_top")
  const slots = c.filter(e => e.type === "pcb_plated_hole" && e.pcb_component_id === pcb.pcb_component_id)
  expect(slots).toHaveLength(4)
  expect(new Set(slots.map(e=>e.pcb_port_id)).size).toBe(4)
  for (const slot of slots) {
    expect(Math.min(slot.hole_width,slot.hole_height)).toBeCloseTo(.6,4)
    expect(Math.max(slot.hole_width,slot.hole_height)).toBeCloseTo(1.4,4)
  }
})