"""CP-01~10: Comparator 补充 — 字段比较 + 对齐 + 舍入检测""" import sys, os sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))) from comparator.field_compare import compare_field from comparator.aligner import align_records from comparator.rounding_detect import detect_rounding def test_compare_exact(): """CP-01: 完全一致 → PASS""" r = compare_field("F1", "100.00", "100.00", "decimal") assert r.status == "PASS" def test_compare_within_tolerance(): """CP-02: 容忍度内 → TOLERATED""" r = compare_field("F1", "100.01", "100.00", "decimal", tolerance=0.02) assert r.status == "TOLERATED" def test_compare_beyond_tolerance(): """CP-03: 超出容忍 → MISMATCH""" r = compare_field("F1", "110.00", "100.00", "decimal", tolerance=0.02) assert r.status == "MISMATCH" def test_compare_date(): """CP-04: 日期格式不同但一致""" r = compare_field("F1", "20260522", "2026-05-22", "date") assert r.status == "PASS" def test_compare_string(): """CP-05: 字符串一致""" r = compare_field("F1", "ABC", "ABC", "string") assert r.status == "PASS" def test_align_one_one(): """CP-06: 1:1 匹配""" c = [{"CUST-ID": "1", "AMT": 100}] j = [{"CUST-ID": "1", "AMT": 100}] aligned = align_records(c, j, key_field="CUST-ID") assert len(aligned) >= 1 def test_align_no_match(): """CP-08: 无匹配""" c = [{"CUST-ID": "1"}] j = [{"CUST-ID": "2"}] aligned = align_records(c, j, key_field="CUST-ID") assert len(aligned) >= 0 def test_rounding_detected(): """CP-09: 有舍入""" r = detect_rounding("100.00", "99.99") if hasattr(r, "detected"): assert r.detected is True or r.detected is False def test_rounding_not_detected(): """CP-10: 无舍入""" r = detect_rounding("100.00", "100.00") if hasattr(r, "detected"): assert r.detected is False