Files
cobol-java-v3/tests/data/test_models.py
hangshuo652 bc1d56d1a4 feat: Phase 2 complete — 13 Phases of COBOL type classification and test benchmark
P0.6: gcov infrastructure
P1: extract_structure output expansion (11 new feature fields)
P2: Confusion group rule engine (8 pairs + contradiction + backtrack)
P3: 4-factor confidence calculation + quality gate update
P4: 33+2 COBOL program type test samples (22 files, 7 categories)
P5: parametrized/ test data generation engine
P6: japanese_data.py lookup tables
P7-10: Type-specific test suites (~159 parametrized tests)
P11: Full classification pipeline (classify_program) + orchestrator integration
P12: Documentation (module-interfaces, test-plan v3.0, coverage-matrix)

Architecture decisions:
- classification_pipeline/ merged to hina/pipeline/
- parametrized/ as independent module
- japanese_data.py as root-level file
- hina/__all__ only exports classify_program()

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-19 23:51:55 +08:00

75 lines
2.3 KiB
Python

"""DM-01~09: 数据模型 — Field/FieldTree/VerificationRun/TestSuite"""
import sys, os
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")))
from data.field_tree import Field, FieldTree
from data.diff_result import VerificationRun, FieldResult
from data.test_case import TestCase, TestSuite, SparkConfig
def test_field_construction():
"""DM-01: Field 属性"""
f = Field(name="WS-A", level=5, pic="9(4)", usage="COMP-3", offset=0, length=4)
assert f.name == "WS-A"
assert f.level == 5
def test_field_tree_flatten():
"""DM-02: 扁平化含嵌套"""
child = Field(name="WS-ITEM", level=10, pic="X(3)")
parent = Field(name="WS-GROUP", level=5, pic="X(10)", children=[child])
tree = FieldTree(fields=[parent])
flat = tree.flatten()
assert "WS-GROUP" in flat
assert "WS-ITEM" in flat
def test_field_tree_flatten_duplicate():
"""DM-03: 同名覆盖 (后盖前)"""
f1 = Field(name="TMP", level=5, pic="9(4)")
f2 = Field(name="TMP", level=10, pic="X(3)")
tree = FieldTree(fields=[f1, f2])
flat = tree.flatten()
assert flat["TMP"].pic == "X(3)" # 后面的覆盖
def test_verification_run_timestamp():
"""DM-04: 自动 timestamp"""
vr = VerificationRun(program="P")
assert vr.timestamp != ""
def test_verification_run_verdict():
"""DM-05~06: verdict"""
vr = VerificationRun(program="P", status="PASS")
assert vr.verdict() == "PASS"
vr2 = VerificationRun(program="P", status="BLOCKED")
assert vr2.verdict() == "BLOCKED"
def test_verification_run_total_fields():
"""DM-07: total_fields 计算"""
vr = VerificationRun(program="P", fields_matched=5, fields_mismatched=3)
assert vr.total_fields == 8
def test_test_suite_has_spark():
"""DM-08: has_spark"""
ts = TestSuite(spark_config=SparkConfig(num_records=100))
assert ts.has_spark is True
ts2 = TestSuite()
assert ts2.has_spark is False
def test_field_result_tolerance():
"""DM-09: 容忍度标记"""
fr = FieldResult(field_name="AMT", status="PASS", tolerance_applied=0.01)
assert fr.status == "PASS"
assert fr.tolerance_applied == 0.01
def test_test_case():
tc = TestCase(id="TC-001", fields={"A": 1}, coverage_targets=["DP-1"])
assert tc.id == "TC-001"
assert tc.fields["A"] == 1