121 lines
5.3 KiB
C#
121 lines
5.3 KiB
C#
using HSchool.Content;
|
|
using HSchool.People;
|
|
using HSchool.Server.Api;
|
|
using HSchool.Server.Game;
|
|
using HSchool.Simulation;
|
|
|
|
namespace HSchool.Server.Tests;
|
|
|
|
public class PersonCardReaderGradebookTests
|
|
{
|
|
private static readonly DateTime Start = new(2012, 4, 3, 9, 0, 0, DateTimeKind.Utc);
|
|
|
|
[Fact]
|
|
public void Card_ReturnsLessonMarksAndAttendanceInSameOrderAsPerson()
|
|
{
|
|
var (catalog, map) = Vanilla();
|
|
var roster = RosterGenerator.Generate(catalog, map, schoolSeed: 75, "Russia", Start);
|
|
var pupil = roster.People.First(person => person.IsStudent && !person.IsParent);
|
|
var rules = catalog.BehaviorRules!;
|
|
var t0 = new DateTime(2012, 4, 3, 10, 0, 0, DateTimeKind.Utc);
|
|
|
|
Assert.True(LessonMarkMemory.Record(pupil, "Mathematics", 5, t0, period: 1, rules));
|
|
Assert.True(LessonMarkMemory.Record(pupil, "Literature", 3, t0.AddHours(1), period: 2, rules));
|
|
Assert.True(AttendanceMemory.Record(
|
|
pupil, "Mathematics", AttendanceStatuses.Present, t0, period: 1, rules));
|
|
Assert.True(AttendanceMemory.Record(
|
|
pupil, "Literature", AttendanceStatuses.Late, t0.AddHours(1), period: 2, rules));
|
|
Assert.True(AttendanceMemory.Record(
|
|
pupil, "History", AttendanceStatuses.Absent, t0.AddHours(2), period: 3, rules));
|
|
|
|
var school = School.Create(75, "GradebookCard", Start, catalog, map);
|
|
using (school)
|
|
{
|
|
school.InstallPeople(roster, 75, "Russia", ApplicantPool.Empty);
|
|
var card = PersonCardReader.Read(school, pupil.Id, "ru");
|
|
Assert.NotNull(card);
|
|
Assert.NotNull(card!.LessonMarks);
|
|
Assert.NotNull(card.Attendance);
|
|
|
|
Assert.Equal(
|
|
pupil.LessonMarks!.Select(row => (row.Subject, row.Value, row.Period)).ToArray(),
|
|
card.LessonMarks!.Select(row => (row.Subject, row.Value, row.Period)).ToArray());
|
|
Assert.Equal(5, card.LessonMarks[0].Value);
|
|
Assert.Equal("Математика", card.LessonMarks[0].SubjectLabel);
|
|
Assert.Equal(3, card.LessonMarks[1].Value);
|
|
|
|
Assert.Equal(
|
|
pupil.Attendance!.Select(row => (row.Subject, row.Status, row.Period)).ToArray(),
|
|
card.Attendance!.Select(row => (row.Subject, row.Status, row.Period)).ToArray());
|
|
Assert.Equal(AttendanceStatuses.Present, card.Attendance[0].Status);
|
|
Assert.Equal("был", card.Attendance[0].StatusLabel);
|
|
Assert.Equal(AttendanceStatuses.Late, card.Attendance[1].Status);
|
|
Assert.Equal("опоздал", card.Attendance[1].StatusLabel);
|
|
Assert.Equal(AttendanceStatuses.Absent, card.Attendance[2].Status);
|
|
Assert.Equal("отсутствовал", card.Attendance[2].StatusLabel);
|
|
Assert.Equal(AbsenceReasons.Truancy, card.Attendance[2].AbsenceReason);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void Staffing_ClassSlot_SummarisesMarksAndAbsences()
|
|
{
|
|
var (catalog, map) = Vanilla();
|
|
var roster = RosterGenerator.Generate(catalog, map, schoolSeed: 75, "Russia", Start);
|
|
var schoolClass = roster.Classes[0];
|
|
var pupils = roster.People
|
|
.Where(person => person.IsStudent
|
|
&& person.ClassId is { } id
|
|
&& id.Equals(schoolClass.Id, StringComparison.Ordinal))
|
|
.Take(2)
|
|
.ToArray();
|
|
Assert.True(pupils.Length >= 2);
|
|
|
|
var rules = catalog.BehaviorRules!;
|
|
var t0 = new DateTime(2012, 4, 3, 10, 0, 0, DateTimeKind.Utc);
|
|
Assert.True(LessonMarkMemory.Record(pupils[0], "Mathematics", 4, t0, period: 1, rules));
|
|
Assert.True(LessonMarkMemory.Record(pupils[1], "Mathematics", 2, t0, period: 1, rules));
|
|
for (var i = 0; i < 3; i++)
|
|
{
|
|
Assert.True(AttendanceMemory.Record(
|
|
pupils[0],
|
|
"Mathematics",
|
|
AttendanceStatuses.Absent,
|
|
t0.AddDays(i),
|
|
period: 1,
|
|
rules));
|
|
}
|
|
|
|
var staffing = StaffingMapper.From(roster, ApplicantPool.Empty, catalog, Start, allocated: 100_000, "ru");
|
|
var slot = Assert.Single(staffing.Classes, row => row.Id == schoolClass.Id);
|
|
Assert.Equal(3f, slot.AverageMark);
|
|
Assert.Equal(3, slot.AbsentLessons);
|
|
Assert.Equal(1, slot.FrequentAbsentees);
|
|
}
|
|
|
|
private static (DefCatalog Catalog, MapLayout Map) Vanilla()
|
|
{
|
|
var root = Path.Combine(AppContext.BaseDirectory, "vanilla");
|
|
Assert.True(Directory.Exists(root), $"Vanilla pack missing at {root}.");
|
|
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;
|
|
}
|
|
|
|
documents.Add(new ContentDocument(
|
|
CatalogLoader.CorePackId,
|
|
Path.GetRelativePath(root, path).Replace('\\', '/'),
|
|
File.ReadAllText(path)));
|
|
}
|
|
|
|
var catalog = new CatalogLoader().Load([CatalogLoader.CorePackId], documents);
|
|
var map = CatalogLoader.LastDefaultMap([CatalogLoader.CorePackId], documents);
|
|
Assert.NotNull(map);
|
|
return (catalog, map);
|
|
}
|
|
}
|