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-verified-seed.test.ts
import{test,expect}from'bun:test'
import{selectVerifiedDdrSeed,resolveDdrTraceNet,ddrSeedTraceHash}from'../scripts/ddr-verified-seed'
const w=(x:number,y:number)=>({route_type:'wire',x,y,layer:'inner2',width:.1016})
function fixture(){const original:any[]=[],connections:any[]=[]
for(const [net,coords]of [['source_trace_1',[[0,0],[4,0]]],['source_trace_10',[[0,2],[4,2],[4,4]]]] as const){const ids=coords.map((_,i)=>`${net}_port${i}`);original.push({type:'source_trace',source_trace_id:net,connected_source_port_ids:ids});const points:any[]=[];coords.forEach(([x,y],i)=>{const id=ids[i]!;original.push({type:'pcb_port',pcb_port_id:`pcb_${id}`,source_port_id:id,x,y,layers:['inner2']},{type:'pcb_smtpad',pcb_smtpad_id:`pad_${id}`,pcb_port_id:`pcb_${id}`,shape:'circle',radius:.1,x,y,layer:'inner2'},{type:'pcb_breakout_point',pcb_breakout_point_id:`exit_${id}`,source_port_id:id,x,y,layer:'inner2'});points.push({pointId:`exit_${id}`})});connections.push({name:net,pointsToConnect:points})}
const traces=[{pcb_trace_id:'complete',connection_name:'source_trace_1_0',route:[w(0,0),w(4,0)]},{pcb_trace_id:'partial_branch',connection_name:'source_trace_10_0',route:[w(0,2),w(4,2)]}]
return {captureHash:'test-capture',bundle:{captureHash:'test-capture',layerSpace:'physical',traces},original,leads:[],connections,expectedNetCount:2}
}
test('seed retains only complete nets and excludes partial shared-bus branches',()=>{const f=fixture(),before=JSON.stringify(f.bundle.traces);const seed=selectVerifiedDdrSeed(f);expect(seed.connectedNetNames).toEqual(['source_trace_1']);expect(seed.traces).toEqual([f.bundle.traces[0]]);expect(seed.discardedIncompleteTraceCount).toBe(1);expect(seed.seedTraceHash).toBe(ddrSeedTraceHash([f.bundle.traces[0]]));expect(JSON.stringify(f.bundle.traces)).toBe(before);expect(seed.traces[0]).not.toBe(f.bundle.traces[0])})
test('seed source identity, layer space and dirty geometry fail closed',()=>{const f=fixture();expect(()=>selectVerifiedDdrSeed({...f,captureHash:'other'})).toThrow('hash');expect(()=>selectVerifiedDdrSeed({...f,bundle:{...f.bundle,layerSpace:'virtual'}})).toThrow('physical');const dirty=structuredClone(f);dirty.bundle.traces[1]!.route=[w(0,.1),w(4,.1)];expect(()=>selectVerifiedDdrSeed(dirty)).toThrow('not clean')})
test('longest aliases resolve correctly and ambiguous net identity is rejected',()=>{const {connections}=fixture();expect(resolveDdrTraceNet({connection_name:'source_trace_10_0'},connections)).toBe('source_trace_10');expect(()=>resolveDdrTraceNet({connection_name:'source_trace_10_0',source_trace_id:'source_trace_1'},connections)).toThrow('uniquely')})