test: ReverseStringRecursiveTest
(#5407)
* test: ReverseStringRecursiveTest * checkstyle: fix formatting * checkstyle: fix formatting --------- Co-authored-by: alxkm <alx@alx.com>
This commit is contained in:
parent
c8cf302d30
commit
0c8616e332
@ -3,10 +3,10 @@ package com.thealgorithms.strings;
|
|||||||
/**
|
/**
|
||||||
* Reverse String using Recursion
|
* Reverse String using Recursion
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public final class ReverseStringRecursive {
|
public final class ReverseStringRecursive {
|
||||||
private ReverseStringRecursive() {
|
private ReverseStringRecursive() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param str string to be reversed
|
* @param str string to be reversed
|
||||||
* @return reversed string
|
* @return reversed string
|
||||||
|
@ -2,30 +2,15 @@ package com.thealgorithms.strings;
|
|||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
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 {
|
public class ReverseStringRecursiveTest {
|
||||||
@Test
|
@ParameterizedTest
|
||||||
void shouldAcceptWhenEmptyStringIsPassed() {
|
@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'",
|
||||||
String expected = "";
|
"'MixOf123AndText!', '!txeTdnA321fOxiM'"})
|
||||||
String reversed = ReverseStringRecursive.reverse("");
|
public void
|
||||||
|
testReverseString(String input, String expectedOutput) {
|
||||||
assertEquals(expected, reversed);
|
assertEquals(expectedOutput, ReverseStringRecursive.reverse(input));
|
||||||
}
|
|
||||||
|
|
||||||
@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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user