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
@@ -1,5 +1,7 @@
using HSchool.Ai;
using HSchool.Content;
using HSchool.People;
using HSchool.Schedule;
namespace HSchool.Simulation.Tests;
@@ -73,6 +75,24 @@ public class WeatherTests
Assert.Equal(0, new OutdoorWeather(-5f, Precipitation.Snow).ExtraCommuteMinutes(null));
}
[Fact]
public void SnowOnStreet_PlansAppearEarlierThanClear()
{
// Tick would SyncWeather and overwrite ForceWeather; Apply is the plan-build path.
using var clear = ComingOnTuesday();
using var snow = ComingOnTuesday();
clear.ForceWeather(new OutdoorWeather(8f, Precipitation.None));
snow.ForceWeather(new OutdoorWeather(-5f, Precipitation.Snow));
PresenceSystem.Apply(clear, 1);
PresenceSystem.Apply(snow, 1);
var pupilId = FirstComingPupil(clear);
var extra = clear.Catalog!.BehaviorRules!.CommuteSnowMinutes;
Assert.Equal(6, extra);
Assert.True(clear.Plans[pupilId].Comes);
Assert.Equal(clear.Plans[pupilId].AppearAt!.Value.AddMinutes(-extra), snow.Plans[pupilId].AppearAt);
}
[Fact]
public void SkipEmpty_SetsMondayMorningWeather_NotSaturdays()
{
@@ -103,6 +123,25 @@ public class WeatherTests
Assert.True(room < 18f, $"walls only, got {room}");
}
private static readonly DateTime TuesdayMorning = new(2012, 4, 3, 6, 0, 0, DateTimeKind.Utc);
private static School ComingOnTuesday()
{
var school = Open(TuesdayMorning);
var schoolClass = school.Roster!.Classes.First();
school.SetTimetable(new Timetable(
[new LessonPlacement(schoolClass.Id, "Mathematics", "t1", schoolClass.RoomId, Day: 1, Period: 1)],
[]));
return school;
}
private static string FirstComingPupil(School school)
{
var pupil = school.Roster!.People.First(person =>
person.IsStudent && person.ClassId == school.Timetable!.Lessons[0].ClassId);
return pupil.Id;
}
private static School Open(DateTime start)
{
var (catalog, map) = VanillaMap();