|
1 | 1 | package com.thealgorithms.strings;
|
2 | 2 |
|
3 | 3 | 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; |
5 | 7 |
|
6 | 8 | 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 | + } |
7 | 14 |
|
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 | + } |
15 | 20 |
|
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) { |
20 | 22 | }
|
21 | 23 | }
|
0 commit comments