0hmX/am3352
This code suite comprises TypeScript scripts that analyze, verify, and assemble complex DDR memory interface hardware, focusing on physical routing, via and pad placement, electrical clearance, and physical constraints, often involving precise geometric calculations and consistent provenance tracking.
- Version
- 1.0.5
- License
- unset
- Stars
- 0
tests/ddr-sequential.test.ts
import {AutoroutingPipelineSolver4} from '@tscircuit/capacity-autorouter'
import {expect,test} from 'bun:test'
import {freezeHostCopper,checkHostTerminalContract,preservePipeline4Terminals,restoreHdTerminalIds} from '../scripts/route-ddr-sequential'
test('frozen diagonal track obstacles contain its entire copper envelope',()=>{
const obstacles=freezeHostCopper([{connection_name:'signal',route:[{route_type:'wire',x:0,y:0,width:.1016,layer:'inner1'},{route_type:'wire',x:1,y:1,width:.1016,layer:'inner1'}]}])
for(let n=0;n<=100;n++)for(const [dx,dy] of [[.0508,0],[-.0508,0],[0,.0508],[0,-.0508]]){
const x=n/100+dx!,y=n/100+dy!
expect(obstacles.some(o=>Math.abs(x-o.center.x)<=o.width/2+1e-8&&Math.abs(y-o.center.y)<=o.height/2+1e-8)).toBe(true)
}
expect(obstacles.every(o=>o.netIsAssignable===false&&o.connectedTo[0]==='signal')).toBe(true)
})
test('through via blocks every virtual signal layer even for a short logical transition',()=>{
const [o]=freezeHostCopper([{connection_name:'signal',route:[{route_type:'via',x:1,y:2,from_layer:'top',to_layer:'inner1',via_diameter:.4572}]}])
expect(o.layers).toEqual(['top','inner1','inner2','bottom'])
expect(o.width).toBe(.4572)
expect(o.shape).toBe('circle')
})
test('reject missing net identity, missing via and unsafe subdivision',()=>{
expect(()=>freezeHostCopper([{route:[]}])).toThrow()
expect(()=>freezeHostCopper([],1)).toThrow()
expect(()=>freezeHostCopper([{connection_name:'signal',route:[{route_type:'wire',x:0,y:0,width:.1016,layer:'top'},{route_type:'wire',x:0,y:0,width:.1016,layer:'inner1'}]}])).toThrow()
})
test('tight diagonal subdivision reduces excess envelope without exploding axis-aligned runs',()=>{
const diagonal={connection_name:'diag',route:[{route_type:'wire',x:0,y:0,width:.1016,layer:'top'},{route_type:'wire',x:1,y:1,width:.1016,layer:'top'}]}
const tight=freezeHostCopper([diagonal],.025),coarse=freezeHostCopper([diagonal],.25)
expect(Math.max(...tight.map(o=>o.width))).toBeLessThan(.12)
expect(Math.max(...coarse.map(o=>o.width))).toBeGreaterThan(.25)
const axis={connection_name:'axis',route:Array.from({length:101},(_,x)=>({route_type:'wire',x,y:0,width:.1016,layer:'top'}))}
expect(freezeHostCopper([axis],.025)).toHaveLength(3)
})
test('terminal contract accepts either branch orientation and requires both loads',()=>{
const p=(x:number,y:number,layer='top')=>({route_type:'wire',x,y,layer,width:.12})
const c={name:'CA',pointsToConnect:[p(0,0),p(1,0),p(1,1)]}
const t=(route:any[])=>({connection_name:'CA',route})
const traces=[t([p(1,0),p(0,0)]),t([p(0,0),p(1,1)])]
expect(checkHostTerminalContract(traces,[c]).valid).toBe(true)
expect(checkHostTerminalContract(traces.slice(0,1),[c]).violations.some(v=>v.reason==='missing-declared-terminal')).toBe(true)
expect(checkHostTerminalContract([t([p(0,0),p(1,.002)])],[{...c,pointsToConnect:c.pointsToConnect.slice(0,2)}]).valid).toBe(false)
expect(checkHostTerminalContract([t([p(0,0),p(1,0,'inner1')])],[{...c,pointsToConnect:c.pointsToConnect.slice(0,2)}]).valid).toBe(false)
expect(checkHostTerminalContract([t([p(0,0),p(1,.0005)])],[{...c,pointsToConnect:c.pointsToConnect.slice(0,2)}]).valid).toBe(true)
expect(()=>checkHostTerminalContract(traces,[c],.01)).toThrow()
})
test('actual installed Pipeline4 stage constructors receive terminal preservation',()=>{
const solver:any=new AutoroutingPipelineSolver4({minTraceWidth:.12,layerCount:1,bounds:{minX:-1,maxX:2,minY:-1,maxY:1},obstacles:[],connections:[{name:'D1',pointsToConnect:[{x:0,y:0,layer:'top',pcb_port_id:'a'},{x:1,y:0,layer:'top',pcb_port_id:'b'}]}]})
preservePipeline4Terminals(solver)
solver.highDensityStitchSolver={mergedHdRoutes:[]}
const simplifier=solver.pipelineDef.find((s:any)=>s.solverName==='traceSimplificationSolver').getConstructorParams(solver)[0]
expect(simplifier.preserveRouteEndpoints).toBe(true)
solver.srjWithPointPairs={connections:[]};solver.highDensityRouteSolver={routes:[]}
const stitch=solver.pipelineDef.find((s:any)=>s.solverName==='highDensityStitchSolver').getConstructorParams(solver)[0]
expect(stitch.preserveTerminalPcbPortIds).toBe(true)
expect(stitch.preferSameLayerTerminalEndpoints).toBe(true)
const density=solver.pipelineDef.find((s:any)=>s.solverName==='highDensityRouteSolver').getConstructorParams(solver)[0]
expect(density.preserveTerminalPcbPortIds).toBe(true)
})
test('pre-global metadata restoration preserves geometry and fails if moved earlier',()=>{
const cs=[{name:'D1',pointsToConnect:[{x:0,y:0,layer:'top',pointId:'cpu'},{x:1,y:1,layer:'top',pointId:'ram'}]}]
const routes=[{connectionName:'D1',route:[{x:1,y:1,z:0},{x:0,y:0,z:0}]}]
const restored=restoreHdTerminalIds(routes,cs,1)
expect(restored[0].route.map((p:any)=>p.pcb_port_id)).toEqual(['ram','cpu'])
expect(routes[0].route[0]).toEqual({x:1,y:1,z:0})
expect(restored[0].route.map(({pcb_port_id,...p}:any)=>p)).toEqual(routes[0].route)
expect(()=>restoreHdTerminalIds([{connectionName:'D1',route:[{x:1.01,y:1,z:0},{x:0,y:0,z:0}]}],cs,1)).toThrow('moved before')
})