- 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.
77 lines
2.9 KiB
C#
77 lines
2.9 KiB
C#
using HSchool.Content;
|
||
|
||
namespace HSchool.Simulation.Tests;
|
||
|
||
public class SchoolTests
|
||
{
|
||
private static readonly DateTime Start = new(2012, 4, 3, 6, 0, 0, DateTimeKind.Utc);
|
||
|
||
[Fact]
|
||
public void Create_StartsRunningAtTheStartDate()
|
||
{
|
||
using var school = School.Create(1, "Гимназия", Start);
|
||
|
||
Assert.Equal(1, school.Id);
|
||
Assert.Equal("Гимназия", school.Name);
|
||
Assert.Equal(Start, school.Clock.Time);
|
||
Assert.True(school.Clock.IsRunning);
|
||
Assert.Equal(ClockSpeed.DefaultIndex, school.Clock.SpeedIndex);
|
||
}
|
||
|
||
[Fact]
|
||
public void Load_RestoresTimePauseAndSpeed()
|
||
{
|
||
var time = Start.AddHours(3);
|
||
using var school = School.Load(7, "Сейв", time, running: false, speedIndex: 3);
|
||
|
||
Assert.Equal(7, school.Id);
|
||
Assert.Equal("Сейв", school.Name);
|
||
Assert.Equal(time, school.Clock.Time);
|
||
Assert.False(school.Clock.IsRunning);
|
||
Assert.Equal(3, school.Clock.SpeedIndex);
|
||
Assert.Equal(DateTimeKind.Utc, school.Clock.Time.Kind);
|
||
}
|
||
|
||
[Fact]
|
||
public void Load_PausedSchool_DoesNotMoveOnTick()
|
||
{
|
||
using var school = School.Load(1, "Пауза", Start.AddMinutes(12), running: false, speedIndex: 4);
|
||
|
||
school.Tick(1d / 20d, 5d);
|
||
|
||
Assert.Equal(Start.AddMinutes(12), school.Clock.Time);
|
||
}
|
||
|
||
[Fact]
|
||
public void Create_WithACatalogAndMap_KeepsThemOnTheSchool()
|
||
{
|
||
var loader = new CatalogLoader();
|
||
var documents = new[]
|
||
{
|
||
new ContentDocument("core", "defs/actions/sit.jsonc", """{ "defName": "Sit" }"""),
|
||
new ContentDocument("core", "defs/things/chair.jsonc", """{ "defName": "Chair", "actions": ["Sit"] }"""),
|
||
new ContentDocument("core", "defs/territories/yard.jsonc", """{ "defName": "Yard", "travelMinutes": 1 }"""),
|
||
new ContentDocument("core", "defs/buildings/main.jsonc", """{ "defName": "Main" }"""),
|
||
new ContentDocument("core", "defs/floors/floor.jsonc", """{ "defName": "Floor" }"""),
|
||
new ContentDocument("core", "defs/rooms/office.jsonc", """{ "defName": "Office", "travelMinutes": 1 }"""),
|
||
};
|
||
var catalog = loader.Load(["core"], documents);
|
||
var map = new MapLayout
|
||
{
|
||
Territory = new TerritoryNode { Id = "yard", Def = "Yard" },
|
||
Buildings = [new BuildingNode { Id = "main", Def = "Main" }],
|
||
Floors = [new FloorNode { Id = "floor-1", Def = "Floor", Building = "main" }],
|
||
Rooms = [new RoomNode { Id = "office", Def = "Office", Building = "main", Floor = "floor-1" }],
|
||
Links = [new MapLink { A = "yard", B = "office" }],
|
||
};
|
||
MapValidator.Validate(map, catalog);
|
||
|
||
using var school = School.Create(1, "С картой", Start, catalog, map);
|
||
school.Tick(1d / 20d, 5d);
|
||
|
||
Assert.Same(catalog, school.Catalog);
|
||
Assert.Same(map, school.Map);
|
||
Assert.True(school.Clock.Time > Start);
|
||
}
|
||
}
|