-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(core): Refactor tests to read from csv
- Loading branch information
Showing
8 changed files
with
46 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,29 @@ | ||
import pandas as pd | ||
|
||
from .context import Context | ||
|
||
def get_people_versus_date_dataframe( | ||
dates, people, requirements, | ||
shifts, solver, | ||
): | ||
|
||
def get_people_versus_date_dataframe(ctx: Context, solver): | ||
# Initialize dataframe with size including leading rows and columns | ||
n_leading_rows, n_leading_cols = 2, 1 | ||
df = pd.DataFrame("", index=range(n_leading_rows + len(people)), columns=range(n_leading_cols + len(dates))) | ||
df = pd.DataFrame("", index=range(n_leading_rows + len(ctx.people)), columns=range(n_leading_cols + len(ctx.dates))) | ||
|
||
# Fill day numbers and weekdays | ||
# - row 0 contains day number | ||
# - row 1 contains weekday | ||
for d, date in enumerate(dates): | ||
for d, date in enumerate(ctx.dates): | ||
df.iloc[0, n_leading_cols + d] = date.day | ||
df.iloc[1, n_leading_cols + d] = date.strftime('%a') | ||
|
||
# Fill person descriptions | ||
# - column 0 contains person description | ||
for p, person in enumerate(people): | ||
for p, person in enumerate(ctx.people): | ||
df.iloc[n_leading_rows+p, 0] = person.description | ||
|
||
# Set cell values based on solver results | ||
for (d, r, p) in shifts.keys(): | ||
if solver.Value(shifts[(d, r, p)]) == 1: | ||
for (d, r, p) in ctx.shifts.keys(): | ||
if solver.Value(ctx.shifts[(d, r, p)]) == 1: | ||
assert df.iloc[n_leading_rows+p, n_leading_cols+d] == "" | ||
df.iloc[n_leading_rows+p, n_leading_cols+d] = requirements[r].id | ||
df.iloc[n_leading_rows+p, n_leading_cols+d] = ctx.requirements[r].id | ||
|
||
return df |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,11 @@ | ||
import nurse_scheduling | ||
import pandas as pd | ||
|
||
|
||
def test_example_1(): | ||
filepath = "tests/testcases/example_1.yaml" | ||
df = nurse_scheduling.schedule(filepath, validate=False, deterministic=True) | ||
filepath = "tests/testcases/example_1" | ||
df = nurse_scheduling.schedule(f"{filepath}.yaml", validate=False, deterministic=True) | ||
print(df) | ||
assert df.values.tolist() == [ | ||
['', 18, 19, 20], | ||
['', 'Fri', 'Sat', 'Sun'], | ||
['Nurse 0', 'E', 'E', 'E'], | ||
['Nurse 1', 'D', 'D', 'D'], | ||
['Nurse 2', '', '', ''], | ||
['Nurse 3', 'N', 'N', 'N'] | ||
] | ||
with open(f"{filepath}.csv", 'r') as f: | ||
expected_csv = f.read() | ||
assert df.to_csv(index=False, header=False) == expected_csv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,9 @@ | ||
import nurse_scheduling | ||
|
||
def test_or_tools_example_1(): | ||
filepath = "tests/testcases/or_tools_example_1.yaml" | ||
df = nurse_scheduling.schedule(filepath, validate=False, deterministic=True) | ||
filepath = "tests/testcases/or_tools_example_1" | ||
df = nurse_scheduling.schedule(f"{filepath}.yaml", validate=False, deterministic=True) | ||
print(df) | ||
assert df.values.tolist() == [ | ||
['', 18, 19, 20], | ||
['', 'Fri', 'Sat', 'Sun'], | ||
['Nurse 0', '', 'N', 'D'], | ||
['Nurse 1', 'D', 'E', 'E'], | ||
['Nurse 2', 'E', 'D', ''], | ||
['Nurse 3', 'N', '', 'N'] | ||
] | ||
with open(f"{filepath}.csv", 'r') as f: | ||
expected_csv = f.read() | ||
assert df.to_csv(index=False, header=False) == expected_csv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,9 @@ | ||
import nurse_scheduling | ||
|
||
def test_or_tools_example_2(): | ||
filepath = "tests/testcases/or_tools_example_2.yaml" | ||
df = nurse_scheduling.schedule(filepath, validate=False, deterministic=True) | ||
filepath = "tests/testcases/or_tools_example_2" | ||
df = nurse_scheduling.schedule(f"{filepath}.yaml", validate=False, deterministic=True) | ||
print(df) | ||
assert df.values.tolist() == [ | ||
['', 1, 2, 3, 4, 5, 6, 7], | ||
['', 'Fri', 'Sat', 'Sun', 'Mon', 'Tue', 'Wed', 'Thu'], | ||
['Nurse 0', 'N', '', 'N', '', 'N', 'E', ''], | ||
['Nurse 1', '', '', 'E', 'N', 'D', '', 'N'], | ||
['Nurse 2', 'E', 'E', '', 'D', '', 'N', 'D'], | ||
['Nurse 3', '', 'D', 'D', 'E', '', 'D', ''], | ||
['Nurse 4', 'D', 'N', '', '', 'E', '', 'E'], | ||
] | ||
with open(f"{filepath}.csv", 'r') as f: | ||
expected_csv = f.read() | ||
assert df.to_csv(index=False, header=False) == expected_csv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
,18,19,20 | ||
,Fri,Sat,Sun | ||
Nurse 0,E,E,E | ||
Nurse 1,D,D,D | ||
Nurse 2,,, | ||
Nurse 3,N,N,N |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
,18,19,20 | ||
,Fri,Sat,Sun | ||
Nurse 0,,N,D | ||
Nurse 1,D,E,E | ||
Nurse 2,E,D, | ||
Nurse 3,N,,N |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
,1,2,3,4,5,6,7 | ||
,Fri,Sat,Sun,Mon,Tue,Wed,Thu | ||
Nurse 0,N,,N,,N,E, | ||
Nurse 1,,,E,N,D,,N | ||
Nurse 2,E,E,,D,,N,D | ||
Nurse 3,,D,D,E,,D, | ||
Nurse 4,D,N,,,E,,E |