110 lines
3.9 KiB
C#
110 lines
3.9 KiB
C#
using HSchool.Ai;
|
|
using HSchool.Content;
|
|
using HSchool.People;
|
|
|
|
namespace HSchool.Simulation.Tests;
|
|
|
|
public class WetAftereffectTests
|
|
{
|
|
private static readonly DateTime TuesdayMorning = new(2012, 4, 3, 6, 0, 0, DateTimeKind.Utc);
|
|
|
|
[Fact]
|
|
public void RainArrival_AssignsWetMoreThanClear()
|
|
{
|
|
using var rainSchool = OpenStaffed(seed: 42);
|
|
using var clearSchool = OpenStaffed(seed: 42);
|
|
rainSchool.ForceWeather(new OutdoorWeather(12f, Precipitation.Rain));
|
|
clearSchool.ForceWeather(new OutdoorWeather(12f, Precipitation.None));
|
|
|
|
var rainWet = CountWet(rainSchool);
|
|
var clearWet = CountWet(clearSchool);
|
|
|
|
Assert.True(rainWet > clearWet);
|
|
Assert.True(rainWet > 0);
|
|
}
|
|
|
|
[Fact]
|
|
public void Wet_RaisesRespiratoryOnsetVsDryControl()
|
|
{
|
|
using var wetSchool = OpenStaffed(seed: 7);
|
|
using var drySchool = OpenStaffed(seed: 7);
|
|
wetSchool.ForceWeather(new OutdoorWeather(14f, Precipitation.None));
|
|
drySchool.ForceWeather(new OutdoorWeather(14f, Precipitation.None));
|
|
|
|
foreach (var person in wetSchool.Roster!.People.Where(row => row.IsStudent || row.IsStaff))
|
|
{
|
|
HealthConditions.Add(
|
|
person,
|
|
new HealthCondition
|
|
{
|
|
DefName = DiseaseFamilies.WetDefName,
|
|
Severity = 0.7f,
|
|
Progress = 0f,
|
|
Source = "rain",
|
|
StartedAt = TuesdayMorning,
|
|
});
|
|
}
|
|
|
|
var wetHits = CountRespiratoryOnset(wetSchool);
|
|
var dryHits = CountRespiratoryOnset(drySchool);
|
|
|
|
Assert.True(wetHits > dryHits);
|
|
Assert.True(wetHits > 0);
|
|
}
|
|
|
|
private static int CountWet(School school)
|
|
{
|
|
school.LastDiseaseDay = int.MinValue;
|
|
DiseaseSystem.Apply(school, gameMinutes: 0);
|
|
return school.Roster!.People.Count(person =>
|
|
person.Conditions is not null
|
|
&& person.Conditions.Any(row => row.DefName == DiseaseFamilies.WetDefName));
|
|
}
|
|
|
|
private static int CountRespiratoryOnset(School school)
|
|
{
|
|
school.LastDiseaseDay = int.MinValue;
|
|
DiseaseSystem.Apply(school, gameMinutes: 0);
|
|
return school.Roster!.People.Count(person =>
|
|
person.Conditions is not null
|
|
&& person.Conditions.Any(row =>
|
|
row.DefName is "CommonCold" or "Influenza" or "Otitis"));
|
|
}
|
|
|
|
private static School OpenStaffed(int seed)
|
|
{
|
|
var (catalog, map) = Vanilla();
|
|
var roster = RosterGenerator.Generate(catalog, map, schoolSeed: seed, "Russia", TuesdayMorning);
|
|
var pool = ApplicantPool.Create(catalog, roster, schoolSeed: seed, "Russia", TuesdayMorning);
|
|
var school = School.Create(1, "Мокрый", TuesdayMorning, catalog, map);
|
|
school.InstallPeople(roster, seed: seed, "Russia", pool);
|
|
school.ConfigurePresence(weekDays: 5, maxDecisionsPerTick: 10_000);
|
|
return school;
|
|
}
|
|
|
|
private static (DefCatalog Catalog, MapLayout Map) Vanilla()
|
|
{
|
|
var root = Path.Combine(AppContext.BaseDirectory, "vanilla");
|
|
var documents = new List<ContentDocument>();
|
|
foreach (var path in Directory.EnumerateFiles(root, "*.*", SearchOption.AllDirectories))
|
|
{
|
|
if (!path.EndsWith(".jsonc", StringComparison.OrdinalIgnoreCase)
|
|
&& !path.EndsWith(".json", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var relative = Path.GetRelativePath(root, path).Replace('\\', '/');
|
|
documents.Add(new ContentDocument(
|
|
CatalogLoader.CorePackId,
|
|
relative,
|
|
File.ReadAllText(path)));
|
|
}
|
|
|
|
var catalog = new CatalogLoader().Load([CatalogLoader.CorePackId], documents);
|
|
var map = CatalogLoader.LastDefaultMap([CatalogLoader.CorePackId], documents);
|
|
Assert.NotNull(map);
|
|
return (catalog, map);
|
|
}
|
|
}
|