Files
projectAIpopular/tests/test_classifier.py
T

45 lines
1.3 KiB
Python

"""分类器单元测试。"""
from router_system.classifier import RuleClassifier
def test_code_classification():
clf = RuleClassifier()
r = clf.classify("用 Python 写一个快速排序函数")
assert r.domain == "code"
assert r.confidence > 0.7
def test_math_classification():
clf = RuleClassifier()
r = clf.classify("求解方程 x^2 - 5x + 6 = 0")
assert r.domain == "math"
assert r.confidence > 0.7
def test_legal_classification():
clf = RuleClassifier()
r = clf.classify("劳动合同到期不续签需要支付经济补偿吗")
assert r.domain == "legal"
def test_medical_classification():
clf = RuleClassifier()
r = clf.classify("高血压患者日常饮食需要注意什么")
assert r.domain == "medical"
def test_general_low_confidence():
clf = RuleClassifier()
r = clf.classify("你好呀")
# 未命中任何领域 -> general,低置信度,触发 should_fallback
assert r.domain == "general"
assert clf.should_fallback(r, 0.6) is True
def test_difficulty_estimation():
clf = RuleClassifier()
easy = clf.classify("1 + 1 = ?")
hard = clf.classify("证明费马大定理并推导其推论,给出详细步骤")
assert hard.difficulty in ("medium", "hard")
assert easy.difficulty == "easy"