Skip to content

Commit f574478

Browse files
authored
tests: add more tests
1 parent 8038418 commit f574478

File tree

5 files changed

+197
-5
lines changed

5 files changed

+197
-5
lines changed

src/test/java/bugs/stackoverflow/belisarius/filters/BlacklistedFilterTest.java

+11
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,20 @@ public void hitTest() throws IOException {
5151
"question"
5252
);
5353

54+
// body would be caught if post was a question
55+
Post post5 = FilterTestUtils.getSamplePost(
56+
"This is my answer. answer: do this",
57+
"This was my answer. It was quite big.",
58+
"title",
59+
null,
60+
"removed some characters from body",
61+
"answer"
62+
);
63+
5464
assertEquals(new BlacklistedFilter(0, post1).isHit(), true);
5565
assertEquals(new BlacklistedFilter(0, post2).isHit(), false);
5666
assertEquals(new BlacklistedFilter(0, post3).isHit(), false);
67+
assertEquals(new BlacklistedFilter(0, post5).isHit(), false);
5768

5869
BlacklistedFilter filter4 = new BlacklistedFilter(0, post4);
5970
assertEquals(filter4.isHit(), true);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package bugs.stackoverflow.belisarius.filters;
2+
3+
import java.io.IOException;
4+
5+
import bugs.stackoverflow.belisarius.models.Post;
6+
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
9+
import org.junit.jupiter.api.Test;
10+
11+
public class FewUniqueCharactersFilterTest {
12+
@Test
13+
public void hitTest() throws IOException {
14+
// https://metasmoke.erwaysoftware.com/post/493704
15+
Post post1 = FilterTestUtils.getSamplePost(
16+
"<p>.......................................................... ...</p>",
17+
"<p>nobody cares</p>",
18+
"Mmmmmmmmmmmmmmmmmmm",
19+
"nobody cares",
20+
"vandalised my post",
21+
"question"
22+
);
23+
24+
// last body is null
25+
Post post2 = FilterTestUtils.getSamplePost(
26+
"<p>??????????????????????????????</p>",
27+
"<p>This is some text</p>",
28+
"Does this code work?",
29+
null,
30+
"edit",
31+
"answer"
32+
);
33+
34+
// https://higgs.sobotics.org/Hippo/report/88186
35+
Post post3 = FilterTestUtils.getSamplePost(
36+
"DeletedDeletedDeletedDeletedDeletedDeletedDeletedDeletedDeletedDeletedDeletedDeleted",
37+
"This was the last question body.",
38+
"DeletedDeletedDeletedDeletedDeleted",
39+
null,
40+
"Deleted",
41+
"question"
42+
);
43+
44+
// few unique characters in code
45+
Post post4 = FilterTestUtils.getSamplePost(
46+
"<p>Code: <code>dddddddddddddddddddddddddddddddddddddddd</code></p>",
47+
"<p>Question text includes <code>some inline code</code>"
48+
+ ", some <pre><code>blocks of code</code></pre> "
49+
+ ", and <blockquote>some quotes</blockquote> as well</p>",
50+
"title",
51+
null,
52+
"removed 20 characters from body",
53+
"question"
54+
);
55+
56+
assertEquals(new FewUniqueCharactersFilter(0, post1).isHit(), true);
57+
assertEquals(new FewUniqueCharactersFilter(0, post2).isHit(), true);
58+
assertEquals(new FewUniqueCharactersFilter(0, post4).isHit(), false);
59+
60+
FewUniqueCharactersFilter filter3 = new FewUniqueCharactersFilter(0, post3);
61+
assertEquals(filter3.isHit(), true);
62+
// total score is always 1
63+
assertEquals(filter3.getTotalScore(), 1.0);
64+
}
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package bugs.stackoverflow.belisarius.filters;
2+
3+
import java.io.IOException;
4+
5+
import bugs.stackoverflow.belisarius.models.Post;
6+
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
9+
import org.junit.jupiter.api.Test;
10+
11+
public class OffensiveWordFilterTest {
12+
@Test
13+
public void hitTest() throws IOException {
14+
// offensive word in
15+
Post post1 = FilterTestUtils.getSamplePost(
16+
"This is my question. It is also quite big.",
17+
"This was my question. It is quite big.",
18+
"title",
19+
"title",
20+
"fuck off everybody",
21+
"question"
22+
);
23+
24+
// answer
25+
Post post2 = FilterTestUtils.getSamplePost(
26+
"This is my very helpful lengthy answer.",
27+
"This is my very helpful lengthy answer.",
28+
"title",
29+
null,
30+
"get lost dumbass",
31+
"answer"
32+
);
33+
34+
// multiple offensive words
35+
Post post3 = FilterTestUtils.getSamplePost(
36+
"This is my question. It is also quite big.",
37+
"This was my question. It is quite big.",
38+
"title",
39+
null,
40+
"shitty question fuck off jerk off this is spam",
41+
"answer"
42+
);
43+
44+
// offensive word in body shouldn't be caught
45+
Post post4 = FilterTestUtils.getSamplePost(
46+
"<p>My very interesting question. you suck</p>",
47+
"<p>This is my question. It is quite big.</p>",
48+
"title",
49+
null,
50+
"normal edit summary",
51+
"answer"
52+
);
53+
54+
assertEquals(new OffensiveWordFilter(0, post1).isHit(), true);
55+
assertEquals(new OffensiveWordFilter(0, post2).isHit(), true);
56+
assertEquals(new OffensiveWordFilter(0, post4).isHit(), false);
57+
58+
OffensiveWordFilter filter3 = new OffensiveWordFilter(0, post3);
59+
assertEquals(filter3.isHit(), true);
60+
assertEquals(filter3.getTotalScore(), 5.0);
61+
}
62+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package bugs.stackoverflow.belisarius.filters;
2+
3+
import java.io.IOException;
4+
5+
import bugs.stackoverflow.belisarius.models.Post;
6+
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
9+
import org.junit.jupiter.api.Test;
10+
11+
public class RepeatedWordFilterTest {
12+
@Test
13+
public void hitTest() throws IOException {
14+
Post post1 = FilterTestUtils.getSamplePost(
15+
"<p>" + "these words are repeated ".repeat(10) + "</p>",
16+
"<p>nobody cares</p>",
17+
"title",
18+
null,
19+
"vandalised my post",
20+
"question"
21+
);
22+
23+
// https://higgs.sobotics.org/Hippo/report/84303
24+
Post post2 = FilterTestUtils.getSamplePost(
25+
"<p>" + "Issue resolved\n".repeat(3) + "</p>",
26+
"<p>This is some text</p>",
27+
"Does this code work?",
28+
null,
29+
"deleted 169 characters in body",
30+
"answer"
31+
);
32+
33+
Post post3 = FilterTestUtils.getSamplePost(
34+
"<p>" + "Deleted ".repeat(100) + "</p>",
35+
"This was the last question body.",
36+
"DeletedDeletedDeletedDeletedDeleted",
37+
null,
38+
"deleted my question",
39+
"question"
40+
);
41+
42+
RepeatedWordFilter filter1 = new RepeatedWordFilter(0, post1);
43+
RepeatedWordFilter filter2 = new RepeatedWordFilter(0, post2);
44+
RepeatedWordFilter filter3 = new RepeatedWordFilter(0, post3);
45+
46+
assertEquals(filter1.isHit(), true);
47+
assertEquals(filter2.isHit(), true);
48+
assertEquals(filter3.isHit(), true);
49+
50+
assertEquals(filter1.getTotalScore(), 2.0);
51+
assertEquals(filter2.getTotalScore(), 4.0);
52+
assertEquals(filter3.getTotalScore(), 5.0);
53+
}
54+
}

src/test/java/bugs/stackoverflow/belisarius/utils/PostUtilsTest.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package bugs.stackoverflow.belisarius.utils;
22

3-
import java.util.HashMap;
43
import java.util.List;
54
import java.util.Map;
65
import java.io.IOException;
@@ -90,7 +89,6 @@ public void getVandalisedPostTest() {
9089
Post deletedPost = belisarius.getPost("1");
9190
assertNull(deletedPost);
9291

93-
Map<String, List<String>> vandalisedPosts = new HashMap<>();
9492
List<String> low = Arrays.asList(
9593
"66373993", // removed code Q
9694
"63575223", // text removed Q
@@ -108,9 +106,11 @@ public void getVandalisedPostTest() {
108106

109107
List<String> high = Arrays.asList("62812593"); // offensive word
110108

111-
vandalisedPosts.put("low", low);
112-
vandalisedPosts.put("medium", medium);
113-
vandalisedPosts.put("high", high);
109+
Map<String, List<String>> vandalisedPosts = Map.of(
110+
"low", low,
111+
"medium", medium,
112+
"high", high
113+
);
114114

115115
for (Map.Entry<String, List<String>> entry : vandalisedPosts.entrySet()) {
116116
for (String postId : entry.getValue()) {

0 commit comments

Comments
 (0)