Natural form fixes
This commit is contained in:
1 parent
2fe36d513a
commit
92605e7a4d
3 files changed
+28
-8
No files matched your search
+23
-3
@@ -17,6 +17,26 @@ def _number(value: float | int) -> str:
|
||||
return str(value).rstrip("0").rstrip(".") if isinstance(value, float) else str(value)
|
||||
|
||||
|
||||
def _points_phrase(value: float | int) -> str:
|
||||
"""Return a number with the natural Russian form of «балл»."""
|
||||
number = _number(value)
|
||||
if isinstance(value, float) and not value.is_integer():
|
||||
word = "балла"
|
||||
else:
|
||||
integer = abs(int(value))
|
||||
last_two = integer % 100
|
||||
last = integer % 10
|
||||
if 11 <= last_two <= 14:
|
||||
word = "баллов"
|
||||
elif last == 1:
|
||||
word = "балл"
|
||||
elif last in (2, 3, 4):
|
||||
word = "балла"
|
||||
else:
|
||||
word = "баллов"
|
||||
return f"{number} {word}"
|
||||
|
||||
|
||||
def render_coaching(session: CoachingSession, result: CoachingResult) -> str:
|
||||
hashtag = "#лазание" if session.skill == "ЛУ" else "#зоркость"
|
||||
kitten_text = f"{session.kitten_name} [{session.kitten_id}]"
|
||||
@@ -28,8 +48,8 @@ def render_coaching(session: CoachingSession, result: CoachingResult) -> str:
|
||||
f"прокачать {session.skill}.",
|
||||
f"Время: {format_clock(parse_clock(session.start))} – "
|
||||
f"{format_clock(parse_clock(session.end))} [{result.minutes} минут].",
|
||||
f"Баллы белки: {_number(result.escort_points)} баллы.",
|
||||
f"Баллы бельчонка: {_number(result.kitten_points)} баллы.",
|
||||
f"Баллы белки: {_points_phrase(result.escort_points)}.",
|
||||
f"Баллы бельчонка: {_points_phrase(result.kitten_points)}.",
|
||||
]
|
||||
return "\n".join(lines)
|
||||
|
||||
@@ -61,5 +81,5 @@ def render_inspection(report: InspectionReport, result: InspectionResult | None
|
||||
)
|
||||
else:
|
||||
lines.append("0")
|
||||
lines.append(f"Баллы осмотра: {result.points} баллы.")
|
||||
lines.append(f"Баллы осмотра: {_points_phrase(result.points)}.")
|
||||
return "\n".join(lines)
|
||||
+4
-4
@@ -134,8 +134,8 @@ class ReportTests(unittest.TestCase):
|
||||
self.assertIn("#лазание", text)
|
||||
self.assertIn("Дикая Вишня [1604614], помог(-ла) Серолап [1617140] прокачать ЛУ.", text)
|
||||
self.assertIn("Время: 11:00 – 11:20 [20 минут].", text)
|
||||
self.assertIn("Баллы белки: 6 баллы.", text)
|
||||
self.assertIn("Баллы бельчонка: 4 баллы.", text)
|
||||
self.assertIn("Баллы белки: 6 баллов.", text)
|
||||
self.assertIn("Баллы бельчонка: 4 балла.", text)
|
||||
self.assertNotIn("Скриншот", text)
|
||||
self.assertNotIn("истории", text)
|
||||
|
||||
@@ -159,7 +159,7 @@ class ReportTests(unittest.TestCase):
|
||||
self.assertIn("+2 вьюнок.", text)
|
||||
self.assertIn("+1 паук.", text)
|
||||
self.assertNotIn("Скриншот", text)
|
||||
self.assertIn("Баллы осмотра: 15 баллы.", text)
|
||||
self.assertIn("Баллы осмотра: 15 баллов.", text)
|
||||
|
||||
def test_spider_and_web_have_different_values(self):
|
||||
report = InspectionReport(
|
||||
@@ -175,7 +175,7 @@ class ReportTests(unittest.TestCase):
|
||||
resources=(("паутина", 1), ("надпись", 1)),
|
||||
)
|
||||
self.assertEqual(calculate_inspection(report).points, 11)
|
||||
self.assertIn("Баллы осмотра: 11 баллы.", render_inspection(report))
|
||||
self.assertIn("Баллы осмотра: 11 баллов.", render_inspection(report))
|
||||
|
||||
def test_inspection_rejects_negative_resources(self):
|
||||
with self.assertRaises(ValueError):
|
||||
|
||||
@@ -30,7 +30,7 @@ class VkConversationTests(unittest.TestCase):
|
||||
confirmation = self.add_screenshot(dialog, 77)
|
||||
self.assertIn("подтверд", confirmation.lower())
|
||||
report = dialog.handle(77, "да")
|
||||
self.assertIn("Баллы белки: 4 баллы.", report)
|
||||
self.assertIn("Баллы белки: 4 балла.", report)
|
||||
|
||||
def test_step_by_step_coaching_accepts_comma_separated_kittens(self):
|
||||
dialog = BelkiDialog()
|
||||
|
||||
Reference in new issue
Block a user