forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReverseStringTest.java
More file actions
56 lines (46 loc) · 2.44 KB
/
ReverseStringTest.java
File metadata and controls
56 lines (46 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package com.thealgorithms.strings;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.CsvSource;
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
@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));
}
@ParameterizedTest
@MethodSource("testCases")
public void testReverseString3(String input, String expectedOutput) {
assertEquals(expectedOutput, ReverseString.reverse3(input));
}
@ParameterizedTest
@MethodSource("testCases")
public void testReverseStringUsingStack(String input, String expectedOutput) {
assertEquals(expectedOutput, ReverseString.reverseStringUsingStack(input));
}
@Test
public void testReverseStringUsingStackWithNullInput() {
assertThrows(IllegalArgumentException.class, () -> ReverseString.reverseStringUsingStack(null));
}
@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
testReverseStringUsingRecursion(String input, String expectedOutput) {
assertEquals(expectedOutput, ReverseString.reverseStringUsingRecursion(input));
}
}