Enhance family and roster management in school simulation by implementing support for incomplete families, ensuring proper handling of absent parents while maintaining surname consistency. Update family creation logic to account for single-parent households and revise child identification to prevent ID conflicts. Introduce seat shuffling to prevent siblings from being placed in the same class, improving the realism of student distribution. Update related tests to validate these new functionalities and ensure robustness in family and roster handling.
ci / server (push) Failing after 3m49s
ci / client (push) Successful in 24s

This commit is contained in:
Leonid Pershin
2026-08-18 21:13:16 +03:00
parent 7f6852548d
commit 3366e8e44b
19 changed files with 766 additions and 90 deletions
@@ -12,11 +12,18 @@ public class RosterGeneratorTests
Assert.Equal(Snapshot(a), Snapshot(b));
}
/// <summary>
/// Each family draws from its own seeded stream, so a bigger map does not reshuffle the
/// families already planned: the first twelve keep their surname, their size and every given
/// name. What a bigger map does move is which classroom a child sits in — seats are dealt
/// across the whole school so siblings are not automatically classmates — and with the
/// classroom comes the year, hence the birth year. That is the one thing not asserted here.
/// </summary>
[Fact]
public void ThirteenthFamily_DoesNotChangeTheFirstTwelve()
public void ThirteenthFamily_DoesNotChangeHowTheFirstTwelveAreDrawn()
{
var twelve = FamilySnapshots(Fixtures.Generate(Fixtures.Classrooms(4)), take: 12);
var thirteen = FamilySnapshots(Fixtures.Generate(Fixtures.Classrooms(5)), take: 12);
var twelve = FamilyIdentities(Fixtures.Generate(Fixtures.Classrooms(4)), take: 12);
var thirteen = FamilyIdentities(Fixtures.Generate(Fixtures.Classrooms(5)), take: 12);
Assert.Equal(12, twelve.Count);
Assert.Equal(twelve, thirteen);
@@ -35,20 +42,31 @@ public class RosterGeneratorTests
continue;
}
var father = people[family.ParentIds[0]];
var mother = people[family.ParentIds[1]];
Assert.False(father.Female);
Assert.True(mother.Female);
// One parent may be absent, so the father's name comes off the family, not off a person.
var parents = family.ParentIds.Select(id => people[id]).ToArray();
Assert.NotEmpty(parents);
Assert.Equal(parents.Length, parents.DistinctBy(parent => parent.Female).Count());
Assert.NotEmpty(family.FatherGiven);
foreach (var parent in parents)
{
Assert.Equal(parent.Name.SurnameCases.Nom, parent.Name.Surname);
}
foreach (var childId in family.ChildIds)
{
var child = people[childId];
Assert.Equal(
NameGrammar.Patronymic(father.Name.Given, child.Female, NameGrammar.SlavicPatronymic),
NameGrammar.Patronymic(family.FatherGiven, child.Female, NameGrammar.SlavicPatronymic),
child.Name.Patronymic);
Assert.Equal(child.Female ? mother.Name.Surname : father.Name.Surname, child.Name.Surname);
Assert.Equal(father.Name.SurnameCases.Nom, father.Name.Surname);
Assert.Equal(mother.Name.SurnameCases.Nom, mother.Name.Surname);
var sameSexParent = parents.FirstOrDefault(parent => parent.Female == child.Female);
if (sameSexParent is not null)
{
Assert.Equal(sameSexParent.Name.Surname, child.Name.Surname);
}
Assert.Equal(child.Name.SurnameCases.Nom, child.Name.Surname);
}
}
}
@@ -167,6 +185,22 @@ public class RosterGeneratorTests
private static string Skills(Person person) =>
string.Join(',', person.Skills.OrderBy(pair => pair.Key, StringComparer.Ordinal).Select(pair => $"{pair.Key}={pair.Value}"));
/// <summary>Who a family is, without where its children ended up sitting.</summary>
private static List<string> FamilyIdentities(Roster roster, int take)
{
var people = roster.People.ToDictionary(person => person.Id, StringComparer.Ordinal);
return roster.Families
.OrderBy(family => family.Id, StringComparer.Ordinal)
.Take(take)
.Select(family =>
{
var members = family.ParentIds.Concat(family.ChildIds).Select(id => people[id]);
return string.Join(';', members.Select(person =>
$"{person.Id}:{person.Name.Surname} {person.Name.Given} {person.Name.Patronymic}:{person.Female}"));
})
.ToList();
}
private static List<string> FamilySnapshots(Roster roster, int take)
{
var people = roster.People.ToDictionary(person => person.Id, StringComparer.Ordinal);