Files
Aislo/resources/tester/test_nice_tick_step.mjs
T
eomsangdonandClaude Opus 5 0ef32b5279 chore(tester): 시험을 resources/tester/ 로 옮김 — 창끼리 건너가게
⚠ **뿌리** — `tmp/` 는 창 사이에 안 건너감(실측 확인: 상대 창이 놓은 `tmp/_sync_probe.txt`
가 시간을 두고 두 번 봐도 안 보임). 그래서 **정본(등록부 스키마)만 건너가고 그것을 읽는
시험은 안 건너가** 오늘 두 번, 같은 시험이 **연 창은 통과·받은 창은 실패**가 됐음.

- `tmp/tests/*` 를 `resources/tester/` 로 **복사**(127 파일). 내용은 **한 줄도 안 고침**
- `tmp/tests` 는 **남겨 둠** — 되돌릴 자리(사용자 지시)
- 실행: `./venv/Scripts/python.exe -m pytest resources/tester/ -q`
  옮기기 전과 **같은 수**: 617 통과 / 22 건너뜀 / 실패 0

⇒ 이제 시험·예외·까닭이 **정본과 함께** 움직임. 오늘 세운 「예외는 정본 스키마에」와 짝임.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-09 17:12:30 +09:00

46 lines
1.9 KiB
JavaScript

// niceTickStep 자체검증 — B06_Section_UI_Section_Common.ts와 같은 로직(의존 없이 복제).
// 실행: node tmp/tests/test_nice_tick_step.mjs
import assert from "node:assert/strict";
function niceTickStep(span, targetCount, maxCount) {
if (!(span > 0)) return 1;
const exponent = Math.floor(Math.log10(span / targetCount));
let best = Math.pow(10, exponent + 2);
let bestError = Infinity;
for (const power of [exponent - 1, exponent, exponent + 1, exponent + 2]) {
for (const mantissa of [1, 2, 5]) {
const step = mantissa * Math.pow(10, power);
const count = Math.floor(span / step) + 1;
if (count > Math.max(2, maxCount)) continue;
const error = Math.abs(count - targetCount);
if (error < bestError) {
bestError = error;
best = step;
}
}
}
return best;
}
const counts = (span, step) => Math.floor(span / step) + 1;
// 1·2·5 계열만 나온다 + 개수는 상한 이하, 목표 10에 근접.
for (const span of [0.4, 1, 3.7, 8, 21, 27, 63, 140, 900, 4200]) {
const step = niceTickStep(span, 10, 20);
const mantissa = step / Math.pow(10, Math.round(Math.log10(step / 5)) - 0 || 0);
assert.ok(step > 0, `step>0 (span=${span})`);
const norm = step / Math.pow(10, Math.floor(Math.log10(step) + 1e-9));
assert.ok([1, 2, 5].some((m) => Math.abs(norm - m) < 1e-9), `1·2·5 계열 아님: ${step}`);
assert.ok(counts(span, step) <= 20, `상한 초과: span=${span} step=${step}`);
assert.ok(counts(span, step) >= 3, `너무 성김: span=${span} step=${step}`);
void mantissa;
}
// 표고 27m 범위, 화면 여유 충분 → 2m 간격 10줄.
assert.equal(niceTickStep(27, 10, 20), 2);
// 화면이 낮아 6줄까지만 → 5m 간격.
assert.equal(niceTickStep(27, 10, 6), 5);
// 좁은 횡단(2m) → 0.2m 간격.
assert.equal(niceTickStep(2, 10, 20), 0.2);
// 범위 0 방어.
assert.equal(niceTickStep(0, 10, 10), 1);
console.log("ok");