From f406fa30e878239010127d48d578f65e4f2112c2 Mon Sep 17 00:00:00 2001 From: khouloud Haddad Amamou Date: Tue, 5 Nov 2024 18:26:39 +0100 Subject: [PATCH 1/7] Remove duplicate characters from a string --- Strings/RemoveDuplicatedCharacters.php | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Strings/RemoveDuplicatedCharacters.php diff --git a/Strings/RemoveDuplicatedCharacters.php b/Strings/RemoveDuplicatedCharacters.php new file mode 100644 index 00000000..e9460e6f --- /dev/null +++ b/Strings/RemoveDuplicatedCharacters.php @@ -0,0 +1,29 @@ + Date: Tue, 5 Nov 2024 20:58:01 +0100 Subject: [PATCH 2/7] Make "removeDuplicatedCharacters" PSR-12 friendly and add unit tests --- Strings/RemoveDuplicatedCharacters.php | 24 ++++--- composer.json | 3 +- .../RemoveDuplicatedCharactersTest.php | 71 +++++++++++++++++++ 3 files changed, 86 insertions(+), 12 deletions(-) create mode 100644 tests/Strings/RemoveDuplicatedCharactersTest.php diff --git a/Strings/RemoveDuplicatedCharacters.php b/Strings/RemoveDuplicatedCharacters.php index e9460e6f..babc683c 100644 --- a/Strings/RemoveDuplicatedCharacters.php +++ b/Strings/RemoveDuplicatedCharacters.php @@ -1,29 +1,33 @@ assertSame('progamin', removeDuplicatedCharacters('programming')); + } + + /** + * Test with a string that has no duplicates. + */ + public function testStringWithoutDuplicates(): void + { + $this->assertSame('abc', removeDuplicatedCharacters('abc')); + } + + /** + * Test with an empty string. + */ + public function testEmptyString(): void + { + $this->assertSame('', removeDuplicatedCharacters('')); + } + + /** + * Test with a string containing only one character repeated. + */ + public function testSingleCharacterRepeated(): void + { + $this->assertSame('a', removeDuplicatedCharacters('aaaaa')); + } + + /** + * Test with special characters. + */ + public function testStringWithSpecialCharacters(): void + { + $this->assertSame('ab!@', removeDuplicatedCharacters('aabb!!@@')); + } + + /** + * Test with a string containing spaces. + */ + public function testStringWithSpaces(): void + { + $this->assertSame('a b', removeDuplicatedCharacters('a a a b b')); + } + + /** + * Test with a string containing mixed case characters. + */ + public function testStringWithMixedCase(): void + { + $this->assertSame('aAbB', removeDuplicatedCharacters('aAaAaAbBbB')); + } +} From a310c88a1aea1d6decf5bf1ff825a52bfb0f796f Mon Sep 17 00:00:00 2001 From: khouloud HADDAD AMAMOU Date: Sun, 17 Nov 2024 20:46:32 +0100 Subject: [PATCH 3/7] Update Strings/RemoveDuplicatedCharacters.php Co-authored-by: Brandon Johnson --- Strings/RemoveDuplicatedCharacters.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Strings/RemoveDuplicatedCharacters.php b/Strings/RemoveDuplicatedCharacters.php index babc683c..e34138e8 100644 --- a/Strings/RemoveDuplicatedCharacters.php +++ b/Strings/RemoveDuplicatedCharacters.php @@ -9,7 +9,7 @@ * @return string The modified string with duplicate characters removed. */ -function removeDuplicatedCharacters(string $inputString): string +function removeDuplicateCharacters(string $inputString): string { // Initialize an empty array to keep track of seen characters $seen = []; From 584704acd6159f00277422c0dd89f29cc89ad802 Mon Sep 17 00:00:00 2001 From: khouloud Haddad Amamou Date: Mon, 25 Nov 2024 10:25:05 +0100 Subject: [PATCH 4/7] Apply fixes --- ...ters.php => RemoveDuplicateCharacters.php} | 3 ++- composer.json | 2 +- ....php => RemoveDuplicateCharactersTest.php} | 22 +++++++++---------- 3 files changed, 14 insertions(+), 13 deletions(-) rename Strings/{RemoveDuplicatedCharacters.php => RemoveDuplicateCharacters.php} (93%) rename tests/Strings/{RemoveDuplicatedCharactersTest.php => RemoveDuplicateCharactersTest.php} (57%) diff --git a/Strings/RemoveDuplicatedCharacters.php b/Strings/RemoveDuplicateCharacters.php similarity index 93% rename from Strings/RemoveDuplicatedCharacters.php rename to Strings/RemoveDuplicateCharacters.php index babc683c..cdad3fb1 100644 --- a/Strings/RemoveDuplicatedCharacters.php +++ b/Strings/RemoveDuplicateCharacters.php @@ -9,7 +9,7 @@ * @return string The modified string with duplicate characters removed. */ -function removeDuplicatedCharacters(string $inputString): string +function removeDuplicateCharacters(string $inputString): string { // Initialize an empty array to keep track of seen characters $seen = []; @@ -31,3 +31,4 @@ function removeDuplicatedCharacters(string $inputString): string return $result; } + diff --git a/composer.json b/composer.json index 42e5a6ff..d1512067 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "ext-json": "*" }, "require-dev": { - "phpunit/phpunit": "^9.6", + "phpunit/phpunit": "^9", "squizlabs/php_codesniffer": "^3.7" }, "scripts": { diff --git a/tests/Strings/RemoveDuplicatedCharactersTest.php b/tests/Strings/RemoveDuplicateCharactersTest.php similarity index 57% rename from tests/Strings/RemoveDuplicatedCharactersTest.php rename to tests/Strings/RemoveDuplicateCharactersTest.php index 88d324ae..14f6c8be 100644 --- a/tests/Strings/RemoveDuplicatedCharactersTest.php +++ b/tests/Strings/RemoveDuplicateCharactersTest.php @@ -3,22 +3,22 @@ declare(strict_types=1); require_once __DIR__ . '/../../vendor/autoload.php'; -require_once __DIR__ . '/../../Strings/RemoveDuplicatedCharacters.php'; +require_once __DIR__ . '/../../Strings/RemoveDuplicateCharacters.php'; use PHPUnit\Framework\TestCase; /** - * Unit tests for the removeDuplicatedCharacters function. - * To run test: ./vendor/bin/phpunit tests/strings/RemoveDuplicatedCharactersTest.php + * Unit tests for the removeDuplicateCharacters function. + * To run test: ./vendor/bin/phpunit tests/strings/removeDuplicateCharactersTest.php */ -final class RemoveDuplicatedCharactersTest extends TestCase +final class removeDuplicateCharactersTest extends TestCase { /** * Test with a string that has multiple duplicates. */ public function testStringWithDuplicates(): void { - $this->assertSame('progamin', removeDuplicatedCharacters('programming')); + $this->assertSame('progamin', removeDuplicateCharacters('programming')); } /** @@ -26,7 +26,7 @@ public function testStringWithDuplicates(): void */ public function testStringWithoutDuplicates(): void { - $this->assertSame('abc', removeDuplicatedCharacters('abc')); + $this->assertSame('abc', removeDuplicateCharacters('abc')); } /** @@ -34,7 +34,7 @@ public function testStringWithoutDuplicates(): void */ public function testEmptyString(): void { - $this->assertSame('', removeDuplicatedCharacters('')); + $this->assertSame('', removeDuplicateCharacters('')); } /** @@ -42,7 +42,7 @@ public function testEmptyString(): void */ public function testSingleCharacterRepeated(): void { - $this->assertSame('a', removeDuplicatedCharacters('aaaaa')); + $this->assertSame('a', removeDuplicateCharacters('aaaaa')); } /** @@ -50,7 +50,7 @@ public function testSingleCharacterRepeated(): void */ public function testStringWithSpecialCharacters(): void { - $this->assertSame('ab!@', removeDuplicatedCharacters('aabb!!@@')); + $this->assertSame('ab!@', removeDuplicateCharacters('aabb!!@@')); } /** @@ -58,7 +58,7 @@ public function testStringWithSpecialCharacters(): void */ public function testStringWithSpaces(): void { - $this->assertSame('a b', removeDuplicatedCharacters('a a a b b')); + $this->assertSame('a b', removeDuplicateCharacters('a a a b b')); } /** @@ -66,6 +66,6 @@ public function testStringWithSpaces(): void */ public function testStringWithMixedCase(): void { - $this->assertSame('aAbB', removeDuplicatedCharacters('aAaAaAbBbB')); + $this->assertSame('aAbB', removeDuplicateCharacters('aAaAaAbBbB')); } } From 9af9243fc990e0a84b2d21ab116d508a11cbf913 Mon Sep 17 00:00:00 2001 From: khouloud HADDAD AMAMOU Date: Sat, 4 Jan 2025 15:27:47 +0000 Subject: [PATCH 5/7] Add RemoveDuplicateCharacters to the Directory. --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index 3554092d..2c64065c 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -136,6 +136,7 @@ * [Maxcharacter](./Strings/MaxCharacter.php) * [Reversestring](./Strings/ReverseString.php) * [Reversewords](./Strings/ReverseWords.php) + * [RemoveDuplicateCharacters](./Strings/RemoveDuplicateCharacters.php) ## Tests * Ciphers From 6d7d19b41b5b1e998d4419d710f589052cebe4ae Mon Sep 17 00:00:00 2001 From: khouloud HADDAD AMAMOU Date: Thu, 23 Jan 2025 11:53:59 +0100 Subject: [PATCH 6/7] Update tests/Strings/RemoveDuplicateCharactersTest.php Co-authored-by: Brandon Johnson --- tests/Strings/RemoveDuplicateCharactersTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Strings/RemoveDuplicateCharactersTest.php b/tests/Strings/RemoveDuplicateCharactersTest.php index 14f6c8be..b017ca1d 100644 --- a/tests/Strings/RemoveDuplicateCharactersTest.php +++ b/tests/Strings/RemoveDuplicateCharactersTest.php @@ -11,7 +11,7 @@ * Unit tests for the removeDuplicateCharacters function. * To run test: ./vendor/bin/phpunit tests/strings/removeDuplicateCharactersTest.php */ -final class removeDuplicateCharactersTest extends TestCase +final class RemoveDuplicateCharactersTest extends TestCase { /** * Test with a string that has multiple duplicates. From c283a45b46f04e535bb2bdf0d972dd53a68724e8 Mon Sep 17 00:00:00 2001 From: khouloud HADDAD AMAMOU Date: Sun, 26 Jan 2025 13:39:53 +0000 Subject: [PATCH 7/7] Remove extra line at the end of the file --- tests/Strings/RemoveDuplicateCharactersTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Strings/RemoveDuplicateCharactersTest.php b/tests/Strings/RemoveDuplicateCharactersTest.php index b017ca1d..6065ec81 100644 --- a/tests/Strings/RemoveDuplicateCharactersTest.php +++ b/tests/Strings/RemoveDuplicateCharactersTest.php @@ -68,4 +68,4 @@ public function testStringWithMixedCase(): void { $this->assertSame('aAbB', removeDuplicateCharacters('aAaAaAbBbB')); } -} +} \ No newline at end of file