New math fixes, again
This commit is contained in:
1 parent
92605e7a4d
commit
ec5a1a197a
5 files changed
+130
-62
No files matched your search
+38
-5
@@ -47,7 +47,7 @@ class CalculationTests(unittest.TestCase):
|
||||
self.assertEqual(result.kitten_points, 12)
|
||||
|
||||
def test_non_self_kitten_and_extra_companion(self):
|
||||
result = calculate_coaching(
|
||||
with self.assertRaisesRegex(ValueError, "Все котята"):
|
||||
CoachingSession(
|
||||
date="15.08",
|
||||
skill="ЗУ",
|
||||
@@ -63,9 +63,6 @@ class CalculationTests(unittest.TestCase):
|
||||
("Третий", 4, "самостоятельно"),
|
||||
),
|
||||
)
|
||||
)
|
||||
self.assertEqual(result.escort_points, 20.7)
|
||||
self.assertEqual(result.kitten_points, 12)
|
||||
|
||||
def test_non_self_30_minutes_matches_calculator(self):
|
||||
result = calculate_coaching(
|
||||
@@ -81,7 +78,7 @@ class CalculationTests(unittest.TestCase):
|
||||
kitten_independence="несамостоятельно",
|
||||
)
|
||||
)
|
||||
self.assertEqual(result.escort_points, 6)
|
||||
self.assertEqual(result.escort_points, 9)
|
||||
self.assertEqual(result.kitten_points, 6)
|
||||
|
||||
def test_non_self_60_minutes_gives_adult_18_and_kitten_12(self):
|
||||
@@ -113,6 +110,42 @@ class CalculationTests(unittest.TestCase):
|
||||
self.assertEqual(result.escort_multiplier, 1.725)
|
||||
self.assertEqual(result.escort_points, 20.7)
|
||||
|
||||
def test_nonself_additional_ward_adds_half_base_bonus(self):
|
||||
result = calculate_coaching(
|
||||
CoachingSession(
|
||||
"15.08", "ЛУ", "10:00", "10:55", "Белка", 1, "Первый", 2,
|
||||
kitten_independence="несамостоятельно",
|
||||
extra_kittens=(("Второй", 3, "несамостоятельно"),),
|
||||
)
|
||||
)
|
||||
self.assertEqual(result.escort_points, 27.5)
|
||||
self.assertEqual(result.kitten_points, 11)
|
||||
|
||||
def test_two_nonself_wards_add_two_bonuses(self):
|
||||
result = calculate_coaching(
|
||||
CoachingSession(
|
||||
"15.08", "ЛУ", "10:00", "10:55", "Белка", 1, "Первый", 2,
|
||||
kitten_independence="несамостоятельно",
|
||||
extra_kittens=(("Второй", 3, "несамостоятельно"),),
|
||||
)
|
||||
)
|
||||
self.assertEqual(result.escort_points, 27.5)
|
||||
|
||||
def test_zu_independence_matrix_matches_reported_values(self):
|
||||
def points(primary, extra):
|
||||
return calculate_coaching(
|
||||
CoachingSession(
|
||||
"16.08", "ЗУ", "10:00", "11:00", "Белка", 1, "Первый", 2,
|
||||
kitten_independence=primary,
|
||||
extra_kittens=(("Второй", 3, extra),),
|
||||
)
|
||||
).escort_points
|
||||
|
||||
self.assertEqual(points("самостоятельно", "самостоятельно"), 18)
|
||||
with self.assertRaisesRegex(ValueError, "Все котята"):
|
||||
points("самостоятельно", "несамостоятельно")
|
||||
self.assertEqual(points("несамостоятельно", "несамостоятельно"), 30)
|
||||
|
||||
def test_training_is_fixed(self):
|
||||
self.assertEqual(calculate_training(TrainingSession("Белка", 1, "Котёнок", 2)).points, 25)
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ from datetime import datetime
|
||||
from tempfile import TemporaryDirectory
|
||||
|
||||
from app.belki.identity import Identity, IdentityDirectory
|
||||
from app.belki.vk_bot import HELP_TEXT, BelkiDialog, inspect_bulk_text
|
||||
from app.belki.vk_bot import HELP_TEXT, BelkiDialog, inspect_bulk_text, parse_text_command
|
||||
|
||||
|
||||
class VkConversationTests(unittest.TestCase):
|
||||
@@ -62,6 +62,14 @@ class VkConversationTests(unittest.TestCase):
|
||||
self.assertIn("Котёнок 2: Малыш [123456]", dialog._confirmation(dialog._states[80]))
|
||||
self.assertIn("самостоятель", response.lower())
|
||||
|
||||
def test_multiple_kittens_reject_mixed_independence_status(self):
|
||||
dialog = BelkiDialog()
|
||||
dialog.handle(81, "/лу")
|
||||
for answer in ("15.08", "11:00", "12:00", "Дикая Вишня [1604614]"):
|
||||
dialog.handle(81, answer)
|
||||
response = dialog.handle(81, "Беззубик [1] самостоятельно, Малыш [2] несамостоятельно")
|
||||
self.assertIn("Все котята", response)
|
||||
|
||||
def test_bulk_input_is_detected_and_confirmed(self):
|
||||
dialog = BelkiDialog()
|
||||
confirmation = dialog.handle(
|
||||
@@ -255,6 +263,20 @@ class VkConversationTests(unittest.TestCase):
|
||||
dialog.handle(502, answer)
|
||||
self.assertIn("скриншот", dialog.handle(502, "несам").lower())
|
||||
|
||||
def test_compact_command_accepts_all_independence_variants(self):
|
||||
for value, expected in (
|
||||
("сам", "самостоятельно"),
|
||||
("самостоятельный", "самостоятельно"),
|
||||
("самостоятельно", "самостоятельно"),
|
||||
("несам", "несамостоятельно"),
|
||||
("несамостоятельный", "несамостоятельно"),
|
||||
("несамостоятельно", "несамостоятельно"),
|
||||
):
|
||||
parsed = parse_text_command(
|
||||
f"/зу 16.08 10:00 10:10 | Белка [1] | Малыш [2] | {value}"
|
||||
)
|
||||
self.assertEqual(parsed["kitten_independence"], expected)
|
||||
|
||||
def test_keyboard_changes_with_dialog_state(self):
|
||||
dialog = BelkiDialog()
|
||||
menu = dialog.keyboard_for(503)
|
||||
|
||||
Reference in new issue
Block a user