forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoyerMooreTest.java
More file actions
55 lines (46 loc) · 1.45 KB
/
BoyerMooreTest.java
File metadata and controls
55 lines (46 loc) · 1.45 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
package com.thealgorithms.searches;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
public class BoyerMooreTest {
@Test
public void testPatternFound() {
BoyerMoore bm = new BoyerMoore("ABCDABD");
String text = "ABC ABCDAB ABCDABCDABDE";
int index = bm.search(text);
assertEquals(15, index);
}
@Test
public void testPatternNotFound() {
BoyerMoore bm = new BoyerMoore("XYZ");
String text = "ABC ABCDAB ABCDABCDABDE";
int index = bm.search(text);
assertEquals(-1, index);
}
@Test
public void testPatternAtBeginning() {
BoyerMoore bm = new BoyerMoore("ABC");
String text = "ABCDEF";
int index = bm.search(text);
assertEquals(0, index);
}
@Test
public void testPatternAtEnd() {
BoyerMoore bm = new BoyerMoore("CDE");
String text = "ABCDEFGCDE";
int index = bm.search(text);
assertEquals(2, index); // Primera ocurrencia de "CDE"
}
@Test
public void testEmptyPattern() {
BoyerMoore bm = new BoyerMoore("");
String text = "Hello world";
int index = bm.search(text);
assertEquals(0, index);
}
@Test
public void testStaticSearchMethod() {
String text = "ABCDEFGCDE";
int index = BoyerMoore.staticSearch(text, "CDE");
assertEquals(2, index); // Primera ocurrencia de "CDE"
}
}