test heavy workload spreading
This commit is contained in:
parent
becd7573c6
commit
85e2c33c31
2 changed files with 35 additions and 7 deletions
|
|
@ -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');
|
$user = $this->createUser('reader@example.com');
|
||||||
$set = $this->createSet($user, 'Course');
|
$set = $this->createSet($user, 'Course');
|
||||||
$lessonLevel = $this->createLevel($set, 'lesson');
|
$lessonLevel = $this->createLevel($set, 'lesson');
|
||||||
$repository = app(ElementRepository::class);
|
$repository = app(ElementRepository::class);
|
||||||
|
|
||||||
foreach (range(1, 5) as $number) {
|
foreach (range(1, 13) as $number) {
|
||||||
$repository->create(new CreateElementDto(
|
$repository->create(new CreateElementDto(
|
||||||
name: "Lesson {$number}",
|
name: "Lesson {$number}",
|
||||||
level: $lessonLevel,
|
level: $lessonLevel,
|
||||||
|
|
@ -269,15 +269,22 @@ class ScheduleEndpointTest extends TestCase
|
||||||
}
|
}
|
||||||
$this->createSession($user, 'valid-token');
|
$this->createSession($user, 'valid-token');
|
||||||
|
|
||||||
$this->credentialedPost('/api/schedules', [
|
$response = $this->credentialedPost('/api/schedules', [
|
||||||
'setId' => $set->getId(),
|
'setId' => $set->getId(),
|
||||||
'levelId' => $lessonLevel->getId(),
|
'levelId' => $lessonLevel->getId(),
|
||||||
'startDate' => '2026-08-10',
|
'startDate' => '2026-08-10',
|
||||||
'targetDate' => '2026-08-13',
|
'targetDate' => '2026-08-14',
|
||||||
'workloadPlacement' => 'spread',
|
'workloadPlacement' => 'spread',
|
||||||
])->assertBadRequest()->assertExactJson([
|
])->assertCreated();
|
||||||
'error' => 'spread placement requires fewer assignments than days',
|
|
||||||
]);
|
$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
|
public function test_it_lists_only_the_users_schedules_newest_first(): void
|
||||||
|
|
|
||||||
|
|
@ -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
|
public function test_it_places_sparse_assignments_at_the_requested_position(): void
|
||||||
{
|
{
|
||||||
$scheduler = new EvenDistributionScheduler;
|
$scheduler = new EvenDistributionScheduler;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue