test heavy workload spreading

This commit is contained in:
Yisroel Baum 2026-08-20 08:19:54 +03:00
parent becd7573c6
commit 85e2c33c31
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
2 changed files with 35 additions and 7 deletions

View file

@ -253,14 +253,14 @@ class ScheduleEndpointTest extends TestCase
]);
}
public function test_it_rejects_spread_placement_for_a_dense_schedule(): void
public function test_it_spreads_heavier_days_across_the_full_range(): void
{
$user = $this->createUser('reader@example.com');
$set = $this->createSet($user, 'Course');
$lessonLevel = $this->createLevel($set, 'lesson');
$repository = app(ElementRepository::class);
foreach (range(1, 5) as $number) {
foreach (range(1, 13) as $number) {
$repository->create(new CreateElementDto(
name: "Lesson {$number}",
level: $lessonLevel,
@ -269,15 +269,22 @@ class ScheduleEndpointTest extends TestCase
}
$this->createSession($user, 'valid-token');
$this->credentialedPost('/api/schedules', [
$response = $this->credentialedPost('/api/schedules', [
'setId' => $set->getId(),
'levelId' => $lessonLevel->getId(),
'startDate' => '2026-08-10',
'targetDate' => '2026-08-13',
'targetDate' => '2026-08-14',
'workloadPlacement' => 'spread',
])->assertBadRequest()->assertExactJson([
'error' => 'spread placement requires fewer assignments than days',
]);
])->assertCreated();
$days = $response->json('schedule.days');
$this->assertIsArray($days);
$this->assertSame(
[3, 2, 3, 2, 3],
array_map(function (array $day): int {
return count($day['assignments']);
}, $days),
);
}
public function test_it_lists_only_the_users_schedules_newest_first(): void

View file

@ -60,6 +60,27 @@ class EvenDistributionSchedulerTest extends TestCase
}
}
public function test_it_spreads_heavier_days_across_the_full_range(): void
{
$scheduler = new EvenDistributionScheduler;
$expectedCounts = [
11 => [2, 2, 3, 2, 2],
12 => [3, 2, 2, 2, 3],
13 => [3, 2, 3, 2, 3],
];
foreach ($expectedCounts as $assignmentCount => $dailyCounts) {
$dates = $scheduler->scheduledDates(
assignmentCount: $assignmentCount,
startDate: $this->utc('2026-08-10'),
targetDate: $this->utc('2026-08-14'),
workloadPlacement: WorkloadPlacement::Spread,
);
$this->assertSame($dailyCounts, $this->dailyCounts($dates));
}
}
public function test_it_places_sparse_assignments_at_the_requested_position(): void
{
$scheduler = new EvenDistributionScheduler;