feat(ranking): add RankingPeriodSchedule helper

Pure deterministic monthly period generator for the four ranking
families. Anchor dates derived from prod capture (2026-06-09): id=1 is
each family's launch month in JST; id=N is anchor + N-1 months. Used
by /ranking/get_viewable_ranking_period_list to render the period
picker and by per-family leaderboard endpoints to echo the requested
period back.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-06-10 10:36:51 -04:00
parent b4aa07577f
commit 80f249f8a2
2 changed files with 174 additions and 0 deletions

View File

@@ -0,0 +1,79 @@
using SVSim.EmulatedEntrypoint.Services;
namespace SVSim.UnitTests.Services;
public class RankingPeriodScheduleTests
{
// 2026-06-09 17:00 UTC = 2026-06-10 02:00 JST — clearly in JST's June 2026 month.
private static readonly DateTime CaptureNowUtc =
new(2026, 6, 9, 17, 0, 0, DateTimeKind.Utc);
[Test]
public void RankMatch_at_capture_time_has_current_period_id_122()
{
var list = RankingPeriodSchedule.GenerateFor(
RankingPeriodSchedule.Family.RankMatch, CaptureNowUtc);
Assert.That(list, Is.Not.Empty);
Assert.That(list[0].Id, Is.EqualTo("122"));
Assert.That(list[0].BeginTime, Is.EqualTo("2026-06-01 02:00:00"));
Assert.That(list[0].EndTime, Is.EqualTo("2026-07-01 01:59:59"));
Assert.That(list.Count, Is.EqualTo(122));
}
[Test]
public void MasterPoint_at_capture_time_has_current_period_id_120()
{
var list = RankingPeriodSchedule.GenerateFor(
RankingPeriodSchedule.Family.MasterPoint, CaptureNowUtc);
Assert.That(list[0].Id, Is.EqualTo("120"));
Assert.That(list.Count, Is.EqualTo(120));
}
[Test]
public void TwoPick_at_capture_time_has_current_period_id_119()
{
var list = RankingPeriodSchedule.GenerateFor(
RankingPeriodSchedule.Family.TwoPick, CaptureNowUtc);
Assert.That(list[0].Id, Is.EqualTo("119"));
Assert.That(list.Count, Is.EqualTo(119));
}
[Test]
public void Sealed_at_capture_time_has_current_period_id_62()
{
var list = RankingPeriodSchedule.GenerateFor(
RankingPeriodSchedule.Family.Sealed, CaptureNowUtc);
Assert.That(list[0].Id, Is.EqualTo("62"));
Assert.That(list.Count, Is.EqualTo(62));
}
[Test]
public void Schedule_is_descending_by_id()
{
var list = RankingPeriodSchedule.GenerateFor(
RankingPeriodSchedule.Family.RankMatch, CaptureNowUtc);
for (int i = 1; i < list.Count; i++)
{
Assert.That(int.Parse(list[i - 1].Id), Is.GreaterThan(int.Parse(list[i].Id)),
$"position {i - 1} ({list[i - 1].Id}) should be > position {i} ({list[i].Id})");
}
}
[Test]
public void TryFindById_returns_entry_when_id_in_range()
{
var entry = RankingPeriodSchedule.TryFindById(
RankingPeriodSchedule.Family.RankMatch, periodId: 122, CaptureNowUtc);
Assert.That(entry, Is.Not.Null);
Assert.That(entry!.BeginTime, Is.EqualTo("2026-06-01 02:00:00"));
}
[Test]
public void TryFindById_returns_null_for_unknown_id()
{
var entry = RankingPeriodSchedule.TryFindById(
RankingPeriodSchedule.Family.RankMatch, periodId: 9999, CaptureNowUtc);
Assert.That(entry, Is.Null);
}
}