/**
* @file token_estimator.test.js
* @description Unit tests for LODA-MCP-COMP-07: token_estimator
* @covers LODA-MCP-DT-07 (Text → Token estimate)
*/
const { estimateTokens } = require('../loda/token_estimator');
describe('LODA-MCP-COMP-07: token_estimator', () => {
describe('estimateTokens()', () => {
test('UT-COMP07-001: empty string returns 0', () => {
expect(estimateTokens('')).toBe(0);
});
test('UT-COMP07-002: short text estimates correctly', () => {
// "hello world" = 11 chars, ceil(11/4) = 3
expect(estimateTokens('hello world')).toBe(3);
});
test('UT-COMP07-003: long text scales linearly', () => {
// 1000 chars, ceil(1000/4) = 250
expect(estimateTokens('a'.repeat(1000))).toBe(250);
});
test('UT-COMP07-004: unicode text handled', () => {
// Unicode characters still counted by length
const unicodeText = '日本語テスト'; // 6 characters
const result = estimateTokens(unicodeText);
expect(result).toBeGreaterThan(0);
expect(result).toBe(Math.ceil(unicodeText.length / 4));
});
test('UT-COMP07-005: null returns 0', () => {
expect(estimateTokens(null)).toBe(0);
});
test('UT-COMP07-006: undefined returns 0', () => {
expect(estimateTokens(undefined)).toBe(0);
});
});
});