|
| 1 | +package com.thealgorithms.searches; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 4 | + |
| 5 | +import org.junit.jupiter.api.Test; |
| 6 | + |
| 7 | +public class BoyerMooreTest { |
| 8 | + |
| 9 | + @Test |
| 10 | + public void testPatternFound() { |
| 11 | + BoyerMoore bm = new BoyerMoore("ABCDABD"); |
| 12 | + String text = "ABC ABCDAB ABCDABCDABDE"; |
| 13 | + int index = bm.search(text); |
| 14 | + assertEquals(15, index); |
| 15 | + } |
| 16 | + |
| 17 | + @Test |
| 18 | + public void testPatternNotFound() { |
| 19 | + BoyerMoore bm = new BoyerMoore("XYZ"); |
| 20 | + String text = "ABC ABCDAB ABCDABCDABDE"; |
| 21 | + int index = bm.search(text); |
| 22 | + assertEquals(-1, index); |
| 23 | + } |
| 24 | + |
| 25 | + @Test |
| 26 | + public void testPatternAtBeginning() { |
| 27 | + BoyerMoore bm = new BoyerMoore("ABC"); |
| 28 | + String text = "ABCDEF"; |
| 29 | + int index = bm.search(text); |
| 30 | + assertEquals(0, index); |
| 31 | + } |
| 32 | + |
| 33 | + @Test |
| 34 | + public void testPatternAtEnd() { |
| 35 | + BoyerMoore bm = new BoyerMoore("CDE"); |
| 36 | + String text = "ABCDEFGCDE"; |
| 37 | + int index = bm.search(text); |
| 38 | + assertEquals(2, index); // Primera ocurrencia de "CDE" |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + public void testEmptyPattern() { |
| 43 | + BoyerMoore bm = new BoyerMoore(""); |
| 44 | + String text = "Hello world"; |
| 45 | + int index = bm.search(text); |
| 46 | + assertEquals(0, index); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + public void testStaticSearchMethod() { |
| 51 | + String text = "ABCDEFGCDE"; |
| 52 | + int index = BoyerMoore.staticSearch(text, "CDE"); |
| 53 | + assertEquals(2, index); // Primera ocurrencia de "CDE" |
| 54 | + } |
| 55 | +} |
0 commit comments