fix(statements): actual нарушенного соотношения — ближайший вариант abs_terms (T14.I1)
Refs #14 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: cedd7915-2efe-41e5-988c-a9117033598b
This commit is contained in:
parent
1b17f2e748
commit
d82940a8ac
@ -42,7 +42,8 @@ def _holds(amounts: dict[str, Decimal], rule: RelationRule, tolerance: Decimal)
|
||||
"""Проверка соотношения в пределах допуска.
|
||||
|
||||
Вычисляет правую часть два раза: как записано и с abs() для членов в abs_terms.
|
||||
Правило выполняется, если хотя бы один вариант в пределах tolerance.
|
||||
Правило выполняется, если хотя бы один вариант в пределах tolerance. При нарушении возвращается вариант, ближайший
|
||||
к левой части (при равенстве — «как записано»): аналитик видит реальную величину расхождения.
|
||||
"""
|
||||
expected = amounts.get(rule.target, _ZERO)
|
||||
plain = _rhs(amounts, rule, absolute=False)
|
||||
@ -52,6 +53,8 @@ def _holds(amounts: dict[str, Decimal], rule: RelationRule, tolerance: Decimal)
|
||||
with_abs = _rhs(amounts, rule, absolute=True)
|
||||
if abs(expected - with_abs) <= tolerance:
|
||||
return True, expected, with_abs
|
||||
if abs(expected - with_abs) < abs(expected - plain):
|
||||
return False, expected, with_abs
|
||||
return False, expected, plain
|
||||
|
||||
|
||||
|
||||
@ -213,3 +213,22 @@ def test_failed_and_empty_relation_lists_reach_the_wire(rules: Rules) -> None:
|
||||
assert wire["soft_relations_failed"] == []
|
||||
assert clean.to_wire()["relations_failed"] == []
|
||||
assert clean.to_wire()["soft_relations_failed"] == []
|
||||
|
||||
|
||||
def test_failed_relation_reports_the_nearest_variant_as_actual(rules: Rules) -> None:
|
||||
"""T14.I1: при нарушении `actual` — вариант (как записано / с abs_terms), ближайший к `expected`."""
|
||||
lines = [line("2110", "1000"), line("2120", "-600"), line("2100", "410")] # как записано 1600, с abs 400
|
||||
|
||||
checks, _ = run_statement_checks(lines, 1, "INCOME", rules)
|
||||
|
||||
failed = {item.relation: item for item in checks.relations_failed}
|
||||
assert failed["2100 = 2110 - 2120"].expected == Decimal("410")
|
||||
assert failed["2100 = 2110 - 2120"].actual == Decimal("400")
|
||||
|
||||
|
||||
def test_failed_relation_keeps_as_written_variant_on_a_tie(rules: Rules) -> None:
|
||||
lines = [line("2110", "1000"), line("2120", "0"), line("2100", "900")] # оба варианта дают 1000
|
||||
|
||||
checks, _ = run_statement_checks(lines, 1, "INCOME", rules)
|
||||
|
||||
assert {item.relation: item.actual for item in checks.relations_failed}["2100 = 2110 - 2120"] == Decimal("1000")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user