|
| 1 | +package javatests.com.williamfiset.algorithms.strings; |
| 2 | + |
| 3 | +import static com.google.common.truth.Truth.assertThat; |
| 4 | + |
| 5 | +import com.williamfiset.algorithms.strings.BoyerMooreStringSearch; |
| 6 | +import org.junit.Before; |
| 7 | +import org.junit.Test; |
| 8 | + |
| 9 | +public class BoyerMooreStringSearchTest { |
| 10 | + |
| 11 | + private BoyerMooreStringSearch underTest; |
| 12 | + |
| 13 | + @Before |
| 14 | + public void setup() { |
| 15 | + underTest = new BoyerMooreStringSearch(); |
| 16 | + } |
| 17 | + |
| 18 | + @Test |
| 19 | + public void shouldReturnEmptyListOnNullInput() { |
| 20 | + assertThat(underTest.findOccurrences(null, "")).isEmpty(); |
| 21 | + assertThat(underTest.findOccurrences("", null)).isEmpty(); |
| 22 | + assertThat(underTest.findOccurrences(null, null)).isEmpty(); |
| 23 | + } |
| 24 | + |
| 25 | + @Test |
| 26 | + public void shouldReturnOneOccurrence() { |
| 27 | + assertThat( |
| 28 | + underTest.findOccurrences( |
| 29 | + "Sample text for testing the Boyer-Moore algorithm.", "Sample")) |
| 30 | + .containsExactly(0); |
| 31 | + assertThat( |
| 32 | + underTest.findOccurrences("Sample text for testing the Boyer-Moore algorithm.", "for")) |
| 33 | + .containsExactly(12); |
| 34 | + assertThat(underTest.findOccurrences("Sample text for testing the Boyer-Moore algorithm.", ".")) |
| 35 | + .containsExactly(49); |
| 36 | + } |
| 37 | + |
| 38 | + @Test |
| 39 | + public void shouldReturnMultiplyOccurrences() { |
| 40 | + assertThat( |
| 41 | + underTest.findOccurrences("Sample text for testing the Boyer-Moore algorithm.", "te")) |
| 42 | + .containsAllOf(7, 16); |
| 43 | + assertThat(underTest.findOccurrences("Sample text for testing the Boyer-Moore algorithm.", " ")) |
| 44 | + .containsAllOf(6, 11, 15, 23, 39); |
| 45 | + } |
| 46 | +} |
0 commit comments