From 37d62f9ca6ffb0523a88017510327b979a93439b Mon Sep 17 00:00:00 2001 From: khouloud Haddad Amamou Date: Tue, 5 Nov 2024 20:58:01 +0100 Subject: [PATCH] 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')); + } +}