Files
h-school/tests/HSchool.Content.Tests/DiseaseDefTests.cs
T
Leonid Pershin b314f50112 Wire sick-teacher stay-home into cancelled lessons.
Heavy flu keeps the assigned teacher off the day plan; pupils get 48/73 no-teacher marks and a one-shot LessonCancelled notice instead of silent empty rooms.
2026-08-21 14:17:37 +03:00

95 lines
4.1 KiB
C#

using HSchool.Content;
namespace HSchool.Content.Tests;
public class DiseaseDefTests
{
private readonly CatalogLoader _loader = new();
[Fact]
public void VanillaCore_LoadsSeveralDiseases()
{
var catalog = LoadVanilla();
Assert.True(catalog.Diseases.ContainsKey("CommonCold"));
Assert.True(catalog.Diseases.ContainsKey("Influenza"));
Assert.True(catalog.Diseases.ContainsKey("StomachBug"));
Assert.True(catalog.Diseases.ContainsKey("Otitis"));
var cold = catalog.Diseases["CommonCold"];
Assert.Equal(DiseaseFamilies.Respiratory, cold.Family);
Assert.Equal(5f, cold.ColdBelowC);
Assert.True(cold.Stages.Count >= 2);
Assert.Equal(0.5f, cold.IncubationDays);
Assert.Equal(14f, cold.ImmunityDays);
Assert.Equal(0.55f, cold.NodeContagionChancePerDay);
Assert.Equal(0.25f, cold.ClassContagionChancePerDay);
Assert.True(cold.ContagiousDuringIncubation);
Assert.Equal(0f, catalog.Diseases["Otitis"].NodeContagionChancePerDay);
Assert.Equal(0f, catalog.Diseases["Otitis"].ClassContagionChancePerDay);
Assert.Equal("ОРВИ", catalog.Label("ru", cold));
Assert.Equal("Common cold", catalog.Label("en", cold));
Assert.Equal(1f, catalog.BehaviorRules!.DiseaseVectorScale);
Assert.Equal(3, catalog.BehaviorRules.DiseaseOutbreakMinNewCases);
Assert.True(catalog.Events.ContainsKey("DiseaseOutbreak"));
Assert.Equal(EventTriggers.DiseaseOutbreak, catalog.Events["DiseaseOutbreak"].Trigger);
Assert.Equal("В школе распространяется болезнь", catalog.Label("ru", catalog.Events["DiseaseOutbreak"]));
Assert.True(catalog.Events.ContainsKey("LessonCancelled"));
Assert.Equal(EventTriggers.LessonNoTeacher, catalog.Events["LessonCancelled"].Trigger);
Assert.Equal(EventSeverities.Info, catalog.Events["LessonCancelled"].Severity);
Assert.False(catalog.Events["LessonCancelled"].Pause);
Assert.Equal(8000, catalog.Events["LessonCancelled"].TtlMs);
Assert.Equal("Урок без учителя", catalog.Label("ru", catalog.Events["LessonCancelled"]));
Assert.Equal("Lesson without a teacher", catalog.Label("en", catalog.Events["LessonCancelled"]));
}
[Fact]
public void MissingFamily_FailsTheCatalog()
{
var documents = PackDocuments.FromDirectory(
CatalogLoader.CorePackId,
Path.Combine(AppContext.BaseDirectory, "vanilla"))
.Append(PackDocuments.Def(
CatalogLoader.CorePackId,
"diseases",
"bad",
"""
{
"defName": "BadDisease",
"incubationDays": 1,
"immunityDays": 1,
"stages": [{ "minSeverity": 0, "severityPerDay": 0.1, "progressPerDay": 0.1 }]
}
"""))
.ToList();
var ex = Assert.Throws<ContentLoadException>(() => _loader.Load([CatalogLoader.CorePackId], documents));
Assert.Contains("family", ex.Message, StringComparison.OrdinalIgnoreCase);
}
[Fact]
public void MissingStages_FailsTheCatalog()
{
var documents = PackDocuments.FromDirectory(
CatalogLoader.CorePackId,
Path.Combine(AppContext.BaseDirectory, "vanilla"))
.Append(PackDocuments.Def(
CatalogLoader.CorePackId,
"diseases",
"bad-stages",
"""{ "defName": "NoStages", "family": "respiratory", "incubationDays": 0, "immunityDays": 1 }"""))
.ToList();
var ex = Assert.Throws<ContentLoadException>(() => _loader.Load([CatalogLoader.CorePackId], documents));
Assert.Contains("stages", ex.Message, StringComparison.OrdinalIgnoreCase);
}
private DefCatalog LoadVanilla()
{
var root = Path.Combine(AppContext.BaseDirectory, "vanilla");
return _loader.Load([CatalogLoader.CorePackId], PackDocuments.FromDirectory(CatalogLoader.CorePackId, root));
}
}