From a22d23dcd75aa15aad9c5af98a3ca8b124c57fea Mon Sep 17 00:00:00 2001 From: Nyan404 Date: Tue, 25 Aug 2026 03:21:01 +0300 Subject: [PATCH] fix: decline inspection counts in Russian --- app/belki/reports.py | 22 +++++++++++++++++----- tests/test_belki.py | 5 +++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/app/belki/reports.py b/app/belki/reports.py index 1fc0497..7995523 100644 --- a/app/belki/reports.py +++ b/app/belki/reports.py @@ -52,6 +52,22 @@ def _points_phrase(value: float | int) -> str: return f"{number} {word}" +def _times_phrase(value: int) -> str: + """Формирует правильную форму слова «раз» для количества осмотров.""" + integer = abs(int(value)) + last_two = integer % 100 + last = integer % 10 + if last_two == 1: + word = "раз" + elif 2 <= last_two <= 4: + word = "раза" + elif last in (2, 3, 4) and not 11 <= last_two <= 14: + word = "раза" + else: + word = "раз" + return f"{value} {word}" + + def render_coaching(session: CoachingSession, result: CoachingResult) -> str: """ Формирует итоговый текст отчёта за ЛУ/ЗУ-сессию. @@ -108,13 +124,9 @@ def render_inspection(report: InspectionReport, result: InspectionResult | None Если ресурсов нет — выводит "0" вместо списка. """ result = result or calculate_inspection(report) - if report.inspections == 1: - word = "раз" - else: - word = "раз" lines = [ "#осмотр", - f"{report.character_name} [{report.character_id}] осмотрел(-а) {report.place} {report.inspections} {word}." + f"{report.character_name} [{report.character_id}] осмотрел(-а) {report.place} {_times_phrase(report.inspections)}." ] if report.resources: lines.extend( diff --git a/tests/test_belki.py b/tests/test_belki.py index d4a2d3a..ff2a9f6 100644 --- a/tests/test_belki.py +++ b/tests/test_belki.py @@ -192,6 +192,11 @@ class ReportTests(unittest.TestCase): ) self.assertEqual(calculate_inspection(report).points, 18) + def test_inspection_count_uses_correct_russian_form(self): + for count, phrase in ((1, "1 раз"), (2, "2 раза"), (4, "4 раза"), (5, "5 раз"), (21, "21 раз"), (24, "24 раза")): + report = InspectionReport("Белка", 1, "дупло", count) + self.assertIn(phrase, render_inspection(report)) + def test_inspection_points_include_attempts_and_resource_values(self): report = InspectionReport( character_name="Дикая Вишня", character_id=1604614,