Add tests that lesson-consequence promises were missing.

Teacher action must not cancel gain, a missing warmth need matches full warmth, snow on the street must reach DayPlans, and a lazy pupil still appears closer to the bell.
This commit is contained in:
Leonid Pershin
2026-08-20 17:11:06 +03:00
parent cd68d2e6b8
commit aa20534b77
4 changed files with 135 additions and 1 deletions
@@ -102,6 +102,24 @@ public class LessonTeacherPresentTests
}
}
[Fact]
public void TeacherActionInRoom_StillGains()
{
var (school, homeroom, pupilId, teacherId) = StaffedMath();
using (school)
{
AdvanceTo(school, LessonStart);
SetPlace(school, pupilId, homeroom);
SetPlace(school, teacherId, homeroom);
SetActivity(school, teacherId, "EatLunch");
var before = SkillOf(school, pupilId, "Mathematics");
LessonLearningSystem.Apply(school, 45);
Assert.True(SkillOf(school, pupilId, "Mathematics") > before);
}
}
[Fact]
public void HungryStillGainsLess_WhenTeacherIsPresent()
{
@@ -221,6 +239,30 @@ public class LessonTeacherPresentTests
}
}
[Fact]
public void MissingWarmthNeed_GainsLikeFullWarmth()
{
var (school, homeroom, pupilId, teacherId) = StaffedMath();
using (school)
{
AdvanceTo(school, LessonStart);
SetPlace(school, pupilId, homeroom);
SetPlace(school, teacherId, homeroom);
ClearNeed(school, pupilId, "Warmth");
var start = SkillOf(school, pupilId, "Mathematics");
LessonLearningSystem.Apply(school, 45);
var missingGain = SkillOf(school, pupilId, "Mathematics") - start;
SetSkill(school, pupilId, "Mathematics", start);
SetNeed(school, pupilId, "Warmth", 1f);
LessonLearningSystem.Apply(school, 45);
var warmGain = SkillOf(school, pupilId, "Mathematics") - start;
Assert.True(missingGain > 0);
Assert.Equal(missingGain, warmGain, precision: 5);
}
}
[Fact]
public void Cold_DoesNotLog_WhenTeacherIsAbsent()
{
@@ -394,6 +436,20 @@ public class LessonTeacherPresentTests
});
}
private static void SetActivity(School school, string personId, string actionId)
{
var query = new QueryDescription().WithAll<PersonIdentity, PersonActivity>();
school.World.Query(
in query,
(ref PersonIdentity identity, ref PersonActivity activity) =>
{
if (identity.Id.Equals(personId, StringComparison.Ordinal))
{
activity = new PersonActivity(actionId, Thing: null, RemainingMinutes: 10f);
}
});
}
private static void SetNeed(School school, string personId, string need, float value)
{
var query = new QueryDescription().WithAll<PersonIdentity, PersonNeeds>();
@@ -438,6 +494,20 @@ public class LessonTeacherPresentTests
});
}
private static void ClearNeed(School school, string personId, string need)
{
var query = new QueryDescription().WithAll<PersonIdentity, PersonNeeds>();
school.World.Query(
in query,
(ref PersonIdentity identity, ref PersonNeeds needs) =>
{
if (identity.Id.Equals(personId, StringComparison.Ordinal))
{
needs.Values.Remove(need);
}
});
}
private static void ClearSkill(School school, string personId, string skill)
{
var query = new QueryDescription().WithAll<PersonIdentity, PersonSkills>();