|
| 1 | +package com.thealgorithms.strings; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.*; |
| 4 | +import java.util.List; |
| 5 | +import org.junit.jupiter.api.Test; |
| 6 | + |
| 7 | +class NaivePatternSearchTest { |
| 8 | + |
| 9 | + @Test |
| 10 | + void testPatternFound() { |
| 11 | + List<Integer> result = NaivePatternSearch.search("abcdxabchjikabc", "abc"); |
| 12 | + assertEquals(List.of(0, 5, 12), result); |
| 13 | + } |
| 14 | + |
| 15 | + @Test |
| 16 | + void testPatternNotFound() { |
| 17 | + List<Integer> result = NaivePatternSearch.search("abcdefg", "xyz"); |
| 18 | + assertTrue(result.isEmpty()); |
| 19 | + } |
| 20 | + |
| 21 | + @Test |
| 22 | + void testPatternAtEnd() { |
| 23 | + List<Integer> result = NaivePatternSearch.search("helloworld", "world"); |
| 24 | + assertEquals(List.of(5), result); |
| 25 | + } |
| 26 | + |
| 27 | + @Test |
| 28 | + void testPatternEqualsText() { |
| 29 | + List<Integer> result = NaivePatternSearch.search("abc", "abc"); |
| 30 | + assertEquals(List.of(0), result); |
| 31 | + } |
| 32 | + |
| 33 | + @Test |
| 34 | + void testEmptyPattern() { |
| 35 | + List<Integer> result = NaivePatternSearch.search("abcdef", ""); |
| 36 | + assertTrue(result.isEmpty()); |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + void testPatternLongerThanText() { |
| 41 | + List<Integer> result = NaivePatternSearch.search("abc", "abcd"); |
| 42 | + assertTrue(result.isEmpty()); |
| 43 | + } |
| 44 | +} |
0 commit comments