fix(goal): bound public calculator inputs
This commit is contained in:
1 parent
041d717439
commit
5d6e5987d1
8 files changed
+58
-8
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import unittest
|
||||
from math import inf, nan
|
||||
|
||||
from app.belki.domain import (
|
||||
CoachingSession,
|
||||
@@ -6,6 +7,7 @@ from app.belki.domain import (
|
||||
TrainingSession,
|
||||
calculate_coaching,
|
||||
calculate_inspection,
|
||||
calculate_goal,
|
||||
calculate_training,
|
||||
format_clock,
|
||||
parse_clock,
|
||||
@@ -28,6 +30,17 @@ class ClockTests(unittest.TestCase):
|
||||
|
||||
|
||||
class CalculationTests(unittest.TestCase):
|
||||
def test_goal_rejects_non_finite_and_unbounded_input(self):
|
||||
for current_points, target_points in ((nan, 1), (1, inf)):
|
||||
with self.assertRaisesRegex(ValueError, "конечным числом"):
|
||||
calculate_goal(
|
||||
current_points=current_points, target_points=target_points,
|
||||
minutes_per_session=20, kitten_count=1,
|
||||
)
|
||||
with self.assertRaisesRegex(ValueError, "от 1 до 1440"):
|
||||
calculate_goal(current_points=0, target_points=1, minutes_per_session=1441)
|
||||
with self.assertRaisesRegex(ValueError, "от 1 до 50"):
|
||||
calculate_goal(current_points=0, target_points=1, minutes_per_session=20, kitten_count=51)
|
||||
def test_self_sufficient_kitten(self):
|
||||
result = calculate_coaching(
|
||||
CoachingSession(
|
||||
|
||||
Reference in new issue
Block a user