Skip to content

Commit

Permalink
Do not allow zero as max credits
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJiahao committed May 11, 2023
1 parent 9ee5b6d commit aff4b00
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/services/scheduler_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def max_credits(self) -> int:

@max_credits.setter
def max_credits(self, max_credits: int) -> None:
if max_credits < 0:
raise MaxCreditError("Opintopisteyläraja ei voi olla negatiivinen.")
if max_credits <= 0:
raise MaxCreditError("Opintopisteyläraja ei voi olla ei-positiivinen.")

for course in self.__courses.values():
if course.credits > max_credits:
Expand Down
8 changes: 6 additions & 2 deletions src/tests/services/test_scheduler_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,13 @@ def test_max_credits(self):
scheduler = SchedulerService(courses)

scheduler.max_credits = 3
scheduler.max_credits = 2
scheduler.max_credits = 4
scheduler.max_credits = 100

def test_max_credits_with_non_positive_value_raises_error(self):
with self.assertRaises(MaxCreditError):
self.scheduler.max_credits = 0

def test_negative_max_credits_raises_error(self):
with self.assertRaises(MaxCreditError):
self.scheduler.max_credits = -10

Expand Down

0 comments on commit aff4b00

Please sign in to comment.