Skip to content

Commit 1e6bdc3

Browse files
authored
fixed : NaivePatternSearchTest.java
1 parent e78d53d commit 1e6bdc3

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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

Comments
 (0)