Skip to content

refactor: ReverseString, test improvements #5406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 27, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: refactor testing into two methods
  • Loading branch information
alxkm committed Aug 27, 2024
commit 89873bc56ddd57a556eed2ce6a0f6ee0022dab9c
16 changes: 14 additions & 2 deletions src/test/java/com/thealgorithms/strings/ReverseStringTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,27 @@

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.stream.Stream;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

public class ReverseStringTest {

private static Stream<Arguments> testCases() {
return Stream.of(Arguments.of("Hello World", "dlroW olleH"), Arguments.of("helloworld", "dlrowolleh"), Arguments.of("123456789", "987654321"), Arguments.of("", ""), Arguments.of("A", "A"), Arguments.of("ab", "ba"), Arguments.of(" leading and trailing spaces ", " secaps gniliart dna gnidael "), Arguments.of("!@#$%^&*()", ")(*&^%$#@!"), Arguments.of("MixOf123AndText!", "!txeTdnA321fOxiM"));
}

@ParameterizedTest
@CsvSource({"'Hello World', 'dlroW olleH'", "'helloworld', 'dlrowolleh'", "'123456789', '987654321'", "'', ''", "'A', 'A'", "'ab', 'ba'", "' leading and trailing spaces ', ' secaps gniliart dna gnidael '", "'!@#$%^&*()', ')(*&^%$#@!'", "'MixOf123AndText!', '!txeTdnA321fOxiM'"})
@MethodSource("testCases")
public void testReverseString(String input, String expectedOutput) {
assertEquals(expectedOutput, ReverseString.reverse(input));
}

@ParameterizedTest
@MethodSource("testCases")
public void testReverseString2(String input, String expectedOutput) {
assertEquals(expectedOutput, ReverseString.reverse2(input));
}
}