Enhance school simulation and management by integrating roster functionality, allowing for the installation and persistence of student and staff data. Update the school architecture to include a roster alongside existing components, ensuring proper validation against map layouts. Revise room definitions to support homeroom designations and update related tests to validate new functionalities and ensure robustness in roster handling.
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
namespace HSchool.People;
|
||||
|
||||
/// <summary>
|
||||
/// Whether a generated or loaded roster still fills this map. A mismatch means the file is stale
|
||||
/// relative to the layout — the school must not start and the file must stay untouched.
|
||||
/// </summary>
|
||||
public static class RosterFit
|
||||
{
|
||||
public static bool Matches(Roster roster, SchoolDemand demand)
|
||||
{
|
||||
if (roster.Classes.Count != demand.Classes.Count || roster.People.Count(person => person.IsStudent) != demand.Seats.Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var classesByRoom = roster.Classes.ToDictionary(schoolClass => schoolClass.RoomId, StringComparer.Ordinal);
|
||||
foreach (var expected in demand.Classes)
|
||||
{
|
||||
if (!classesByRoom.TryGetValue(expected.RoomId, out var actual)
|
||||
|| actual.Capacity != expected.Capacity
|
||||
|| actual.PupilIds.Count != expected.Capacity)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
var staffed = roster.People
|
||||
.Where(person => person.IsStaff && person.Position is not null && person.WorkplaceRoomId is not null)
|
||||
.Select(person => new StaffOpening(person.WorkplaceRoomId!, person.Position!))
|
||||
.ToHashSet();
|
||||
|
||||
if (staffed.Count != demand.Staff.Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var opening in demand.Staff)
|
||||
{
|
||||
if (!staffed.Contains(opening))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user