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:
@@ -30,7 +30,8 @@
|
|||||||
|
|
||||||
## Критерий готовности
|
## Критерий готовности
|
||||||
|
|
||||||
- Снежным утром класс наполняется позже, чем ясным; ленивый по-прежнему ближе к звонку
|
- Снежным утром `AppearAt` раньше на `commuteSnowMinutes` (запас на дорогу, не более медленная
|
||||||
|
ходьба); ленивый по-прежнему ближе к звонку
|
||||||
- `dotnet test` проходит
|
- `dotnet test` проходит
|
||||||
|
|
||||||
## Стоп
|
## Стоп
|
||||||
|
|||||||
@@ -162,6 +162,30 @@ public class WalkingTests
|
|||||||
Assert.True(implied.Comes);
|
Assert.True(implied.Comes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Lazy_AppearsCloserToTheBell_OnSnow()
|
||||||
|
{
|
||||||
|
var (catalog, map) = Fixtures.Vanilla();
|
||||||
|
var walks = WalkGraph.Build(catalog, map);
|
||||||
|
var roster = RosterGenerator.Generate(catalog, map, schoolSeed: 9, "Russia", TuesdayLesson);
|
||||||
|
var lazy = roster.People.First(person => person.IsStudent && person.Traits.Contains("Lazy"));
|
||||||
|
var schoolClass = roster.Classes.First(row => row.Id == lazy.ClassId);
|
||||||
|
var keen = roster.People.First(person =>
|
||||||
|
person.IsStudent && person.ClassId == lazy.ClassId && !person.Traits.Contains("Lazy"));
|
||||||
|
var table = new Timetable(
|
||||||
|
[new LessonPlacement(schoolClass.Id, "Mathematics", "t1", schoolClass.RoomId, Day: 1, Period: 1)],
|
||||||
|
[]);
|
||||||
|
var extra = catalog.BehaviorRules!.CommuteSnowMinutes;
|
||||||
|
var lazyPlan = DayPlans.Build(
|
||||||
|
catalog, walks, lazy, schoolClass, table, TuesdayLesson, weekDays: 5, schoolSeed: 9, extra);
|
||||||
|
var keenPlan = DayPlans.Build(
|
||||||
|
catalog, walks, keen, schoolClass, table, TuesdayLesson, weekDays: 5, schoolSeed: 9, extra);
|
||||||
|
|
||||||
|
Assert.True(lazyPlan.Comes);
|
||||||
|
Assert.True(keenPlan.Comes);
|
||||||
|
Assert.True(lazyPlan.AppearAt > keenPlan.AppearAt);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void SameSeedAndSnowMinutes_YieldTheSameAppearAt()
|
public void SameSeedAndSnowMinutes_YieldTheSameAppearAt()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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]
|
[Fact]
|
||||||
public void HungryStillGainsLess_WhenTeacherIsPresent()
|
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]
|
[Fact]
|
||||||
public void Cold_DoesNotLog_WhenTeacherIsAbsent()
|
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)
|
private static void SetNeed(School school, string personId, string need, float value)
|
||||||
{
|
{
|
||||||
var query = new QueryDescription().WithAll<PersonIdentity, PersonNeeds>();
|
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)
|
private static void ClearSkill(School school, string personId, string skill)
|
||||||
{
|
{
|
||||||
var query = new QueryDescription().WithAll<PersonIdentity, PersonSkills>();
|
var query = new QueryDescription().WithAll<PersonIdentity, PersonSkills>();
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
using HSchool.Ai;
|
||||||
using HSchool.Content;
|
using HSchool.Content;
|
||||||
using HSchool.People;
|
using HSchool.People;
|
||||||
|
using HSchool.Schedule;
|
||||||
|
|
||||||
namespace HSchool.Simulation.Tests;
|
namespace HSchool.Simulation.Tests;
|
||||||
|
|
||||||
@@ -73,6 +75,24 @@ public class WeatherTests
|
|||||||
Assert.Equal(0, new OutdoorWeather(-5f, Precipitation.Snow).ExtraCommuteMinutes(null));
|
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]
|
[Fact]
|
||||||
public void SkipEmpty_SetsMondayMorningWeather_NotSaturdays()
|
public void SkipEmpty_SetsMondayMorningWeather_NotSaturdays()
|
||||||
{
|
{
|
||||||
@@ -103,6 +123,25 @@ public class WeatherTests
|
|||||||
Assert.True(room < 18f, $"walls only, got {room}");
|
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)
|
private static School Open(DateTime start)
|
||||||
{
|
{
|
||||||
var (catalog, map) = VanillaMap();
|
var (catalog, map) = VanillaMap();
|
||||||
|
|||||||
Reference in New Issue
Block a user