package com.gzzm.lobster.common;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
 * 验证 Token 估算的稳定性与基本合理性。
 * Verifies stability and basic sanity of the token estimator.
 */
public class TokenEstimatorTest {

    @Test
    public void emptyReturnsZero() {
        assertEquals(0, TokenEstimator.estimate(""));
        assertEquals(0, TokenEstimator.estimate(null));
    }

    @Test
    public void cjkCharactersCountedOne() {
        // 5 个中文字符约 5 tokens
        int tokens = TokenEstimator.estimate("大龙虾平台");
        assertTrue("should be >=4", tokens >= 4);
        assertTrue("should be <=6", tokens <= 6);
    }

    @Test
    public void englishWordsAreFractional() {
        // 4 words -> ~3 tokens
        int tokens = TokenEstimator.estimate("Big Lobster AI Server");
        assertTrue(tokens >= 3);
        assertTrue(tokens <= 4);
    }

    @Test
    public void mixedText() {
        int tokens = TokenEstimator.estimate("大龙虾 is an Agent 平台");
        assertTrue(tokens > 0);
    }

    @Test
    public void stableAcrossCalls() {
        String s = "这是一段测试文本 testing text";
        assertEquals(TokenEstimator.estimate(s), TokenEstimator.estimate(s));
    }
}
