mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-12-19 07:00:35 +08:00
Add Z-Algorithm for Linear-Time String Pattern Matching (#7124)
* Add Z-Algorithm (string pattern matching) with tests * Add Z-Algorithm (string pattern matching) with tests * Add Z-Algorithm (string pattern matching) with tests * Fix checkstyle errors for ZAlgorithm * Fix: clang-format and checkstyle compliance for ZAlgorithm
This commit is contained in:
25
src/test/java/com/thealgorithms/strings/ZAlgorithmTest.java
Normal file
25
src/test/java/com/thealgorithms/strings/ZAlgorithmTest.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package com.thealgorithms.strings;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ZAlgorithmTest {
|
||||
|
||||
@Test
|
||||
void testZFunction() {
|
||||
int[] z = ZAlgorithm.zFunction("aaaaa");
|
||||
assertArrayEquals(new int[] {0, 4, 3, 2, 1}, z);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSearchFound() {
|
||||
assertEquals(2, ZAlgorithm.search("abcabca", "cab"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSearchNotFound() {
|
||||
assertEquals(-1, ZAlgorithm.search("abcdef", "gh"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user