|
| 1 | +import { expect, test } from "bun:test" |
| 2 | +import { convertCircuitJsonToDsnJson } from "../../lib/dsn-pcb/circuit-json-to-dsn-json/convert-circuit-json-to-dsn-json" |
| 3 | +import type { AnyCircuitElement } from "circuit-json" |
| 4 | + |
| 5 | +test("multi-layer support - 2 layers (default)", () => { |
| 6 | + const circuitElements: AnyCircuitElement[] = [ |
| 7 | + { |
| 8 | + type: "pcb_board", |
| 9 | + pcb_board_id: "pcb_board_0", |
| 10 | + center: { x: 0, y: 0 }, |
| 11 | + thickness: 1.4, |
| 12 | + num_layers: 2, |
| 13 | + width: 34.48, |
| 14 | + height: 14.16, |
| 15 | + } as any, |
| 16 | + ] |
| 17 | + |
| 18 | + const dsnJson = convertCircuitJsonToDsnJson(circuitElements) |
| 19 | + |
| 20 | + expect(dsnJson.structure.layers).toHaveLength(2) |
| 21 | + expect(dsnJson.structure.layers[0].name).toBe("F.Cu") |
| 22 | + expect(dsnJson.structure.layers[0].property.index).toBe(0) |
| 23 | + expect(dsnJson.structure.layers[1].name).toBe("B.Cu") |
| 24 | + expect(dsnJson.structure.layers[1].property.index).toBe(1) |
| 25 | +}) |
| 26 | + |
| 27 | +test("multi-layer support - 4 layers", () => { |
| 28 | + const circuitElements: AnyCircuitElement[] = [ |
| 29 | + { |
| 30 | + type: "pcb_board", |
| 31 | + pcb_board_id: "pcb_board_0", |
| 32 | + center: { x: 0, y: 0 }, |
| 33 | + thickness: 1.4, |
| 34 | + num_layers: 4, |
| 35 | + width: 34.48, |
| 36 | + height: 14.16, |
| 37 | + } as any, |
| 38 | + ] |
| 39 | + |
| 40 | + const dsnJson = convertCircuitJsonToDsnJson(circuitElements) |
| 41 | + |
| 42 | + expect(dsnJson.structure.layers).toHaveLength(4) |
| 43 | + expect(dsnJson.structure.layers[0].name).toBe("F.Cu") |
| 44 | + expect(dsnJson.structure.layers[0].property.index).toBe(0) |
| 45 | + expect(dsnJson.structure.layers[1].name).toBe("In1.Cu") |
| 46 | + expect(dsnJson.structure.layers[1].property.index).toBe(1) |
| 47 | + expect(dsnJson.structure.layers[2].name).toBe("In2.Cu") |
| 48 | + expect(dsnJson.structure.layers[2].property.index).toBe(2) |
| 49 | + expect(dsnJson.structure.layers[3].name).toBe("B.Cu") |
| 50 | + expect(dsnJson.structure.layers[3].property.index).toBe(3) |
| 51 | +}) |
| 52 | + |
| 53 | +test("multi-layer support - 6 layers", () => { |
| 54 | + const circuitElements: AnyCircuitElement[] = [ |
| 55 | + { |
| 56 | + type: "pcb_board", |
| 57 | + pcb_board_id: "pcb_board_0", |
| 58 | + center: { x: 0, y: 0 }, |
| 59 | + thickness: 1.4, |
| 60 | + num_layers: 6, |
| 61 | + width: 34.48, |
| 62 | + height: 14.16, |
| 63 | + } as any, |
| 64 | + ] |
| 65 | + |
| 66 | + const dsnJson = convertCircuitJsonToDsnJson(circuitElements) |
| 67 | + |
| 68 | + expect(dsnJson.structure.layers).toHaveLength(6) |
| 69 | + expect(dsnJson.structure.layers[0].name).toBe("F.Cu") |
| 70 | + expect(dsnJson.structure.layers[0].property.index).toBe(0) |
| 71 | + expect(dsnJson.structure.layers[1].name).toBe("In1.Cu") |
| 72 | + expect(dsnJson.structure.layers[1].property.index).toBe(1) |
| 73 | + expect(dsnJson.structure.layers[2].name).toBe("In2.Cu") |
| 74 | + expect(dsnJson.structure.layers[2].property.index).toBe(2) |
| 75 | + expect(dsnJson.structure.layers[3].name).toBe("In3.Cu") |
| 76 | + expect(dsnJson.structure.layers[3].property.index).toBe(3) |
| 77 | + expect(dsnJson.structure.layers[4].name).toBe("In4.Cu") |
| 78 | + expect(dsnJson.structure.layers[4].property.index).toBe(4) |
| 79 | + expect(dsnJson.structure.layers[5].name).toBe("B.Cu") |
| 80 | + expect(dsnJson.structure.layers[5].property.index).toBe(5) |
| 81 | +}) |
| 82 | + |
| 83 | +test("multi-layer support - no num_layers specified (default to 2)", () => { |
| 84 | + const circuitElements: AnyCircuitElement[] = [ |
| 85 | + { |
| 86 | + type: "pcb_board", |
| 87 | + pcb_board_id: "pcb_board_0", |
| 88 | + center: { x: 0, y: 0 }, |
| 89 | + thickness: 1.4, |
| 90 | + width: 34.48, |
| 91 | + height: 14.16, |
| 92 | + } as any, |
| 93 | + ] |
| 94 | + |
| 95 | + const dsnJson = convertCircuitJsonToDsnJson(circuitElements) |
| 96 | + |
| 97 | + expect(dsnJson.structure.layers).toHaveLength(2) |
| 98 | + expect(dsnJson.structure.layers[0].name).toBe("F.Cu") |
| 99 | + expect(dsnJson.structure.layers[0].property.index).toBe(0) |
| 100 | + expect(dsnJson.structure.layers[1].name).toBe("B.Cu") |
| 101 | + expect(dsnJson.structure.layers[1].property.index).toBe(1) |
| 102 | +}) |
0 commit comments