Skip to content

Commit

Permalink
tests: add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
double-beep authored Aug 21, 2024
1 parent 8038418 commit f574478
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,20 @@ public void hitTest() throws IOException {
"question"
);

// body would be caught if post was a question
Post post5 = FilterTestUtils.getSamplePost(
"This is my answer. answer: do this",
"This was my answer. It was quite big.",
"title",
null,
"removed some characters from body",
"answer"
);

assertEquals(new BlacklistedFilter(0, post1).isHit(), true);
assertEquals(new BlacklistedFilter(0, post2).isHit(), false);
assertEquals(new BlacklistedFilter(0, post3).isHit(), false);
assertEquals(new BlacklistedFilter(0, post5).isHit(), false);

BlacklistedFilter filter4 = new BlacklistedFilter(0, post4);
assertEquals(filter4.isHit(), true);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package bugs.stackoverflow.belisarius.filters;

import java.io.IOException;

import bugs.stackoverflow.belisarius.models.Post;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

public class FewUniqueCharactersFilterTest {
@Test
public void hitTest() throws IOException {
// https://metasmoke.erwaysoftware.com/post/493704
Post post1 = FilterTestUtils.getSamplePost(
"<p>.......................................................... ...</p>",
"<p>nobody cares</p>",
"Mmmmmmmmmmmmmmmmmmm",
"nobody cares",
"vandalised my post",
"question"
);

// last body is null
Post post2 = FilterTestUtils.getSamplePost(
"<p>??????????????????????????????</p>",
"<p>This is some text</p>",
"Does this code work?",
null,
"edit",
"answer"
);

// https://higgs.sobotics.org/Hippo/report/88186
Post post3 = FilterTestUtils.getSamplePost(
"DeletedDeletedDeletedDeletedDeletedDeletedDeletedDeletedDeletedDeletedDeletedDeleted",
"This was the last question body.",
"DeletedDeletedDeletedDeletedDeleted",
null,
"Deleted",
"question"
);

// few unique characters in code
Post post4 = FilterTestUtils.getSamplePost(
"<p>Code: <code>dddddddddddddddddddddddddddddddddddddddd</code></p>",
"<p>Question text includes <code>some inline code</code>"
+ ", some <pre><code>blocks of code</code></pre> "
+ ", and <blockquote>some quotes</blockquote> as well</p>",
"title",
null,
"removed 20 characters from body",
"question"
);

assertEquals(new FewUniqueCharactersFilter(0, post1).isHit(), true);
assertEquals(new FewUniqueCharactersFilter(0, post2).isHit(), true);
assertEquals(new FewUniqueCharactersFilter(0, post4).isHit(), false);

FewUniqueCharactersFilter filter3 = new FewUniqueCharactersFilter(0, post3);
assertEquals(filter3.isHit(), true);
// total score is always 1
assertEquals(filter3.getTotalScore(), 1.0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package bugs.stackoverflow.belisarius.filters;

import java.io.IOException;

import bugs.stackoverflow.belisarius.models.Post;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

public class OffensiveWordFilterTest {
@Test
public void hitTest() throws IOException {
// offensive word in
Post post1 = FilterTestUtils.getSamplePost(
"This is my question. It is also quite big.",
"This was my question. It is quite big.",
"title",
"title",
"fuck off everybody",
"question"
);

// answer
Post post2 = FilterTestUtils.getSamplePost(
"This is my very helpful lengthy answer.",
"This is my very helpful lengthy answer.",
"title",
null,
"get lost dumbass",
"answer"
);

// multiple offensive words
Post post3 = FilterTestUtils.getSamplePost(
"This is my question. It is also quite big.",
"This was my question. It is quite big.",
"title",
null,
"shitty question fuck off jerk off this is spam",
"answer"
);

// offensive word in body shouldn't be caught
Post post4 = FilterTestUtils.getSamplePost(
"<p>My very interesting question. you suck</p>",
"<p>This is my question. It is quite big.</p>",
"title",
null,
"normal edit summary",
"answer"
);

assertEquals(new OffensiveWordFilter(0, post1).isHit(), true);
assertEquals(new OffensiveWordFilter(0, post2).isHit(), true);
assertEquals(new OffensiveWordFilter(0, post4).isHit(), false);

OffensiveWordFilter filter3 = new OffensiveWordFilter(0, post3);
assertEquals(filter3.isHit(), true);
assertEquals(filter3.getTotalScore(), 5.0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package bugs.stackoverflow.belisarius.filters;

import java.io.IOException;

import bugs.stackoverflow.belisarius.models.Post;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

public class RepeatedWordFilterTest {
@Test
public void hitTest() throws IOException {
Post post1 = FilterTestUtils.getSamplePost(
"<p>" + "these words are repeated ".repeat(10) + "</p>",
"<p>nobody cares</p>",
"title",
null,
"vandalised my post",
"question"
);

// https://higgs.sobotics.org/Hippo/report/84303
Post post2 = FilterTestUtils.getSamplePost(
"<p>" + "Issue resolved\n".repeat(3) + "</p>",
"<p>This is some text</p>",
"Does this code work?",
null,
"deleted 169 characters in body",
"answer"
);

Post post3 = FilterTestUtils.getSamplePost(
"<p>" + "Deleted ".repeat(100) + "</p>",
"This was the last question body.",
"DeletedDeletedDeletedDeletedDeleted",
null,
"deleted my question",
"question"
);

RepeatedWordFilter filter1 = new RepeatedWordFilter(0, post1);
RepeatedWordFilter filter2 = new RepeatedWordFilter(0, post2);
RepeatedWordFilter filter3 = new RepeatedWordFilter(0, post3);

assertEquals(filter1.isHit(), true);
assertEquals(filter2.isHit(), true);
assertEquals(filter3.isHit(), true);

assertEquals(filter1.getTotalScore(), 2.0);
assertEquals(filter2.getTotalScore(), 4.0);
assertEquals(filter3.getTotalScore(), 5.0);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package bugs.stackoverflow.belisarius.utils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.io.IOException;
Expand Down Expand Up @@ -90,7 +89,6 @@ public void getVandalisedPostTest() {
Post deletedPost = belisarius.getPost("1");
assertNull(deletedPost);

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

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

vandalisedPosts.put("low", low);
vandalisedPosts.put("medium", medium);
vandalisedPosts.put("high", high);
Map<String, List<String>> vandalisedPosts = Map.of(
"low", low,
"medium", medium,
"high", high
);

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

0 comments on commit f574478

Please sign in to comment.