Skip to content

Commit

Permalink
Sync circular-buffer (#770)
Browse files Browse the repository at this point in the history
[no important files changed]
  • Loading branch information
fejan-malek authored Jul 7, 2024
1 parent a1f3b20 commit aa57a00
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 25 deletions.
22 changes: 0 additions & 22 deletions exercises/practice/circular-buffer/.meta/example.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
<?php

/*
* By adding type hints and enabling strict type checking, code can become
* easier to read, self-documenting and reduce the number of potential bugs.
* By default, type declarations are non-strict, which means they will attempt
* to change the original type to match the type specified by the
* type-declaration.
*
* In other words, if you pass a string to a function requiring a float,
* it will attempt to convert the string value to a float.
*
* To enable strict mode, a single declare directive must be placed at the top
* of the file.
* This means that the strictness of typing is configured on a per-file basis.
* This directive not only affects the type declarations of parameters, but also
* a function's return type.
*
* For more info review the Concept on strict type checking in the PHP track
* <link>.
*
* To disable strict typing, comment out the directive below.
*/

declare(strict_types=1);

class BufferFullError extends Exception
Expand Down
20 changes: 17 additions & 3 deletions exercises/practice/circular-buffer/CircularBufferTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
class CircularBufferTest extends TestCase
{
/**
* @testdox reading empty buffer should fail
* uuid: 28268ed4-4ff3-45f3-820e-895b44d53dfa
*/
public function testReadingEmptyBufferShouldFail(): void
Expand All @@ -19,6 +20,7 @@ public function testReadingEmptyBufferShouldFail(): void
}

/**
* @testdox can read an item just written
* uuid: 2e6db04a-58a1-425d-ade8-ac30b5f318f3
*/
public function testCanReadAnItemJustWritten(): void
Expand All @@ -29,6 +31,7 @@ public function testCanReadAnItemJustWritten(): void
}

/**
* @testdox each item may only be read once
* uuid: 90741fe8-a448-45ce-be2b-de009a24c144
*/
public function testEachItemMayOnlyBeReadOnce(): void
Expand All @@ -41,6 +44,7 @@ public function testEachItemMayOnlyBeReadOnce(): void
}

/**
* @testdox items are read in the order they are written
* uuid: be0e62d5-da9c-47a8-b037-5db21827baa7
*/
public function testItemsAreReadInTheOrderTheyAreWritten(): void
Expand All @@ -53,6 +57,7 @@ public function testItemsAreReadInTheOrderTheyAreWritten(): void
}

/**
* @testdox full buffer can't be written to
* uuid: 2af22046-3e44-4235-bfe6-05ba60439d38
*/
public function testFullBufferCantBeWrittenTo(): void
Expand All @@ -64,6 +69,7 @@ public function testFullBufferCantBeWrittenTo(): void
}

/**
* @testdox a read frees up capacity for another write
* uuid: 547d192c-bbf0-4369-b8fa-fc37e71f2393
*/
public function testAReadFreesUpCapacityForAnotherWrite(): void
Expand All @@ -76,6 +82,7 @@ public function testAReadFreesUpCapacityForAnotherWrite(): void
}

/**
* @testdox read position is maintained even across multiple writes
* uuid: 04a56659-3a81-4113-816b-6ecb659b4471
*/
public function testReadPositionIsMaintainedEvenAcrossMultipleWrites(): void
Expand All @@ -90,6 +97,7 @@ public function testReadPositionIsMaintainedEvenAcrossMultipleWrites(): void
}

/**
* @testdox items cleared out of buffer can't be read
* uuid: 60c3a19a-81a7-43d7-bb0a-f07242b1111f
*/
public function testItemsClearedOutOfBufferCantBeRead(): void
Expand All @@ -102,6 +110,7 @@ public function testItemsClearedOutOfBufferCantBeRead(): void
}

/**
* @testdox clear frees up capacity for another write
* uuid: 45f3ae89-3470-49f3-b50e-362e4b330a59
*/
public function testClearFreesUpCapacityForAnotherWrite(): void
Expand All @@ -114,6 +123,7 @@ public function testClearFreesUpCapacityForAnotherWrite(): void
}

/**
* @testdox clear does nothing on empty buffer
* uuid: e1ac5170-a026-4725-bfbe-0cf332eddecd
*/
public function testClearDoesNothingOnEmptyBuffer(): void
Expand All @@ -125,9 +135,10 @@ public function testClearDoesNothingOnEmptyBuffer(): void
}

/**
* @testdox overwrite acts like write on non-full buffer
* uuid: 9c2d4f26-3ec7-453f-a895-7e7ff8ae7b5b
*/
public function testForceWriteActsLikeWriteOnNonFullBuffer(): void
public function testOverwriteActsLikeWriteOnNonFullBuffer(): void
{
$buffer = new CircularBuffer(2);
$buffer->write('1');
Expand All @@ -137,9 +148,10 @@ public function testForceWriteActsLikeWriteOnNonFullBuffer(): void
}

/**
* @testdox overwrite replaces the oldest item on full buffer
* uuid: 880f916b-5039-475c-bd5c-83463c36a147
*/
public function testForceWriteReplacesTheOldestItemOnFullBuffer(): void
public function testOverwriteReplacesTheOldestItemOnFullBuffer(): void
{
$buffer = new CircularBuffer(2);
$buffer->write('1');
Expand All @@ -150,9 +162,10 @@ public function testForceWriteReplacesTheOldestItemOnFullBuffer(): void
}

/**
* @testdox overwrite replaces the oldest item remaining in buffer following a read
* uuid: bfecab5b-aca1-4fab-a2b0-cd4af2b053c3
*/
public function testForceWriteReplacesTheOldestItemRemainingInBufferFollowingARead(): void
public function testOverwriteReplacesTheOldestItemRemainingInBufferFollowingARead(): void
{
$buffer = new CircularBuffer(3);
$buffer->write('1');
Expand All @@ -167,6 +180,7 @@ public function testForceWriteReplacesTheOldestItemRemainingInBufferFollowingARe
}

/**
* @testdox initial clear does not affect wrapping around
* uuid: 9cebe63a-c405-437b-8b62-e3fdc1ecec5a
*/
public function testInitialClearDoesNotAffectWrappingAround(): void
Expand Down

0 comments on commit aa57a00

Please sign in to comment.