feat: add Belichya Nora calculator and VK bot
This commit is contained in:
1 parent
cd6a594ed4
commit
c86d077f9f
20 files changed
+2002
-18
No files matched your search
@@ -0,0 +1,115 @@
|
||||
import unittest
|
||||
|
||||
from app.belki.domain import (
|
||||
CoachingSession,
|
||||
InspectionReport,
|
||||
TrainingSession,
|
||||
calculate_coaching,
|
||||
calculate_training,
|
||||
format_clock,
|
||||
parse_clock,
|
||||
)
|
||||
from app.belki.reports import render_coaching, render_inspection, render_training
|
||||
|
||||
|
||||
class ClockTests(unittest.TestCase):
|
||||
def test_duration_supports_midnight(self):
|
||||
self.assertEqual(parse_clock("23:55"), 23 * 60 + 55)
|
||||
self.assertEqual(format_clock(parse_clock("23:05")), "23:05")
|
||||
self.assertEqual(
|
||||
CoachingSession.duration_minutes("23:55", "00:10"),
|
||||
15,
|
||||
)
|
||||
|
||||
def test_invalid_clock_is_rejected(self):
|
||||
with self.assertRaises(ValueError):
|
||||
parse_clock("5:5")
|
||||
|
||||
|
||||
class CalculationTests(unittest.TestCase):
|
||||
def test_self_sufficient_kitten(self):
|
||||
result = calculate_coaching(
|
||||
CoachingSession(
|
||||
date="15.08",
|
||||
skill="ЛУ",
|
||||
start="00:52",
|
||||
end="01:52",
|
||||
escort_name="Дикая Вишня",
|
||||
escort_id=1604614,
|
||||
kitten_name="Котёнок",
|
||||
kitten_id=1676767,
|
||||
kitten_independence="самостоятельно",
|
||||
)
|
||||
)
|
||||
self.assertEqual(result.minutes, 60)
|
||||
self.assertEqual(result.escort_points, 12)
|
||||
self.assertEqual(result.kitten_points, 24)
|
||||
|
||||
def test_non_self_kitten_and_extra_companion(self):
|
||||
result = calculate_coaching(
|
||||
CoachingSession(
|
||||
date="15.08",
|
||||
skill="ЗУ",
|
||||
start="11:00",
|
||||
end="12:00",
|
||||
escort_name="Белка",
|
||||
escort_id=1,
|
||||
kitten_name="Первый",
|
||||
kitten_id=2,
|
||||
kitten_independence="несамостоятельно",
|
||||
extra_kittens=(
|
||||
("Второй", 3, "несамостоятельно"),
|
||||
("Третий", 4, "самостоятельно"),
|
||||
),
|
||||
)
|
||||
)
|
||||
self.assertEqual(result.escort_points, 24)
|
||||
self.assertEqual(result.kitten_points, 24)
|
||||
|
||||
def test_training_is_fixed(self):
|
||||
self.assertEqual(calculate_training(TrainingSession("Белка", 1, "Котёнок", 2)).points, 25)
|
||||
|
||||
|
||||
class ReportTests(unittest.TestCase):
|
||||
def test_coaching_report_contains_new_fields_and_reminder(self):
|
||||
session = CoachingSession(
|
||||
date="15.08",
|
||||
skill="ЛУ",
|
||||
start="11:00",
|
||||
end="11:20",
|
||||
escort_name="Дикая Вишня",
|
||||
escort_id=1604614,
|
||||
kitten_name="Серолап",
|
||||
kitten_id=1617140,
|
||||
kitten_independence="несамостоятельно",
|
||||
)
|
||||
text = render_coaching(session, calculate_coaching(session))
|
||||
self.assertIn("15.08 [ЛУ]", text)
|
||||
self.assertIn("Время: 11:00–11:20 [20 минут]", text)
|
||||
self.assertIn("Сопровождающий: Дикая Вишня [1604614]", text)
|
||||
self.assertIn("Баллы белки: 6", text)
|
||||
self.assertIn("Баллы бельчонка: 8", text)
|
||||
self.assertIn("истории", text)
|
||||
|
||||
def test_training_report_is_separate(self):
|
||||
text = render_training(TrainingSession("Белка", 1, "Котёнок", 2))
|
||||
self.assertIn("#урок", text)
|
||||
self.assertIn("25", text)
|
||||
|
||||
def test_inspection_report_lists_zero_and_resources(self):
|
||||
text = render_inspection(
|
||||
InspectionReport(
|
||||
character_name="Дикая Вишня",
|
||||
character_id=1604614,
|
||||
place="дупло",
|
||||
inspections=6,
|
||||
resources=(("вьюнок", -2), ("паук", 1)),
|
||||
)
|
||||
)
|
||||
self.assertIn("осмотрел(а) дупло 6 раз", text)
|
||||
self.assertIn("- 2 вьюнок", text)
|
||||
self.assertIn("+1 паук", text)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user