Skip to content

Commit 95d8cfd

Browse files
committed
Increase tests coverage
1 parent a3f31a8 commit 95d8cfd

File tree

3 files changed

+41
-23
lines changed

3 files changed

+41
-23
lines changed

processscheduler/resource.py

-8
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,6 @@ def __init__(self, name: str, productivity: Optional[int] = 0) -> None:
4444
raise TypeError('productivity must be an integer >= 0')
4545
self.productivity = productivity
4646

47-
# Necessary to define _eq__ and __hash__ because of lgtm warnings of kind
48-
def __hash__(self) -> int:
49-
return self.uid
50-
51-
def __eq__(self, other) -> Bool:
52-
return self.uid == other.uid
53-
54-
5547
class AlternativeWorkers(_Resource):
5648
""" Class representing the selection of n workers chosen among a list
5749
of possible workers """

processscheduler/task.py

+12-11
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,6 @@ def __init__(self, name: str) -> None:
5555
# optional flag, set to True if this task is optional, else True
5656
self.optional = False
5757

58-
# Necessary to define _eq__ and __hash__ because of lgtm warnings of kind
59-
def __hash__(self) -> int:
60-
return self.uid
61-
62-
def __eq__(self, other) -> Bool:
63-
return self.uid == other.uid
64-
6558
def set_optional(self):
6659
self.optional = True
6760

@@ -145,15 +138,23 @@ def __init__(self, name: str,
145138
length_at_most: Optional[int] = None,
146139
work_amount: Optional[int] = 0):
147140
super().__init__(name)
141+
142+
if is_positive_integer(length_at_most):
143+
self.add_assertion(self.duration <= length_at_most)
144+
elif length_at_most is not None:
145+
raise TypeError('length_as_most should either be a positive integer or None')
146+
147+
if not is_positive_integer(length_at_least):
148+
raise TypeError('length_at_least must be a positive integer')
149+
150+
if not is_positive_integer(work_amount):
151+
raise TypeError('work_amount me be a positive integer')
152+
148153
self.length_at_least = length_at_least
149154
self.length_at_most = length_at_most
150155
self.work_amount = work_amount
151156

152157
# set minimal duration
153158
self.add_assertion(self.duration >= length_at_least)
154-
155-
if length_at_most is not None:
156-
self.add_assertion(self.duration <= length_at_most)
157-
158159
# add an assertion: end = start + duration
159160
self.add_assertion(self.start + self.duration == self.end)

test/test_features.py

+29-4
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,22 @@ def test_create_task_fixed_duration(self) -> None:
6060
ps.FixedDurationTask('NegativeWorkAmount', 2, work_amount=-3)
6161

6262
def test_create_task_variable_duration(self) -> None:
63-
task = ps.VariableDurationTask('vdt')
64-
self.assertIsInstance(task, ps.VariableDurationTask)
65-
63+
ps.VariableDurationTask('vdt1')
64+
ps.VariableDurationTask('vdt2', length_at_most=4)
65+
ps.VariableDurationTask('vdt3', length_at_least=4)
66+
ps.VariableDurationTask('vdt21', work_amount=10)
67+
with self.assertRaises(TypeError):
68+
ps.VariableDurationTask('vdt3', length_at_most=4.5)
69+
with self.assertRaises(TypeError):
70+
ps.VariableDurationTask('vdt4', length_at_most=-1)
71+
with self.assertRaises(TypeError):
72+
ps.VariableDurationTask('vdt5', length_at_least=-1)
73+
with self.assertRaises(TypeError):
74+
ps.VariableDurationTask('vdt6', work_amount=-1)
75+
with self.assertRaises(TypeError):
76+
ps.VariableDurationTask('vdt7', work_amount=1.5)
77+
with self.assertRaises(TypeError):
78+
ps.VariableDurationTask('vdt8', work_amount=None)
6679
#
6780
# Workers
6881
#
@@ -94,7 +107,7 @@ def test_eq_overloading(self) -> None:
94107
self.assertEqual(task_1, task_1)
95108
self.assertNotEqual(task_1, task_2)
96109

97-
def test_redondnt_tasks_resources(self) -> None:
110+
def test_redondant_tasks_resources(self) -> None:
98111
pb = ps.SchedulingProblem('ProblemRedundantTaskResource')
99112
# we should not be able to add twice the same resource or task
100113
task_1 = ps.ZeroDurationTask('task1')
@@ -124,6 +137,18 @@ def test_redondnt_tasks_resources(self) -> None:
124137
pb.add_resource(2.0)
125138
self.assertEqual(list(pb.get_resources()), [worker_1])
126139

140+
def test_resource_requirements(self) -> None:
141+
task_1 = ps.FixedDurationTask('task1', duration=3)
142+
worker_1 = ps.Worker('Worker1')
143+
worker_2 = ps.Worker('Worker1')
144+
worker_3 = ps.Worker('Worker1')
145+
task_1.add_required_resource(worker_1)
146+
task_1.add_required_resources([worker_1, worker_2])
147+
with self.assertRaises(TypeError):
148+
task_1.add_required_resource(3)
149+
with self.assertRaises(TypeError):
150+
task_1.add_required_resources("a_string")
151+
127152
#
128153
# Single task constraints
129154
#

0 commit comments

Comments
 (0)