Update reviewed phase details, enhance presence tests for hiring and assigning teachers during lessons, and fix timetable handling in the School class. Added new tests for presence management and ensured proper campus staffing behavior during lesson transitions.
This commit is contained in:
@@ -212,6 +212,10 @@ public class GameSocketTests(AppHostFixture fixture)
|
||||
// one person made this test fail under load.
|
||||
await SendAsync(socket, buffer =>
|
||||
ProtocolCodec.WriteSetRunning(buffer, new ClientSetRunningMessage(Running: true)));
|
||||
// Presence still goes out while paused (empty people, lesson labels from the table).
|
||||
// Waiting for people first drains those frames and can spend the 40-frame budget
|
||||
// before the resume even lands. Clock.Running is the signal that time is moving.
|
||||
await ReceiveClockWhereAsync(socket, clock => clock.Running);
|
||||
presence = await ReceivePresenceWhereAsync(socket, frame => frame.People.Count > 0);
|
||||
Assert.All(presence.People, person => Assert.False(string.IsNullOrWhiteSpace(person.NodeId)));
|
||||
Assert.Contains(presence.People, person => directory.People.Any(row => row.Id == person.Id));
|
||||
|
||||
@@ -224,11 +224,87 @@ public class PresenceTests
|
||||
[Fact]
|
||||
public void HireAndAssignMath_DuringLessonThree_PutsSomeoneOnCampus()
|
||||
{
|
||||
var start = new DateTime(2012, 4, 3, 10, 20, 0, DateTimeKind.Utc);
|
||||
using var school = OpenEmpty(start);
|
||||
school.Tick(0.2d, 5d);
|
||||
Assert.True(school.IsCampusEmpty());
|
||||
using var school = UnstaffedDuringLessonThree();
|
||||
HireMathTeacher(school);
|
||||
Assert.True(school.IsCampusEmpty(), "paused ticks must not walk anyone in");
|
||||
|
||||
school.Clock.IsRunning = true;
|
||||
Assert.True(SomeoneWalksIn(school), $"nobody on campus after mid-lesson hire at {school.Clock.Time:HH:mm}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AssigningMath_AfterDayPlansWereBuilt_PutsSomeoneOnCampus()
|
||||
{
|
||||
using var school = UnstaffedDuringLessonThree();
|
||||
var catalog = school.Catalog!;
|
||||
var map = school.Map!;
|
||||
var hired = Staffing.Hire(
|
||||
catalog,
|
||||
map,
|
||||
school.Roster!,
|
||||
school.Applicants!,
|
||||
school.Applicants!.Applicants[0].Person.Id,
|
||||
Staffing.TeacherPosition,
|
||||
Cap);
|
||||
Assert.Equal(StaffingError.None, hired.Error);
|
||||
school.ApplyStaffing(hired.Roster, hired.Pool);
|
||||
school.SetTimetable(SchoolTimetables.Build(catalog, map, hired.Roster, null, weekDays: 5));
|
||||
|
||||
school.Clock.IsRunning = true;
|
||||
school.Tick(1d / 20d, 5d);
|
||||
school.Clock.IsRunning = false;
|
||||
Assert.True(school.IsCampusEmpty(), "a teacher with no subjects still has no reason to come");
|
||||
|
||||
var assigned = Staffing.AssignSubject(
|
||||
catalog,
|
||||
hired.Roster,
|
||||
hired.Pool,
|
||||
hired.Roster.People.Single(person => person.IsStaff).Id,
|
||||
"Mathematics",
|
||||
Cap);
|
||||
Assert.Equal(StaffingError.None, assigned.Error);
|
||||
school.ApplyStaffing(assigned.Roster, assigned.Pool);
|
||||
school.SetTimetable(SchoolTimetables.Build(catalog, map, assigned.Roster, null, weekDays: 5));
|
||||
|
||||
school.Clock.IsRunning = true;
|
||||
Assert.True(
|
||||
SomeoneWalksIn(school),
|
||||
"stale day plans after an assign that did not change headcount left the campus empty");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Simulation_DoesNotReferenceSockets()
|
||||
{
|
||||
var names = typeof(School).Assembly.GetReferencedAssemblies().Select(assembly => assembly.Name!);
|
||||
Assert.DoesNotContain(names, name => name.Contains("Sockets", StringComparison.OrdinalIgnoreCase));
|
||||
Assert.DoesNotContain(names, name => name.Contains("AspNet", StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
private static School UnstaffedDuringLessonThree()
|
||||
{
|
||||
var start = new DateTime(2012, 4, 3, 10, 20, 0, DateTimeKind.Utc);
|
||||
var school = OpenEmpty(start);
|
||||
school.ConfigurePresence(weekDays: 5, maxDecisionsPerTick: 64);
|
||||
school.SetTimetable(SchoolTimetables.Build(school.Catalog!, school.Map!, school.Roster!, null, weekDays: 5));
|
||||
|
||||
var step = 1d / 20d;
|
||||
for (var i = 0; i < 40; i++)
|
||||
{
|
||||
school.Tick(step, 5d);
|
||||
}
|
||||
|
||||
Assert.True(school.IsCampusEmpty());
|
||||
school.Clock.IsRunning = false;
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
school.Tick(step, 5d);
|
||||
}
|
||||
|
||||
return school;
|
||||
}
|
||||
|
||||
private static void HireMathTeacher(School school)
|
||||
{
|
||||
var catalog = school.Catalog!;
|
||||
var map = school.Map!;
|
||||
var hired = Staffing.Hire(
|
||||
@@ -242,25 +318,31 @@ public class PresenceTests
|
||||
Assert.Equal(StaffingError.None, hired.Error);
|
||||
school.ApplyStaffing(hired.Roster, hired.Pool);
|
||||
|
||||
var assigned = Staffing.AssignSubject(catalog, hired.Roster, hired.Pool, hired.Roster.People.Single(person => person.IsStaff).Id, "Mathematics", Cap);
|
||||
var assigned = Staffing.AssignSubject(
|
||||
catalog,
|
||||
hired.Roster,
|
||||
hired.Pool,
|
||||
hired.Roster.People.Single(person => person.IsStaff).Id,
|
||||
"Mathematics",
|
||||
Cap);
|
||||
Assert.Equal(StaffingError.None, assigned.Error);
|
||||
school.ApplyStaffing(assigned.Roster, assigned.Pool);
|
||||
school.SetTimetable(SchoolTimetables.Build(catalog, map, assigned.Roster, null, weekDays: 5));
|
||||
|
||||
for (var i = 0; i < 20; i++)
|
||||
{
|
||||
school.Tick(0.2d, 5d);
|
||||
}
|
||||
|
||||
Assert.Contains(school.CapturePresence(), row => row.NodeId is not null);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Simulation_DoesNotReferenceSockets()
|
||||
private static bool SomeoneWalksIn(School school)
|
||||
{
|
||||
var names = typeof(School).Assembly.GetReferencedAssemblies().Select(assembly => assembly.Name!);
|
||||
Assert.DoesNotContain(names, name => name.Contains("Sockets", StringComparison.OrdinalIgnoreCase));
|
||||
Assert.DoesNotContain(names, name => name.Contains("AspNet", StringComparison.OrdinalIgnoreCase));
|
||||
var step = 1d / 20d;
|
||||
for (var i = 0; i < 400; i++)
|
||||
{
|
||||
school.Tick(step, 5d);
|
||||
if (school.CapturePresence().Any(row => row.NodeId is not null))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static (School School, string Homeroom, string PupilId) StaffedFirstFloorClass()
|
||||
|
||||
Reference in New Issue
Block a user