Skip to content

Commit 8a7c4fd

Browse files
author
alxkm
committed
test: PalindromeTest
1 parent 74b05ef commit 8a7c4fd

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed
Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
package com.thealgorithms.strings;
22

33
import org.junit.jupiter.api.Assertions;
4-
import org.junit.jupiter.api.Test;
4+
import org.junit.jupiter.params.ParameterizedTest;
5+
import org.junit.jupiter.params.provider.MethodSource;
6+
import java.util.stream.Stream;
57

68
public class PalindromeTest {
9+
10+
private static Stream<TestData> provideTestCases() {
11+
return Stream.of(new TestData(null, true), new TestData("", true), new TestData("aba", true), new TestData("123321", true), new TestData("kayak", true),
12+
new TestData("abb", false), new TestData("abc", false), new TestData("abc123", false), new TestData("kayaks", false));
13+
}
714

8-
@Test
9-
public void palindrome() {
10-
11-
String[] palindromes = {null, "", "aba", "123321", "kayak"};
12-
for (String s : palindromes) {
13-
Assertions.assertTrue(Palindrome.isPalindrome(s) && Palindrome.isPalindromeRecursion(s) && Palindrome.isPalindromeTwoPointer(s));
14-
}
15+
@ParameterizedTest
16+
@MethodSource("provideTestCases")
17+
void testPalindrome(TestData testData) {
18+
Assertions.assertEquals(testData.expected, Palindrome.isPalindrome(testData.input) && Palindrome.isPalindromeRecursion(testData.input) && Palindrome.isPalindromeTwoPointer(testData.input));
19+
}
1520

16-
String[] notPalindromes = {"abb", "abc", "abc123", "kayaks"};
17-
for (String s : notPalindromes) {
18-
Assertions.assertFalse(Palindrome.isPalindrome(s) || Palindrome.isPalindromeRecursion(s) || Palindrome.isPalindromeTwoPointer(s));
19-
}
21+
private record TestData (String input, boolean expected) {
2022
}
2123
}

0 commit comments

Comments
 (0)