Files
h-school/tests/HSchool.Simulation.Tests/SchoolTests.cs
T
Leonid Pershin b135a9caad Enhance protocol and simulation features with activity tracking and behavior definitions
- Updated protocol documentation to include new `activity` and `activityLabel` fields in the person card response, reflecting real-time activity status.
- Introduced `BehaviorDef` to define behavior rules, including need thresholds and lesson skill gains, enhancing AI decision-making.
- Revised the `DefCatalog` to incorporate behavior definitions and updated validation logic to ensure proper behavior handling.
- Enhanced the simulation to manage presence and activity states, allowing for more dynamic interactions within the school environment.
- Updated tests to validate the new activity tracking and behavior functionalities, ensuring robust performance and reliability.
- Improved localization strings to support new activity and behavior features, enhancing user experience.
2026-08-19 19:49:44 +03:00

77 lines
3.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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", "abstract": true }"""),
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);
}
}