|
7 | 7 | import org.junit.jupiter.api.Test;
|
8 | 8 |
|
9 | 9 | public class ZalgorithmTest {
|
| 10 | + |
10 | 11 | /**
|
11 | 12 | * Test 1:
|
12 |
| - * Input: text = "ababcababcabc", pattern = "abc" |
13 |
| - * Output: [2, 7, 10] |
14 |
| - * Explanation: The pattern "abc" occurs at indices 2, 7, and 10. |
| 13 | + * Pattern: "a", Text: "aabaaabaa" |
| 14 | + * Expected: [0, 1, 4, 5, 8] |
15 | 15 | */
|
16 | 16 | @Test
|
17 |
| - public void testFindPatternOccurrences() { |
18 |
| - String text = "ababcababcabc"; |
19 |
| - String pattern = "abc"; |
20 |
| - List<Integer> expected = Arrays.asList(2, 7, 10); |
21 |
| - |
22 |
| - List<Integer> actual = Zalgorithm.findPatternOccurrences(text, pattern); |
23 |
| - |
24 |
| - assertEquals(expected, actual); |
| 17 | + public void testFindPatternOccurrencesSingleCharacter() { |
| 18 | + String text = "aabaaabaa"; |
| 19 | + String pattern = "a"; |
| 20 | + List<Integer> expected = Arrays.asList(0, 1, 4, 5, 8); |
| 21 | + assertEquals(expected, Zalgorithm.findPatternOccurrences(text, pattern)); |
25 | 22 | }
|
26 | 23 |
|
27 | 24 | /**
|
28 | 25 | * Test 2:
|
29 |
| - * Input: text = "abcdefg", pattern = "xyz" |
30 |
| - * Output: [] |
31 |
| - * Explanation: The pattern "xyz" does not occur in the text. |
| 26 | + * Pattern: "abc", Text: "ababcabcabc" |
| 27 | + * Expected: [2, 5, 8] |
32 | 28 | */
|
33 | 29 | @Test
|
34 |
| - public void testFindPatternOccurrencesNoMatch() { |
35 |
| - String text = "abcdefg"; |
36 |
| - String pattern = "xyz"; |
37 |
| - List<Integer> expected = Arrays.asList(); |
38 |
| - |
39 |
| - List<Integer> actual = Zalgorithm.findPatternOccurrences(text, pattern); |
40 |
| - |
41 |
| - assertEquals(expected, actual); |
| 30 | + public void testFindPatternOccurrences() { |
| 31 | + String text = "ababcabcabc"; |
| 32 | + String pattern = "abc"; |
| 33 | + List<Integer> expected = Arrays.asList(2, 5, 8); |
| 34 | + assertEquals(expected, Zalgorithm.findPatternOccurrences(text, pattern)); |
42 | 35 | }
|
43 |
| - |
44 | 36 | /**
|
45 | 37 | * Test 3:
|
46 |
| - * Input: text = "aabbaabbaaa", pattern = "a" |
47 |
| - * Output: [0, 3, 5, 9] |
48 |
| - * Explanation: The pattern "a" occurs at indices 0, 3, 5, and 9. |
| 38 | + * Pattern: "aa", Text: "aaaaaa" |
| 39 | + * Expected: [0, 1, 2, 3, 4] |
49 | 40 | */
|
50 | 41 | @Test
|
51 |
| - public void testFindPatternOccurrencesSingleCharacter() { |
52 |
| - String text = "aabbaabbaaa"; |
53 |
| - String pattern = "a"; |
54 |
| - List<Integer> expected = Arrays.asList(0, 3, 5, 9); |
55 |
| - |
56 |
| - List<Integer> actual = Zalgorithm.findPatternOccurrences(text, pattern); |
57 |
| - |
58 |
| - assertEquals(expected, actual); |
| 42 | + public void testFindPatternOccurrencesRepeated() { |
| 43 | + String text = "aaaaaa"; |
| 44 | + String pattern = "aa"; |
| 45 | + List<Integer> expected = Arrays.asList(0, 1, 2, 3, 4); |
| 46 | + assertEquals(expected, Zalgorithm.findPatternOccurrences(text, pattern)); |
59 | 47 | }
|
60 | 48 | }
|
0 commit comments