From 2fd159dbe57664ee3920390cb9ee772b8b54965b Mon Sep 17 00:00:00 2001 From: Tomas Norre Mikkelsen Date: Mon, 28 Oct 2024 07:53:50 +0100 Subject: [PATCH 1/6] sync run length encoding --- .../run-length-encoding/.docs/instructions.md | 12 +- .../run-length-encoding/.meta/example.php | 22 --- .../RunLengthEncodingTest.php | 157 +++++++++++++----- 3 files changed, 119 insertions(+), 72 deletions(-) diff --git a/exercises/practice/run-length-encoding/.docs/instructions.md b/exercises/practice/run-length-encoding/.docs/instructions.md index 95f7a9d6..fc8ce056 100644 --- a/exercises/practice/run-length-encoding/.docs/instructions.md +++ b/exercises/practice/run-length-encoding/.docs/instructions.md @@ -2,8 +2,7 @@ Implement run-length encoding and decoding. -Run-length encoding (RLE) is a simple form of data compression, where runs -(consecutive data elements) are replaced by just one data value and count. +Run-length encoding (RLE) is a simple form of data compression, where runs (consecutive data elements) are replaced by just one data value and count. For example we can represent the original 53 characters with only 13. @@ -11,14 +10,11 @@ For example we can represent the original 53 characters with only 13. "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB" -> "12WB12W3B24WB" ``` -RLE allows the original data to be perfectly reconstructed from -the compressed data, which makes it a lossless data compression. +RLE allows the original data to be perfectly reconstructed from the compressed data, which makes it a lossless data compression. ```text "AABCCCDEEEE" -> "2AB3CD4E" -> "AABCCCDEEEE" ``` -For simplicity, you can assume that the unencoded string will only contain -the letters A through Z (either lower or upper case) and whitespace. This way -data to be encoded will never contain any numbers and numbers inside data to -be decoded always represent the count for the following character. +For simplicity, you can assume that the unencoded string will only contain the letters A through Z (either lower or upper case) and whitespace. +This way data to be encoded will never contain any numbers and numbers inside data to be decoded always represent the count for the following character. diff --git a/exercises/practice/run-length-encoding/.meta/example.php b/exercises/practice/run-length-encoding/.meta/example.php index 3965acb4..2c0b7e8c 100644 --- a/exercises/practice/run-length-encoding/.meta/example.php +++ b/exercises/practice/run-length-encoding/.meta/example.php @@ -1,27 +1,5 @@ . - * - * To disable strict typing, comment out the directive below. - */ - declare(strict_types=1); /** diff --git a/exercises/practice/run-length-encoding/RunLengthEncodingTest.php b/exercises/practice/run-length-encoding/RunLengthEncodingTest.php index c1477360..fa67e45f 100644 --- a/exercises/practice/run-length-encoding/RunLengthEncodingTest.php +++ b/exercises/practice/run-length-encoding/RunLengthEncodingTest.php @@ -1,27 +1,5 @@ . - * - * To disable strict typing, comment out the directive below. - */ - declare(strict_types=1); class RunLengthEncodingTest extends PHPUnit\Framework\TestCase @@ -31,59 +9,154 @@ public static function setUpBeforeClass(): void require_once 'RunLengthEncoding.php'; } + /** + * uuid: ad53b61b-6ffc-422f-81a6-61f7df92a231 + * @testdox empty string + */ public function testEncodeEmptyString(): void { - $this->assertEquals('', encode('')); + $this->assertEquals( + '', + encode('') + ); } - public function testEncodeSingleCharactersOnly(): void + /** + * uuid: 52012823-b7e6-4277-893c-5b96d42f82de + * @testdox single characters only are encoded without count + */ + public function testEncodeSingleCharactersOnlyAreEncodedWithoutCount(): void { - $this->assertEquals('XYZ', encode('XYZ')); + $this->assertEquals( + 'XYZ', + encode('XYZ') + ); } - public function testDecodeEmptyString(): void + /** + * uuid: b7868492-7e3a-415f-8da3-d88f51f80409 + * @testdox string with no single characters + */ + public function testEncodeStringWithNoSingleCharacters(): void { - $this->assertEquals('', decode('')); + $this->assertEquals( + '2A3B4C', + encode('AABBBCCCC') + ); } - public function testDecodeSingleCharactersOnly(): void + /** + * uuid: 859b822b-6e9f-44d6-9c46-6091ee6ae358 + * @testdox single characters mixed with repeated characters + */ + public function testEncodeSingleCharactersMixedWithRepeatedCharacters(): void { - $this->assertEquals('XYZ', decode('XYZ')); + $this->assertEquals( + '12WB12W3B24WB', + encode('WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB') + ); } - public function testEncodeSimple(): void + /** + * uuid: 1b34de62-e152-47be-bc88-469746df63b3 + * @testdox multiple whitespace mixed in string + */ + public function testEncodeMultipleWhitespaceMixedInString(): void { - $this->assertEquals('2A3B4C', encode('AABBBCCCC')); + $this->assertEquals( + '2 hs2q q2w2 ', + encode(' hsqq qww ') + ); } - public function testDecodeSimple(): void + /** + * uuid: abf176e2-3fbd-40ad-bb2f-2dd6d4df721a + * @testdox lowercase characters + */ + public function testEncodeLowercaseCharacters(): void { - $this->assertEquals('AABBBCCCC', decode('2A3B4C')); + $this->assertEquals( + '2a3b4c', + encode('aabbbcccc') + ); } - public function testEncodeWithSingleValues(): void + /** + * uuid: 7ec5c390-f03c-4acf-ac29-5f65861cdeb5 + * @testdox empty string + */ + public function testDecodeEmptyString(): void { $this->assertEquals( - '12WB12W3B24WB', - encode('WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB') + '', + decode('') ); } - public function testDecodeWithSingleValues(): void + /** + * uuid: ad23f455-1ac2-4b0e-87d0-b85b10696098 + * @testdox single characters only + */ + public function testDecodeSingleCharactersOnly(): void + { + $this->assertEquals( + 'XYZ', + decode('XYZ') + ); + } + /** + * uuid: 21e37583-5a20-4a0e-826c-3dee2c375f54 + * @testdox string with no single characters + */ + public function testDecodeStringWithNoSingleCharacters(): void + { + $this->assertEquals( + 'AABBBCCCC', + decode('2A3B4C') + ); + } + /** + * uuid: 1389ad09-c3a8-4813-9324-99363fba429c + * @testdox single characters with repeated characters + */ + public function testDecodeSingleCharactersWithRepeatedCharacters(): void { $this->assertEquals( 'WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB', decode('12WB12W3B24WB') ); } - + /** + * uuid: 3f8e3c51-6aca-4670-b86c-a213bf4706b0 + * @testdox multiple whitespace mixed in string + */ public function testDecodeMultipleWhitespaceMixedInString(): void { - $this->assertEquals(' hsqq qww ', decode('2 hs2q q2w2 ')); + $this->assertEquals( + ' hsqq qww ', + decode('2 hs2q q2w2 ') + ); } - - public function testEncodeDecodeCombination(): void + /** + * uuid: 29f721de-9aad-435f-ba37-7662df4fb551 + * @testdox lowercase string + */ + public function testDecodeLowercaseString(): void { - $this->assertEquals('zzz ZZ zZ', decode(encode('zzz ZZ zZ'))); + $this->assertEquals( + 'aabbbcccc', + decode('2a3b4c') + ); + } + /** + * uuid: 2a762efd-8695-4e04-b0d6-9736899fbc16 + * @testdox encode followed by decode gives original string + */ + public function testEncodeFollowedByDecodeGivesOriginalString(): void + { + $this->assertEquals( + 'zzz ZZ zZ', + decode('zzz ZZ zZ') + ); } } From 1388e366bc47ff7b4071743735434edd62eecc78 Mon Sep 17 00:00:00 2001 From: Tomas Norre Mikkelsen Date: Wed, 30 Oct 2024 15:25:57 +0100 Subject: [PATCH 2/6] Update exercises/practice/run-length-encoding/RunLengthEncodingTest.php Co-authored-by: mk-mxp <55182845+mk-mxp@users.noreply.github.com> --- .../practice/run-length-encoding/RunLengthEncodingTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/practice/run-length-encoding/RunLengthEncodingTest.php b/exercises/practice/run-length-encoding/RunLengthEncodingTest.php index fa67e45f..b97160dd 100644 --- a/exercises/practice/run-length-encoding/RunLengthEncodingTest.php +++ b/exercises/practice/run-length-encoding/RunLengthEncodingTest.php @@ -156,7 +156,7 @@ public function testEncodeFollowedByDecodeGivesOriginalString(): void { $this->assertEquals( 'zzz ZZ zZ', - decode('zzz ZZ zZ') + decode(encode('zzz ZZ zZ')) ); } } From f11b3b8f6d1b964ea1a67fea9688282e3ed2891f Mon Sep 17 00:00:00 2001 From: Tomas Norre Mikkelsen Date: Wed, 30 Oct 2024 15:26:05 +0100 Subject: [PATCH 3/6] Update exercises/practice/run-length-encoding/RunLengthEncodingTest.php Co-authored-by: mk-mxp <55182845+mk-mxp@users.noreply.github.com> --- .../practice/run-length-encoding/RunLengthEncodingTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/practice/run-length-encoding/RunLengthEncodingTest.php b/exercises/practice/run-length-encoding/RunLengthEncodingTest.php index b97160dd..cd00924d 100644 --- a/exercises/practice/run-length-encoding/RunLengthEncodingTest.php +++ b/exercises/practice/run-length-encoding/RunLengthEncodingTest.php @@ -11,7 +11,7 @@ public static function setUpBeforeClass(): void /** * uuid: ad53b61b-6ffc-422f-81a6-61f7df92a231 - * @testdox empty string + * @testdox Run-length encode a string - empty string */ public function testEncodeEmptyString(): void { From dbdf85c831ee3ee9267fe501ee6d3458f3210bfe Mon Sep 17 00:00:00 2001 From: Tomas Norre Mikkelsen Date: Wed, 30 Oct 2024 15:26:11 +0100 Subject: [PATCH 4/6] Update exercises/practice/run-length-encoding/RunLengthEncodingTest.php Co-authored-by: mk-mxp <55182845+mk-mxp@users.noreply.github.com> --- .../practice/run-length-encoding/RunLengthEncodingTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/practice/run-length-encoding/RunLengthEncodingTest.php b/exercises/practice/run-length-encoding/RunLengthEncodingTest.php index cd00924d..b89281ab 100644 --- a/exercises/practice/run-length-encoding/RunLengthEncodingTest.php +++ b/exercises/practice/run-length-encoding/RunLengthEncodingTest.php @@ -83,7 +83,7 @@ public function testEncodeLowercaseCharacters(): void /** * uuid: 7ec5c390-f03c-4acf-ac29-5f65861cdeb5 - * @testdox empty string + * @testdox Run-length decode a string - empty string */ public function testDecodeEmptyString(): void { From 3c42072769e674e2ffcf62a41b171e47f1959b44 Mon Sep 17 00:00:00 2001 From: Tomas Norre Mikkelsen Date: Wed, 30 Oct 2024 15:27:52 +0100 Subject: [PATCH 5/6] add prefix to @testdox --- .../RunLengthEncodingTest.php | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/exercises/practice/run-length-encoding/RunLengthEncodingTest.php b/exercises/practice/run-length-encoding/RunLengthEncodingTest.php index b89281ab..2021a188 100644 --- a/exercises/practice/run-length-encoding/RunLengthEncodingTest.php +++ b/exercises/practice/run-length-encoding/RunLengthEncodingTest.php @@ -23,7 +23,7 @@ public function testEncodeEmptyString(): void /** * uuid: 52012823-b7e6-4277-893c-5b96d42f82de - * @testdox single characters only are encoded without count + * @testdox Run-length encode a string - single characters only are encoded without count */ public function testEncodeSingleCharactersOnlyAreEncodedWithoutCount(): void { @@ -35,7 +35,7 @@ public function testEncodeSingleCharactersOnlyAreEncodedWithoutCount(): void /** * uuid: b7868492-7e3a-415f-8da3-d88f51f80409 - * @testdox string with no single characters + * @testdox Run-length encode a string - string with no single characters */ public function testEncodeStringWithNoSingleCharacters(): void { @@ -47,7 +47,7 @@ public function testEncodeStringWithNoSingleCharacters(): void /** * uuid: 859b822b-6e9f-44d6-9c46-6091ee6ae358 - * @testdox single characters mixed with repeated characters + * @testdox Run-length encode a string - single characters mixed with repeated characters */ public function testEncodeSingleCharactersMixedWithRepeatedCharacters(): void { @@ -59,7 +59,7 @@ public function testEncodeSingleCharactersMixedWithRepeatedCharacters(): void /** * uuid: 1b34de62-e152-47be-bc88-469746df63b3 - * @testdox multiple whitespace mixed in string + * @testdox Run-length encode a string - multiple whitespace mixed in string */ public function testEncodeMultipleWhitespaceMixedInString(): void { @@ -71,7 +71,7 @@ public function testEncodeMultipleWhitespaceMixedInString(): void /** * uuid: abf176e2-3fbd-40ad-bb2f-2dd6d4df721a - * @testdox lowercase characters + * @testdox Run-length encode a string - lowercase characters */ public function testEncodeLowercaseCharacters(): void { @@ -95,7 +95,7 @@ public function testDecodeEmptyString(): void /** * uuid: ad23f455-1ac2-4b0e-87d0-b85b10696098 - * @testdox single characters only + * @testdox Run-length decode a string - single characters only */ public function testDecodeSingleCharactersOnly(): void { @@ -106,7 +106,7 @@ public function testDecodeSingleCharactersOnly(): void } /** * uuid: 21e37583-5a20-4a0e-826c-3dee2c375f54 - * @testdox string with no single characters + * @testdox Run-length decode a string - string with no single characters */ public function testDecodeStringWithNoSingleCharacters(): void { @@ -117,7 +117,7 @@ public function testDecodeStringWithNoSingleCharacters(): void } /** * uuid: 1389ad09-c3a8-4813-9324-99363fba429c - * @testdox single characters with repeated characters + * @testdox Run-length decode a string - single characters with repeated characters */ public function testDecodeSingleCharactersWithRepeatedCharacters(): void { @@ -128,7 +128,7 @@ public function testDecodeSingleCharactersWithRepeatedCharacters(): void } /** * uuid: 3f8e3c51-6aca-4670-b86c-a213bf4706b0 - * @testdox multiple whitespace mixed in string + * @testdox Run-length decode a string - multiple whitespace mixed in string */ public function testDecodeMultipleWhitespaceMixedInString(): void { @@ -139,7 +139,7 @@ public function testDecodeMultipleWhitespaceMixedInString(): void } /** * uuid: 29f721de-9aad-435f-ba37-7662df4fb551 - * @testdox lowercase string + * @testdox Run-length decode a string - lowercase string */ public function testDecodeLowercaseString(): void { @@ -150,7 +150,7 @@ public function testDecodeLowercaseString(): void } /** * uuid: 2a762efd-8695-4e04-b0d6-9736899fbc16 - * @testdox encode followed by decode gives original string + * @testdox Run-length decode a string - encode followed by decode gives original string */ public function testEncodeFollowedByDecodeGivesOriginalString(): void { From ab5aa93743c149c5e11cd8e04c9fc187800e60a8 Mon Sep 17 00:00:00 2001 From: Tomas Norre Mikkelsen Date: Wed, 30 Oct 2024 16:22:56 +0100 Subject: [PATCH 6/6] Update exercises/practice/run-length-encoding/RunLengthEncodingTest.php Co-authored-by: mk-mxp <55182845+mk-mxp@users.noreply.github.com> --- .../practice/run-length-encoding/RunLengthEncodingTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/practice/run-length-encoding/RunLengthEncodingTest.php b/exercises/practice/run-length-encoding/RunLengthEncodingTest.php index 2021a188..dca9c876 100644 --- a/exercises/practice/run-length-encoding/RunLengthEncodingTest.php +++ b/exercises/practice/run-length-encoding/RunLengthEncodingTest.php @@ -150,7 +150,7 @@ public function testDecodeLowercaseString(): void } /** * uuid: 2a762efd-8695-4e04-b0d6-9736899fbc16 - * @testdox Run-length decode a string - encode followed by decode gives original string + * @testdox encode followed by decode gives original string */ public function testEncodeFollowedByDecodeGivesOriginalString(): void {