Add opinions storage, morning drift, and Connections card tab.
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
using HSchool.Content;
|
||||
using HSchool.People;
|
||||
using HSchool.Schedule;
|
||||
|
||||
namespace HSchool.Simulation.Tests;
|
||||
|
||||
public class MorningOpinionsTests
|
||||
{
|
||||
private static readonly DateTime TuesdayMorning = new(2012, 4, 3, 6, 0, 0, DateTimeKind.Utc);
|
||||
private static readonly DateTime TuesdayEvening = new(2012, 4, 3, 22, 0, 0, DateTimeKind.Utc);
|
||||
private static readonly DateTime WednesdayMorning = new(2012, 4, 4, 6, 0, 0, DateTimeKind.Utc);
|
||||
|
||||
[Fact]
|
||||
public void SeveralWorkMornings_DriftClassmateTowardZero_FamilyTowardStart()
|
||||
{
|
||||
using var school = OpenStaffed();
|
||||
var child = school.Roster!.People.First(person => person.IsStudent && !person.IsParent);
|
||||
var classmate = school.Roster.People.First(person =>
|
||||
person.IsStudent
|
||||
&& !person.Id.Equals(child.Id, StringComparison.Ordinal)
|
||||
&& !OpinionStore.FamilyMemberIds(school.Roster, child).Contains(person.Id));
|
||||
var family = school.Roster.Families.Single(row => row.Id.Equals(child.FamilyId, StringComparison.Ordinal));
|
||||
var parentId = family.ParentIds[0];
|
||||
var rules = school.Catalog!.BehaviorRules!;
|
||||
|
||||
OpinionStore.Set(child, classmate.Id, 30);
|
||||
OpinionStore.Set(child, parentId, rules.OpinionChildToParentStart - 15);
|
||||
|
||||
AdvanceTo(school, TuesdayEvening);
|
||||
for (var day = 0; day < 3; day++)
|
||||
{
|
||||
while (school.Clock.Time < WednesdayMorning.AddDays(day))
|
||||
{
|
||||
school.Tick(0.2d, 5d);
|
||||
}
|
||||
}
|
||||
|
||||
Assert.True(child.Opinions.TryGetValue(classmate.Id, out var classmateView));
|
||||
Assert.True(classmateView < 30);
|
||||
Assert.True(classmateView <= 30 - rules.OpinionDriftPerMorning);
|
||||
|
||||
Assert.True(child.Opinions.TryGetValue(parentId, out var parentView));
|
||||
Assert.True(parentView > rules.OpinionChildToParentStart - 15);
|
||||
Assert.True(parentView <= rules.OpinionChildToParentStart);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SkipEmpty_AppliesOpinionDrift()
|
||||
{
|
||||
using var school = OpenEmpty(TuesdayEvening);
|
||||
var child = school.Roster!.People.First(person => person.IsStudent && !person.IsParent);
|
||||
var classmate = school.Roster.People.First(person =>
|
||||
person.IsStudent
|
||||
&& !person.Id.Equals(child.Id, StringComparison.Ordinal)
|
||||
&& !OpinionStore.FamilyMemberIds(school.Roster, child).Contains(person.Id));
|
||||
|
||||
OpinionStore.Set(child, classmate.Id, 12);
|
||||
var before = child.Opinions[classmate.Id];
|
||||
|
||||
Assert.True(school.TrySkipEmpty().Succeeded);
|
||||
|
||||
Assert.True(child.Opinions.TryGetValue(classmate.Id, out var after));
|
||||
Assert.True(after < before);
|
||||
}
|
||||
|
||||
private static void AdvanceTo(School school, DateTime until)
|
||||
{
|
||||
while (school.Clock.Time < until)
|
||||
{
|
||||
school.Tick(0.2d, 5d);
|
||||
}
|
||||
}
|
||||
|
||||
private static School OpenStaffed()
|
||||
{
|
||||
var (catalog, map) = Vanilla();
|
||||
var roster = RosterGenerator.Generate(catalog, map, schoolSeed: 1, "Russia", TuesdayMorning);
|
||||
var pool = ApplicantPool.Create(catalog, roster, schoolSeed: 1, "Russia", TuesdayMorning);
|
||||
var school = School.Create(1, "Мнения", TuesdayMorning, catalog, map);
|
||||
school.InstallPeople(roster, seed: 1, "Russia", pool);
|
||||
school.ConfigurePresence(weekDays: 5, maxDecisionsPerTick: 10_000);
|
||||
return school;
|
||||
}
|
||||
|
||||
private static School OpenEmpty(DateTime start)
|
||||
{
|
||||
var (catalog, map) = Vanilla();
|
||||
var roster = RosterGenerator.Generate(catalog, map, schoolSeed: 1, "Russia", start);
|
||||
var pool = ApplicantPool.Create(catalog, roster, schoolSeed: 1, "Russia", start);
|
||||
var school = School.Create(1, "Мнения ночь", start, catalog, map);
|
||||
school.InstallPeople(roster, seed: 1, "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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user