From 0c8616e33226ed87fcb5a78c4b4b30c336bd0057 Mon Sep 17 00:00:00 2001 From: Alex Klymenko Date: Tue, 27 Aug 2024 10:49:20 +0200 Subject: [PATCH] test: `ReverseStringRecursiveTest` (#5407) * test: ReverseStringRecursiveTest * checkstyle: fix formatting * checkstyle: fix formatting --------- Co-authored-by: alxkm --- .../strings/ReverseStringRecursive.java | 2 +- .../strings/ReverseStringRecursiveTest.java | 31 +++++-------------- 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/thealgorithms/strings/ReverseStringRecursive.java b/src/main/java/com/thealgorithms/strings/ReverseStringRecursive.java index e180f6c3..817b0a8c 100644 --- a/src/main/java/com/thealgorithms/strings/ReverseStringRecursive.java +++ b/src/main/java/com/thealgorithms/strings/ReverseStringRecursive.java @@ -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 diff --git a/src/test/java/com/thealgorithms/strings/ReverseStringRecursiveTest.java b/src/test/java/com/thealgorithms/strings/ReverseStringRecursiveTest.java index b33037f3..19daa61f 100644 --- a/src/test/java/com/thealgorithms/strings/ReverseStringRecursiveTest.java +++ b/src/test/java/com/thealgorithms/strings/ReverseStringRecursiveTest.java @@ -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)); } }