Merge branch 'phase/78-diseases'
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user