import { readFileSync } from 'node:fs'; import { fileURLToPath } from 'node:url'; import * as XLSX from 'xlsx'; import { describe, expect, it } from 'vitest'; import { buildAbut } from '../src/core/abut/geometry'; import { parseAbutments, toAbutInput } from '../src/core/abut/parse'; import { buildMembers } from '../src/core/abut/members'; import { ABUT_BEARING_RULE_DEFAULT, abutBearingChecks, abutElevationRows, abutSolplatePlan, abutSolplateRows, resolveBearingRule, } from '../src/core/abut/bearing-table'; import { applyBearingRule } from '../src/core/abut/edit'; import { checkStoredAbutments } from '../src/core/project'; const RAG = fileURLToPath(new URL('../../../RAG/운곡교P1입력.xlsx', import.meta.url)); const rec = parseAbutments(XLSX.read(readFileSync(RAG), { type: 'buffer' })).abutments[0]; const input = toAbutInput(rec); const model = buildAbut(input); const members = buildMembers(model, { bottomEl: input.foundationBottomEl, pileLengthMm: input.pileLengthMm }); const rule = resolveBearingRule(); const H = rec.bearingHeightMm; describe('교대 받침 카드 (교각 솔플레이트 규칙, 받침높이 H = 교대 시트 값)', () => { it('the rule defaults are the pier rule: 1000 × 1100 · −0.5 %, H 275 from the 교대 sheet', () => { expect(ABUT_BEARING_RULE_DEFAULT).toMatchObject({ lengthMm: 1000, widthMm: 1100, slopePct: -0.5 }); expect(H).toBe(275); // T = ⌈22 + 1000·0.5/200⌉ = 25, h3 = 275 − 25 = 250, T1/T2 = 25 ± 2.5 expect(abutSolplatePlan(rule, H)).toMatchObject({ T: 25, h3: 250, T1: 27.5, T2: 22.5 }); }); it('ELEVATION: block 125 = 75 + 50, E = 75 + 50 + 250 + 25 = 400', () => { const rows = abutElevationRows(model, rule, H); expect(rows).toHaveLength(5); for (const r of rows) { expect([r.h1, r.h2, r.h3, r.h4, r.E]).toEqual([75, 50, 250, 25, 400]); expect(r.solplateTopEl).toBeCloseTo(r.seatEl + 0.4, 6); } const first = rows.find((r) => r.no === 1)!; expect(first.seg).toBe('①'); expect(first.seatEl).toBeCloseTo(44.367, 3); expect(first.z).toBeCloseTo(44.492, 3); }); it('솔플레이트 TABLE: L 1000, W 1100, S −0.5 %, T 25, T1 27.5 / T2 22.5, check 5.0 = 5.0', () => { const [r] = abutSolplateRows(model, rule, H); expect([r.L, r.W, r.S, r.T, r.T1, r.T2]).toEqual([1000, 1100, -0.5, 25, 27.5, 22.5]); expect(r.check).toBe('5.0 = 5.0'); }); it('the rule inputs change the plan: S −1.91 gives T 32 and h3 243', () => { const steep = resolveBearingRule({ slopePct: -1.91 }); // T = ⌈22 + 1000·1.91/200⌉ = ⌈31.55⌉ = 32 expect(abutSolplatePlan(steep, H)).toMatchObject({ T: 32, h3: 243 }); expect(abutElevationRows(model, steep, H)[0].E).toBe(75 + 50 + 275); }); it('checks: W02, W04 (흉벽 ≈ 145 · 전면 255), W03 and I01 all clear for A1', () => { const lines = abutBearingChecks(model, members, rule, H); expect(lines).toHaveLength(4); expect(lines[0]).toContain('W02 없음'); // 시안 145 is bearing ① (lateral 0.745); the smallest gap over the five bearings is 144 (lateral 0.744). expect(lines[1]).toMatch(/흉벽 14[45]/); expect(lines[1]).toContain('전면 255'); expect(lines[1]).toContain('W04 없음'); expect(lines[2]).toContain('W03 없음'); expect(lines[3]).toContain('I01 없음'); }); it('the rule edit keeps only changed values, refuses L 0 and a rule thicker than H, and the project file accepts it', () => { const edited = applyBearingRule(applyBearingRule(rec, 'lengthMm', 900), 'widthMm', 1000); expect(edited.bearingRule).toEqual({ lengthMm: 900, widthMm: 1000 }); expect(() => applyBearingRule(rec, 'lengthMm', 0)).toThrow('0보다'); expect(() => applyBearingRule(rec, 'slopePct', 60)).toThrow('받침높이'); expect(() => checkStoredAbutments([edited])).not.toThrow(); expect(() => checkStoredAbutments([{ ...edited, bearingRule: { lengthMm: 'x' } }])).toThrow('받침 규칙'); }); });