133 lines
4.7 KiB
C#
133 lines
4.7 KiB
C#
using HSchool.Content;
|
|
|
|
namespace HSchool.People.Tests;
|
|
|
|
public class WetAftereffectTests
|
|
{
|
|
[Fact]
|
|
public void HeavyDisease_LeavesAftereffectThatClears()
|
|
{
|
|
var catalog = LoadVanilla();
|
|
var started = new DateTime(2012, 4, 3, 8, 0, 0, DateTimeKind.Utc);
|
|
var person = Blank("p1");
|
|
HealthConditions.Add(
|
|
person,
|
|
new HealthCondition
|
|
{
|
|
DefName = "Influenza",
|
|
Severity = 0.85f,
|
|
Progress = 0.99f,
|
|
Source = "cold",
|
|
StartedAt = started,
|
|
});
|
|
|
|
Assert.True(HealthConditions.Tick(
|
|
person,
|
|
peopleSeed: 3,
|
|
dayNumber: 50,
|
|
gameMinutes: 24 * 60,
|
|
catalog,
|
|
started.AddDays(3)));
|
|
|
|
Assert.NotNull(person.Conditions);
|
|
Assert.Contains(person.Conditions!, row => row.DefName == DiseaseFamilies.AftereffectDefName);
|
|
Assert.DoesNotContain(person.Conditions!, row => row.DefName == "Influenza");
|
|
Assert.True(DiseaseImmunities.IsImmune(person, "Influenza", started.AddDays(4)));
|
|
|
|
// Aftereffect clears on its stage curve within a few game days — not a year-long chronicle.
|
|
for (var day = 0; day < 14 && person.Conditions is { Count: > 0 }; day++)
|
|
{
|
|
HealthConditions.Tick(
|
|
person,
|
|
peopleSeed: 3,
|
|
dayNumber: 51 + day,
|
|
gameMinutes: 24 * 60,
|
|
catalog,
|
|
started.AddDays(4 + day));
|
|
}
|
|
|
|
Assert.True(
|
|
person.Conditions is null
|
|
|| person.Conditions.All(row => row.DefName != DiseaseFamilies.AftereffectDefName));
|
|
}
|
|
|
|
[Fact]
|
|
public void RosterJson_RoundTripsWetAndAftereffect()
|
|
{
|
|
var roster = Fixtures.Generate(Fixtures.Classrooms(4));
|
|
var pupil = roster.People.First(person => person.IsStudent && !person.IsParent);
|
|
var started = new DateTime(2012, 4, 3, 9, 0, 0, DateTimeKind.Utc);
|
|
HealthConditions.Add(
|
|
pupil,
|
|
new HealthCondition
|
|
{
|
|
DefName = DiseaseFamilies.WetDefName,
|
|
Severity = 0.6f,
|
|
Progress = 0.1f,
|
|
Source = "rain",
|
|
StartedAt = started,
|
|
});
|
|
HealthConditions.Add(
|
|
pupil,
|
|
new HealthCondition
|
|
{
|
|
DefName = DiseaseFamilies.AftereffectDefName,
|
|
Severity = 0.4f,
|
|
Progress = 0.2f,
|
|
Source = "Influenza",
|
|
StartedAt = started.AddDays(-1),
|
|
});
|
|
|
|
var json = RosterJson.Serialize(RosterDocument.From(1, roster));
|
|
Assert.Contains($"\"defName\": \"{DiseaseFamilies.WetDefName}\"", json, StringComparison.Ordinal);
|
|
Assert.Contains($"\"defName\": \"{DiseaseFamilies.AftereffectDefName}\"", json, StringComparison.Ordinal);
|
|
|
|
var loaded = RosterJson.Parse(json).ToRoster();
|
|
var loadedPupil = loaded.People.First(person => person.Id.Equals(pupil.Id, StringComparison.Ordinal));
|
|
Assert.NotNull(loadedPupil.Conditions);
|
|
Assert.Equal(2, loadedPupil.Conditions!.Count);
|
|
Assert.Contains(loadedPupil.Conditions, row => row.DefName == DiseaseFamilies.WetDefName && row.Source == "rain");
|
|
Assert.Contains(
|
|
loadedPupil.Conditions,
|
|
row => row.DefName == DiseaseFamilies.AftereffectDefName && row.Source == "Influenza");
|
|
}
|
|
|
|
private static DefCatalog LoadVanilla()
|
|
{
|
|
var root = Path.Combine(AppContext.BaseDirectory, "vanilla");
|
|
return new CatalogLoader().Load(
|
|
[CatalogLoader.CorePackId],
|
|
PackDocuments.FromDirectory(CatalogLoader.CorePackId, root));
|
|
}
|
|
|
|
private static Person Blank(string id)
|
|
{
|
|
var cases = new CaseTable
|
|
{
|
|
Nom = id,
|
|
Gen = id,
|
|
Dat = id,
|
|
Acc = id,
|
|
Ins = id,
|
|
Pre = id,
|
|
};
|
|
return new Person
|
|
{
|
|
Id = id,
|
|
FamilyId = "f",
|
|
Female = false,
|
|
BirthDate = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc),
|
|
Name = new PersonName(id, id, id, cases, cases, cases),
|
|
IsStudent = true,
|
|
IsStaff = false,
|
|
IsParent = false,
|
|
Numbers = new Dictionary<string, int>(StringComparer.Ordinal),
|
|
Choices = new Dictionary<string, string>(StringComparer.Ordinal),
|
|
Skills = new Dictionary<string, int>(StringComparer.Ordinal),
|
|
Traits = [],
|
|
Needs = new Dictionary<string, float>(StringComparer.Ordinal),
|
|
Opinions = new Dictionary<string, int>(StringComparer.Ordinal),
|
|
};
|
|
}
|
|
}
|