many improvements

This commit is contained in:
Ross
2022-07-11 19:46:40 +01:00
parent 0cebbfddf6
commit dc975b991c
25 changed files with 1949 additions and 863 deletions
+110 -9
View File
@@ -49,10 +49,7 @@ class TestShifts:
Rota.add_shifts(
SingleShift(
("group1", "group2"),
"a",
12.5,
days,
sites=("group1", "group2"), name="a", length= 12.5, days=days,
),
)
@@ -63,12 +60,116 @@ class TestShifts:
Rota.add_shifts(
SingleShift(
("group1"),
"a",
12.5,
days,
sites=("group1",), name="a", length= 12.5, days=days,
),
)
with pytest.raises(InvalidShift):
Rota.build_and_solve(options={"ratio": 0.000})
Rota.build_and_solve(options={"ratio": 0.000})
class TestShiftConstraints:
def test_max_shifts(self):
Rota = generate_basic_rota()
Rota.add_shifts(
SingleShift(
sites=("group1", "group2"), name="a", length= 12.5, days=days,
constraint=[{"name": "max_shifts_per_week", "options": 4}],
),
)
Rota.build_and_solve(options={"ratio": 0.000})
assert Rota.results.solver.status == "ok"
assert Rota.results.solver.termination_condition == "optimal"
def test_max_shifts_fail(self):
Rota = generate_basic_rota()
Rota.add_shifts(
SingleShift(
sites=("group1", "group2"), name="a", length= 12.5, days=days,
constraint=[{"name": "max_shifts_per_week", "options": 3}],
),
)
Rota.build_and_solve(options={"ratio": 0.000})
assert Rota.results.solver.termination_condition == "infeasible"
Rota.add_worker(
Worker(
name="worker3", site="group1", grade=1,
),
)
Rota.build_and_solve(options={"ratio": 0.000})
assert Rota.results.solver.status == "ok"
assert Rota.results.solver.termination_condition == "optimal"
def test_max_shifts_per_week_block(self):
Rota = generate_basic_rota()
Rota.add_shifts(
SingleShift(
sites=("group1", "group2"), name="a", length= 12.5, days=days,
constraint=[{"name": "max_shifts_per_week_block", "options": {"weeks": 2}}],
),
)
Rota.build_and_solve(options={"ratio": 0.000})
Rota.export_rota_to_html("max_shifts_per_week_block")
assert Rota.results.solver.status == "ok"
assert Rota.results.solver.termination_condition == "optimal"
def test_max_shifts_per_week_block_fail(self):
Rota = generate_basic_rota()
Rota.add_shifts(
SingleShift(
sites=("group1", "group2"), name="a", length= 12.5, days=days,
constraint=[{"name": "max_shifts_per_week_block", "options": {"weeks": 3}}],
),
)
Rota.build_and_solve(options={"ratio": 0.000})
Rota.export_rota_to_html("max_shifts_per_week_block")
assert Rota.results.solver.status == "warning"
def test_max_shifts_per_week_block_shift_number(self):
Rota = generate_basic_rota()
Rota.add_shifts(
SingleShift(
sites=("group1", "group2"), name="a", length= 12.5, days=days,
constraint=[{"name": "max_shifts_per_week_block", "options": {"weeks": 2, "shift_number": 7}}],
),
)
Rota.build_and_solve(options={"ratio": 0.000})
Rota.export_rota_to_html("max_shifts_per_week_block")
assert Rota.results.solver.status == "ok"
def test_max_shifts_per_week_block_shift_number_fail(self):
Rota = generate_basic_rota()
Rota.add_shifts(
SingleShift(
sites=("group1", "group2"), name="a", length= 12.5, days=days,
constraint=[{"name": "max_shifts_per_week_block", "options": {"weeks": 2, "shift_number": 6}}],
),
)
Rota.build_and_solve(options={"ratio": 0.000})
Rota.export_rota_to_html("max_shifts_per_week_block")
assert Rota.results.solver.status == "warning"