Refactor and optimizations
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?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;
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user