Files
homeclaw/tests/speech-units.test.ts

67 lines
3.6 KiB
TypeScript

/**
* speech-units — TTS가 영문 단위 기호를 글자 이름으로 읽는 문제(2026-10-17 "그램을 지라고 읽는다").
*/
import { test, describe } from 'node:test';
import assert from 'node:assert/strict';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { spellUnitsForSpeech: f } = require('../web-ui/js/voice/speech-units.js');
describe('spellUnitsForSpeech', () => {
test('숫자에 붙은 단위를 한글로', () => {
assert.equal(f('설탕 50g 넣고'), '설탕 50그램 넣고');
assert.equal(f('72.5kg'), '72.5킬로그램');
assert.equal(f('15 cm'), '15센티미터');
assert.equal(f('256GB'), '256기가바이트');
assert.equal(f('3.4GHz'), '3.4기가헤르츠');
assert.equal(f('1013hPa'), '1013헥토파스칼');
assert.equal(f('35㎍/㎥'), '35마이크로그램 퍼 세제곱미터');
});
test('복합 단위가 단일 단위보다 먼저', () => {
assert.equal(f('3.2m/s'), '3.2미터 매 초');
assert.equal(f('40km/h'), '40킬로미터 매 시');
assert.equal(f('2.5mm'), '2.5밀리미터');
});
test('조사가 붙어도 변환, 영단어·숫자 없는 글자는 그대로', () => {
assert.equal(f('100m를 달렸다'), '100미터를 달렸다');
assert.equal(f('5mins left'), '5mins left');
assert.equal(f('The A team and g'), 'The A team and g');
});
test('섭씨·달러', () => {
assert.equal(f('21.5℃'), '섭씨 21.5도');
assert.equal(f('$100'), '100달러');
});
test('실사용 로그에서 빠졌던 단위(cm³·fps·t/s·TFLOPS·Nm·MP·mg/dL)', () => {
assert.equal(f('43cm³'), '43세제곱센티미터');
assert.equal(f('60fps'), '60프레임 매 초');
assert.equal(f('18 t/s'), '18토큰 매 초');
assert.equal(f('13TFLOPS'), '13테라플롭스');
assert.equal(f('17Nm'), '17뉴턴미터');
assert.equal(f('12MP'), '12메가픽셀');
assert.equal(f('110mg/dL'), '110밀리그램 퍼 데시리터');
assert.equal(f('5.5mmol/L'), '5.5밀리몰 퍼 리터');
assert.equal(f('4000mAh'), '4000밀리암페어시');
});
test('충돌하는 표기는 건드리지 않는다', () => {
for (const s of ['1990s 노래', '5W1H 원칙', '3D 프린터', '4K 모니터', '5G 통신', '37.5N', '2000년대']) assert.equal(f(s), s);
});
test('데이터·야드파운드·의료·방사선·통화 등 일반 단위', () => {
const cases: Array<[string, string]> = [
['2PB', '2페타바이트'], ['100kbps', '100킬로비피에스'], ['1.5GiB', '1.5기비바이트'], ['8bit', '8비트'],
['5lb', '5파운드'], ['12oz', '12온스'], ['6ft', '6피트'], ['60mph', '60마일 매 시'], ['150hp', '150마력'],
['1000IU', '1000국제단위'], ['5.2ng/mL', '5.2나노그램 퍼 밀리리터'], ['9.5g/dL', '9.5그램 퍼 데시리터'], ['24.5kg/m²', '24.5킬로그램 퍼 제곱미터'],
['1.2mSv', '1.2밀리시버트'], ['0.5Gy', '0.5그레이'], ['400ppb', '400피피비'], ['1atm', '1기압'], ['800lm', '800루멘'],
['2.7g/cm³', '2.7그램 퍼 세제곱센티미터'], ['5mW', '5밀리와트'], ['30sec', '30초'], ['2hr', '2시간'],
['€50', '50유로'], ['£30', '30파운드'], ['¥1000', '1000엔'], ['₩5000', '5000원'], ['98.6℉', '화씨 98.6도'],
];
for (const [input, expected] of cases) assert.equal(f(input), expected, input);
});
test('복합 단위가 단일 단위로 쪼개지지 않는다', () => {
assert.equal(f('5.2ng/mL'), '5.2나노그램 퍼 밀리리터');
assert.equal(f('110mg/dL'), '110밀리그램 퍼 데시리터');
assert.equal(f('5min'), '5분');
assert.equal(f('5mins'), '5mins');
});
});