Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 21.3k
Expand file tree
/
Copy pathHorspoolSearchTest.java
More file actions
Latest commit
87 lines (71 loc) · 2.37 KB
/
Copy pathHorspoolSearchTest.java
File metadata and controls
87 lines (71 loc) · 2.37 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
packagecom.thealgorithms.strings;
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
importstaticorg.junit.jupiter.api.Assertions.assertThrows;
importorg.junit.jupiter.api.Test;
classHorspoolSearchTest {
@Test
voidtestFindFirstMatch() {
intindex = HorspoolSearch.findFirst("World", "Hello World");
assertEquals(6, index);
}
@Test
voidtestFindFirstNotMatch() {
intindex = HorspoolSearch.findFirst("hell", "Hello World");
assertEquals(-1, index);
}
@Test
voidtestFindFirstPatternLongerText() {
intindex = HorspoolSearch.findFirst("Hello World!!!", "Hello World");
assertEquals(-1, index);
}
@Test
voidtestFindFirstPatternEmpty() {
intindex = HorspoolSearch.findFirst("", "Hello World");
assertEquals(-1, index);
}
@Test
voidtestFindFirstTextEmpty() {
intindex = HorspoolSearch.findFirst("Hello", "");
assertEquals(-1, index);
}
@Test
voidtestFindFirstPatternAndTextEmpty() {
intindex = HorspoolSearch.findFirst("", "");
assertEquals(-1, index);
}
@Test
voidtestFindFirstSpecialCharacter() {
intindex = HorspoolSearch.findFirst("$3**", "Hello $3**$ World");
assertEquals(6, index);
}
@Test
voidtestFindFirstInsensitiveMatch() {
intindex = HorspoolSearch.findFirstInsensitive("hello", "Hello World");
assertEquals(0, index);
}
@Test
voidtestFindFirstInsensitiveNotMatch() {
intindex = HorspoolSearch.findFirstInsensitive("helo", "Hello World");
assertEquals(-1, index);
}
@Test
voidtestGetLastComparisons() {
HorspoolSearch.findFirst("World", "Hello World");
intlastSearchNumber = HorspoolSearch.getLastComparisons();
assertEquals(7, lastSearchNumber);
}
@Test
voidtestGetLastComparisonsNotMatch() {
HorspoolSearch.findFirst("Word", "Hello World");
intlastSearchNumber = HorspoolSearch.getLastComparisons();
assertEquals(3, lastSearchNumber);
}
@Test
voidtestFindFirstPatternNull() {
assertThrows(NullPointerException.class, () -> HorspoolSearch.findFirst(null, "Hello World"));
}
@Test
voidtestFindFirstTextNull() {
assertThrows(NullPointerException.class, () -> HorspoolSearch.findFirst("Hello", null));
}
}