Files
h-school/tests/HSchool.Content.Tests/DiseaseDefTests.cs
T
Leonid Pershin 2d633411e4 Add DiseaseDef diseases with weather vectors and excused absence.
Vanilla ships several diseases whose stages drive lesson gain, stay-home
rolls, and illness attendance; cold/rain/snow raise onset via BehaviorDef scale.
2026-08-21 13:28:57 +03:00

78 lines
2.8 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("ОРВИ", catalog.Label("ru", cold));
Assert.Equal("Common cold", catalog.Label("en", cold));
Assert.Equal(1f, catalog.BehaviorRules!.DiseaseVectorScale);
}
[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));
}
}