42 lines
1.4 KiB
PHP
42 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Services;
|
|
|
|
use App\Events\PerceptronTrainingIteration;
|
|
use App\Services\IterationEventBuffer\PerceptronIterationEventBuffer;
|
|
use App\Services\IterationEventBuffer\PerceptronLimitedEpochEventBuffer;
|
|
use Illuminate\Support\Facades\Event;
|
|
use Tests\TestCase;
|
|
|
|
class IterationEventBufferTest extends TestCase
|
|
{
|
|
public function test_iterations_are_sent_as_a_single_batch(): void
|
|
{
|
|
Event::fake();
|
|
$buffer = new PerceptronIterationEventBuffer('session', 'training');
|
|
|
|
$buffer->addIteration(1, 0, 0.5, []);
|
|
$buffer->addIteration(1, 1, 0.25, []);
|
|
$buffer->flush();
|
|
|
|
Event::assertDispatched(PerceptronTrainingIteration::class, function (PerceptronTrainingIteration $event): bool {
|
|
return count($event->iterations) === 2;
|
|
});
|
|
}
|
|
|
|
public function test_limited_buffer_discards_non_selected_epochs(): void
|
|
{
|
|
Event::fake();
|
|
$buffer = new PerceptronLimitedEpochEventBuffer('session', 'training', 2);
|
|
|
|
$buffer->addIteration(1, 0, 0.5, []);
|
|
$buffer->addIteration(2, 0, 0.25, []);
|
|
$buffer->flush();
|
|
|
|
Event::assertDispatched(PerceptronTrainingIteration::class, function (PerceptronTrainingIteration $event): bool {
|
|
return count($event->iterations) === 1
|
|
&& $event->iterations[0]['epoch'] === 1;
|
|
});
|
|
}
|
|
}
|