Files
h-school/tests/HSchool.Simulation.Tests/SchoolTests.cs
T

77 lines
2.9 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" }"""),
new ContentDocument("core", "defs/things/chair.jsonc", """{ "defName": "Chair", "actions": ["Sit"] }"""),
new ContentDocument("core", "defs/territories/yard.jsonc", """{ "defName": "Yard" }"""),
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" }"""),
};
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);
}
}