test: ReverseStringRecursiveTest (#5407)

* test: ReverseStringRecursiveTest

* checkstyle: fix formatting

* checkstyle: fix formatting

---------

Co-authored-by: alxkm <alx@alx.com>
This commit is contained in:
Alex Klymenko 2024-08-27 10:49:20 +02:00 committed by GitHub
parent c8cf302d30
commit 0c8616e332
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 24 deletions

View File

@ -3,10 +3,10 @@ package com.thealgorithms.strings;
/**
* Reverse String using Recursion
*/
public final class ReverseStringRecursive {
private ReverseStringRecursive() {
}
/**
* @param str string to be reversed
* @return reversed string

View File

@ -2,30 +2,15 @@ package com.thealgorithms.strings;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
public class ReverseStringRecursiveTest {
@Test
void shouldAcceptWhenEmptyStringIsPassed() {
String expected = "";
String reversed = ReverseStringRecursive.reverse("");
assertEquals(expected, reversed);
}
@Test
void shouldAcceptNotWhenWhenSingleCharacterIsPassed() {
String expected = "a";
String reversed = ReverseStringRecursive.reverse("a");
assertEquals(expected, reversed);
}
@Test
void shouldAcceptWhenStringIsPassed() {
String expected = "dlroWolleH";
String reversed = ReverseStringRecursive.reverse("HelloWorld");
assertEquals(expected, reversed);
@ParameterizedTest
@CsvSource({"'Hello World', 'dlroW olleH'", "'helloworld', 'dlrowolleh'", "'123456789', '987654321'", "'', ''", "'A', 'A'", "'!123 ABC xyz!', '!zyx CBA 321!'", "'Abc 123 Xyz', 'zyX 321 cbA'", "'12.34,56;78:90', '09:87;65,43.21'", "'abcdEFGHiJKL', 'LKJiHGFEdcba'",
"'MixOf123AndText!', '!txeTdnA321fOxiM'"})
public void
testReverseString(String input, String expectedOutput) {
assertEquals(expectedOutput, ReverseStringRecursive.reverse(input));
}
}