- Introduced the `HSchool.Ai` project, responsible for routing, day plans, and presence management. - Updated the `HSchool.Simulation` project to integrate with the new AI functionalities, improving decision-making and presence tracking. - Added `travelMinutes` to room and territory definitions, ensuring accurate movement calculations within the simulation. - Enhanced the `School` class to manage presence and implement empty-time skipping functionality. - Updated documentation to reflect the new AI features and their impact on school simulation. - Added tests for presence management and routing to ensure robust functionality and reliability.
187 lines
6.4 KiB
C#
187 lines
6.4 KiB
C#
namespace HSchool.Content.Tests;
|
|
|
|
public class CalendarTests
|
|
{
|
|
private readonly CatalogLoader _loader = new();
|
|
|
|
[Fact]
|
|
public void VanillaCore_LoadsDayFrameAndHolidays()
|
|
{
|
|
var catalog = LoadVanilla();
|
|
var frame = catalog.DayFrame;
|
|
|
|
Assert.NotNull(frame);
|
|
Assert.Equal("08:30", frame.FirstLesson);
|
|
Assert.Equal(7, frame.LessonCount);
|
|
Assert.Equal(45, frame.LessonMinutes);
|
|
Assert.Equal(10, frame.BreakMinutes);
|
|
Assert.Equal(3, frame.LongBreakAfter);
|
|
Assert.Equal(20, frame.LongBreakMinutes);
|
|
Assert.Equal("Учебный день", catalog.Label("ru", frame));
|
|
Assert.Equal("School day", catalog.Label("en", frame));
|
|
Assert.Equal("GymHall", catalog.Subjects["PhysicalEducation"].Room);
|
|
Assert.Equal("ComputerLab", catalog.Subjects["Informatics"].Room);
|
|
Assert.Null(catalog.Subjects["Mathematics"].Room);
|
|
Assert.True(catalog.Holidays.ContainsKey("SpringBreak"));
|
|
Assert.Equal(24, catalog.Holidays["SpringBreak"].Start.Day);
|
|
Assert.Equal(31, catalog.Holidays["SpringBreak"].End.Day);
|
|
}
|
|
|
|
[Fact]
|
|
public void Saturday_IsOutsideOnAFiveDayWeek()
|
|
{
|
|
var slot = SchoolDay.At(LoadVanilla(), new DateTime(2012, 3, 31, 10, 20, 0, DateTimeKind.Utc), weekDays: 5);
|
|
|
|
Assert.Equal(DaySlot.Outside, slot);
|
|
}
|
|
|
|
[Fact]
|
|
public void Holiday_IsOutsideEvenOnASevenDayWeek()
|
|
{
|
|
var slot = SchoolDay.At(LoadVanilla(), new DateTime(2012, 3, 31, 10, 20, 0, DateTimeKind.Utc), weekDays: 7);
|
|
|
|
Assert.Equal(DaySlot.Outside, slot);
|
|
}
|
|
|
|
[Fact]
|
|
public void WeekdaySchoolMorning_IsLessonThree()
|
|
{
|
|
var slot = SchoolDay.At(LoadVanilla(), new DateTime(2012, 4, 3, 10, 20, 0, DateTimeKind.Utc), weekDays: 5);
|
|
|
|
Assert.Equal(DaySlot.Lesson(3), slot);
|
|
}
|
|
|
|
[Fact]
|
|
public void WeekdayNight_IsOutside()
|
|
{
|
|
var slot = SchoolDay.At(LoadVanilla(), new DateTime(2012, 4, 3, 23, 0, 0, DateTimeKind.Utc), weekDays: 5);
|
|
|
|
Assert.Equal(DaySlot.Outside, slot);
|
|
}
|
|
|
|
[Fact]
|
|
public void SixDayWeek_MakesANonHolidaySaturdayASchoolDay()
|
|
{
|
|
var slot = SchoolDay.At(LoadVanilla(), new DateTime(2012, 4, 7, 10, 20, 0, DateTimeKind.Utc), weekDays: 6);
|
|
|
|
Assert.Equal(DaySlot.Lesson(3), slot);
|
|
}
|
|
|
|
[Fact]
|
|
public void WinterBreak_WrapsTheNewYear()
|
|
{
|
|
var catalog = LoadVanilla();
|
|
var inside = SchoolDay.At(catalog, new DateTime(2012, 1, 5, 10, 20, 0, DateTimeKind.Utc), weekDays: 5);
|
|
var after = SchoolDay.At(catalog, new DateTime(2012, 1, 16, 10, 20, 0, DateTimeKind.Utc), weekDays: 5);
|
|
|
|
Assert.Equal(DaySlot.Outside, inside);
|
|
Assert.Equal(DaySlot.Lesson(3), after);
|
|
}
|
|
|
|
[Fact]
|
|
public void BreakAfterLessonTwo_IsTenFifteen()
|
|
{
|
|
var slot = SchoolDay.At(LoadVanilla(), new DateTime(2012, 4, 3, 10, 15, 0, DateTimeKind.Utc), weekDays: 5);
|
|
|
|
Assert.Equal(DaySlot.BreakAfter(2), slot);
|
|
}
|
|
|
|
[Fact]
|
|
public void NextWorkMorning_FromSaturdayLandsOnMondaySix()
|
|
{
|
|
var catalog = LoadVanilla();
|
|
var next = SchoolDay.NextWorkMorning(catalog, new DateTime(2012, 4, 7, 10, 0, 0, DateTimeKind.Utc), weekDays: 5);
|
|
|
|
Assert.Equal(new DateTime(2012, 4, 9, 6, 0, 0, DateTimeKind.Utc), next);
|
|
}
|
|
|
|
[Fact]
|
|
public void NextWorkMorning_FromTuesdayNightLandsOnThatMorning()
|
|
{
|
|
var catalog = LoadVanilla();
|
|
var next = SchoolDay.NextWorkMorning(catalog, new DateTime(2012, 4, 3, 3, 0, 0, DateTimeKind.Utc), weekDays: 5);
|
|
|
|
Assert.Equal(new DateTime(2012, 4, 3, 6, 0, 0, DateTimeKind.Utc), next);
|
|
}
|
|
|
|
[Fact]
|
|
public void NextWorkMorning_FromTuesdayEveningLandsOnWednesday()
|
|
{
|
|
var catalog = LoadVanilla();
|
|
var next = SchoolDay.NextWorkMorning(catalog, new DateTime(2012, 4, 3, 22, 0, 0, DateTimeKind.Utc), weekDays: 5);
|
|
|
|
Assert.Equal(new DateTime(2012, 4, 4, 6, 0, 0, DateTimeKind.Utc), next);
|
|
}
|
|
|
|
[Fact]
|
|
public void InWorkWindow_SevenOnAWorkday_IsAlreadyOpen()
|
|
{
|
|
var catalog = LoadVanilla();
|
|
var seven = new DateTime(2012, 4, 3, 7, 0, 0, DateTimeKind.Utc);
|
|
|
|
Assert.True(SchoolDay.IsWorkday(catalog, seven, weekDays: 5));
|
|
Assert.True(SchoolDay.InWorkWindow(catalog, seven, weekDays: 5));
|
|
}
|
|
|
|
[Fact]
|
|
public void InWorkWindow_DoesNotNeedTeachers()
|
|
{
|
|
var catalog = LoadVanilla();
|
|
var morning = new DateTime(2012, 4, 3, 10, 0, 0, DateTimeKind.Utc);
|
|
|
|
Assert.True(SchoolDay.InWorkWindow(catalog, morning, weekDays: 5));
|
|
}
|
|
|
|
[Fact]
|
|
public void Subject_UnknownRoom_FailsTheCatalog()
|
|
{
|
|
var ex = Assert.Throws<ContentLoadException>(() => _loader.Load(
|
|
[CatalogLoader.CorePackId],
|
|
[
|
|
PackDocuments.Def(CatalogLoader.CorePackId, "skills", "math", """{ "defName": "Mathematics" }"""),
|
|
PackDocuments.Def(
|
|
CatalogLoader.CorePackId,
|
|
"subjects",
|
|
"pe",
|
|
"""
|
|
{
|
|
"defName": "PhysicalEducation",
|
|
"grades": { "min": 1, "max": 11 },
|
|
"hoursPerWeek": 3,
|
|
"room": "GhostHall",
|
|
"skills": [{ "skill": "Mathematics", "share": 1 }]
|
|
}
|
|
"""),
|
|
]));
|
|
|
|
Assert.Contains("GhostHall", ex.Message);
|
|
}
|
|
|
|
[Fact]
|
|
public void TwoConcreteDayFrames_FailTheCatalog()
|
|
{
|
|
var ex = Assert.Throws<ContentLoadException>(() => _loader.Load(
|
|
[CatalogLoader.CorePackId],
|
|
[
|
|
PackDocuments.Def(
|
|
CatalogLoader.CorePackId,
|
|
"dayframe",
|
|
"a",
|
|
"""{ "defName": "A", "firstLesson": "08:30", "lessonCount": 1, "lessonMinutes": 45 }"""),
|
|
PackDocuments.Def(
|
|
CatalogLoader.CorePackId,
|
|
"dayframe",
|
|
"b",
|
|
"""{ "defName": "B", "firstLesson": "08:30", "lessonCount": 1, "lessonMinutes": 45 }"""),
|
|
]));
|
|
|
|
Assert.Contains("DayFrameDef", ex.Message);
|
|
}
|
|
|
|
private DefCatalog LoadVanilla()
|
|
{
|
|
var root = Path.Combine(AppContext.BaseDirectory, "vanilla");
|
|
return _loader.Load([CatalogLoader.CorePackId], PackDocuments.FromDirectory(CatalogLoader.CorePackId, root));
|
|
}
|
|
}
|