formatting of execises

This commit is contained in:
2024-02-05 09:54:13 +01:00
parent e17d23f92a
commit c54518ed65
4 changed files with 56 additions and 10 deletions

View File

@@ -1,6 +1,6 @@
import functools
import multiprocessing
from typing import Callable, Iterator
from typing import Callable, Iterable, Iterator
class TimeoutException(Exception):
@@ -43,7 +43,7 @@ def run_tests_for_task(task: type) -> None:
run_tests_for_task(task)
def points_to_detuct(e: type | Callable) -> int:
def points_to_deduct(e: type | Callable) -> int:
match e:
case type() if hasattr(e, 'is_task'):
to_detuct = 0
@@ -51,7 +51,7 @@ def points_to_detuct(e: type | Callable) -> int:
if hasattr(test, 'is_test'):
to_detuct += test.to_deduct()
for task in e.tasks:
to_detuct += points_to_detuct(task)
to_detuct += points_to_deduct(task)
return e.max_points if to_detuct > e.max_points else to_detuct
case Callable(test):
return test.to_detuct()
@@ -76,6 +76,23 @@ class Exercise(object):
self.run_tests()
self.deduct_points()
@property
def id(self) -> str:
return self.__id
@property
def max_points(self) -> float:
return self.__max_points
@property
def points(self) -> float:
return self.__points
@property
def tasks(self) -> Iterable[object]:
return self.__tasks
def run_tests(self):
for task in self.__tasks:
@@ -83,7 +100,7 @@ class Exercise(object):
def deduct_points(self):
for task in self.__tasks:
to_detuct = points_to_detuct(task)
to_detuct = points_to_deduct(task)
task.points = 0 if to_detuct > task.max_points else task.max_points - to_detuct
self.__points = functools.reduce(
lambda a, b: a + b, map(lambda t: t.points, self.__tasks), 0.0)