Add weekly consistency goals
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
using QuestionsApi.Models;
|
||||
using QuestionsApi.Services;
|
||||
using Xunit;
|
||||
|
||||
namespace QuestionsApi.Tests;
|
||||
|
||||
public sealed class WeeklyGoalPolicyTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("2026-08-03", "2026-08-03")]
|
||||
[InlineData("2026-08-09", "2026-08-03")]
|
||||
[InlineData("2026-08-10", "2026-08-10")]
|
||||
public void WeekStartsOnMondayUtc(string value, string expected) =>
|
||||
Assert.Equal(DateTime.Parse(expected).Date, WeeklyGoalStore.WeekStart(DateTime.Parse(value)));
|
||||
|
||||
[Fact]
|
||||
public void ActiveDaysAreDistinctUtcDates()
|
||||
{
|
||||
var values = new[]
|
||||
{
|
||||
new DateTime(2026, 8, 3, 1, 0, 0, DateTimeKind.Utc),
|
||||
new DateTime(2026, 8, 3, 22, 0, 0, DateTimeKind.Utc),
|
||||
new DateTime(2026, 8, 4, 1, 0, 0, DateTimeKind.Utc)
|
||||
};
|
||||
Assert.Equal(2, WeeklyGoalStore.CountActiveDays(values));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0, WeeklyRemediationTypes.HardCorrect, 5)]
|
||||
[InlineData(4, WeeklyRemediationTypes.HardCorrect, 5)]
|
||||
[InlineData(5, WeeklyRemediationTypes.Reviews, 5)]
|
||||
[InlineData(25, WeeklyRemediationTypes.Reviews, 15)]
|
||||
public void RemediationIsFeasibleAndCapped(int available, string type, int target) =>
|
||||
Assert.Equal((type, target), WeeklyGoalStore.ChooseRemediation(available));
|
||||
|
||||
[Fact]
|
||||
public void HardProgressRequiresCorrectEligibleDifficultyFourAttempt()
|
||||
{
|
||||
var system = Step3SystemCatalog.All[0];
|
||||
var start = new DateTime(2026, 8, 3, 0, 0, 0, DateTimeKind.Utc);
|
||||
var goal = new WeeklyGoal { WeekStartUtc = start, ExpiresUtc = start.AddDays(7), EligibleSystems = [system] };
|
||||
var attempt = new QuestionAttempt { IsCorrect = true, CreatedUtc = start.AddDays(1) };
|
||||
var question = new Question { Step3System = system, Difficulty = 4 };
|
||||
Assert.True(WeeklyGoalStore.QualifiesHardAttempt(goal, attempt, question));
|
||||
attempt.IsCorrect = false;
|
||||
Assert.False(WeeklyGoalStore.QualifiesHardAttempt(goal, attempt, question));
|
||||
attempt.IsCorrect = true;
|
||||
question.Difficulty = 3;
|
||||
Assert.False(WeeklyGoalStore.QualifiesHardAttempt(goal, attempt, question));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user