Implement hard day exclusions for workers and add corresponding tests
This commit is contained in:
+62
-1
@@ -1534,4 +1534,65 @@ def test_force_assign_shift2():
|
||||
assert shift_list[0] == "a", "Worker 0 should have 'a' on 1st Monday"
|
||||
assert shift_list[1] == "a", "Worker 0 should have 'b' on 1st Tuesday"
|
||||
assert shift_list[2] == "a", "Worker 0 should have 'b' on 1st Tuesday"
|
||||
assert shift_list[3] == "a", "Worker 0 should have 'b' on 1st Tuesday"
|
||||
assert shift_list[3] == "a", "Worker 0 should have 'b' on 1st Tuesday"
|
||||
|
||||
|
||||
def test_worker_hard_day_exclusion():
|
||||
Rota = generate_basic_rota(workers=4, weeks_to_rota=16)
|
||||
|
||||
workers = Rota.get_workers()
|
||||
|
||||
for worker in workers:
|
||||
worker.add_hard_day_exclusion({"Mon", "Tue"})
|
||||
|
||||
Rota.add_shifts(
|
||||
SingleShift(
|
||||
sites=("group1",),
|
||||
name="a",
|
||||
length=8,
|
||||
days=days[:5],
|
||||
workers_required=2,
|
||||
assign_as_block=False, # global setting is off
|
||||
),
|
||||
)
|
||||
|
||||
Rota.build_and_solve(options={"ratio": 0.0})
|
||||
Rota.export_rota_to_html("test_worker_hard_day_exclusion", folder="tests")
|
||||
|
||||
for worker in Rota.get_workers():
|
||||
shift_list = Rota.get_worker_shift_list(worker)
|
||||
for week in range(16):
|
||||
mon_idx = week * 7 + days.index("Mon")
|
||||
tue_idx = week * 7 + days.index("Tue")
|
||||
assert not (shift_list[mon_idx] == "a" and shift_list[tue_idx] == "a"), f"Worker {worker.name} has 'a' on both Mon and Tue in week {week}, which should not happen due to hard day exclusion"
|
||||
|
||||
def test_worker_hard_day_exclusion2():
|
||||
Rota = generate_basic_rota(workers=4, weeks_to_rota=16)
|
||||
|
||||
workers = Rota.get_workers()
|
||||
|
||||
for worker in workers:
|
||||
worker.add_hard_day_exclusion({"Sat", "Sun"})
|
||||
|
||||
worker.add_hard_day_dependency({"Fri", "Sun"})
|
||||
|
||||
Rota.add_shifts(
|
||||
SingleShift(
|
||||
sites=("group1",),
|
||||
name="a",
|
||||
length=8,
|
||||
days=days[4:],
|
||||
workers_required=2,
|
||||
assign_as_block=False, # global setting is off
|
||||
),
|
||||
)
|
||||
|
||||
Rota.build_and_solve(options={"ratio": 0.0})
|
||||
Rota.export_rota_to_html("test_worker_hard_day_exclusion", folder="tests")
|
||||
|
||||
for worker in Rota.get_workers():
|
||||
shift_list = Rota.get_worker_shift_list(worker)
|
||||
for week in range(16):
|
||||
sat_idx = week * 7 + days.index("Sat")
|
||||
sun_idx = week * 7 + days.index("Sun")
|
||||
assert not (shift_list[sat_idx] == "a" and shift_list[sun_idx] == "a"), f"Worker {worker.name} has 'a' on both Mon and Tue in week {week}, which should not happen due to hard day exclusion"
|
||||
Reference in New Issue
Block a user