Skip to content

Commit

Permalink
tests: add even more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
double-beep authored Aug 21, 2024
1 parent 95753ae commit db8c706
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public double getTotalScore() {

@Override
public String getFormattedReasonMessage() {
String message = getFormattedMessage("title", "title")
+ getFormattedMessage("body", "body")
String message = getFormattedMessage("title", "Title")
+ getFormattedMessage("body", "Body")
+ getFormattedMessage("comment", "Edit summary");

return message.trim();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ private String getRepeatedWords() {
words.append(word);
}

return words.toString().substring(0, 40) + "...";
return words.toString().length() < 40
? words.toString()
: words.toString().substring(0, 40) + "...";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package bugs.stackoverflow.belisarius.filters;

import java.io.IOException;
import java.util.List;

import bugs.stackoverflow.belisarius.models.Post;

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

import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -70,5 +72,22 @@ public void hitTest() throws IOException {
assertEquals(filter4.isHit(), true);
// 1 (title) + 1 (edit summary) + 2 (post body) = 4
assertEquals(filter4.getTotalScore(), 4.0);

List<String> reasons = List.of(
"Contains blacklisted word: (?i)(problem|error|issue)\\s+(re|now\\s+)?(solved|fixed)",
"Contains blacklisted word: (?:problem|error|issue).{0,10}(?<!n't|not)\\s+(?:now\\s+)?fixed(?!\\W*\\?)",
"Contains blacklisted word: (?i)(problem|error|issue)\\s+(re|now\\s+)?(solved|fixed)",
"Contains blacklisted word: (?i)(answer -|answer:)"
);
List<String> actual = filter4.getReasonName();

assertTrue(actual.containsAll(reasons) && reasons.containsAll(actual));
assertEquals(
filter4.getFormattedReasonMessage(),
"**Body contains blacklisted words:** (?i)(problem|error|issue)\\s+(re|now\\s+)?(solved|fixed), "
+ "(?i)(answer -|answer:) **Edit summary contains blacklisted words:** "
+ "(?i)(problem|error|issue)\\s+(re|now\\s+)?(solved|fixed), "
+ "(?:problem|error|issue).{0,10}(?<!n't|not)\\s+(?:now\\s+)?fixed(?!\\W*\\?)"
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,7 @@ public void hitTest() throws IOException {
assertEquals(filter4.isHit(), true);
// total score is always 1
assertEquals(filter4.getTotalScore(), 1.0);
assertEquals(filter4.getFormattedReasonMessage(), "**Code removed**");
assertEquals(filter4.getReasonName().get(0), "Code removed");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,7 @@ public void hitTest() throws IOException {
assertEquals(filter3.isHit(), true);
// total score is always 1
assertEquals(filter3.getTotalScore(), 1.0);
assertEquals(filter3.getFormattedReasonMessage(), "**Few unique characters detected:** Deltd");
assertEquals(filter3.getReasonName().get(0), "Few unique characters in body");
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package bugs.stackoverflow.belisarius.filters;

import java.io.IOException;
import java.util.List;

import bugs.stackoverflow.belisarius.models.Post;

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

import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -58,5 +60,21 @@ public void hitTest() throws IOException {
OffensiveWordFilter filter3 = new OffensiveWordFilter(0, post3);
assertEquals(filter3.isHit(), true);
assertEquals(filter3.getTotalScore(), 5.0);

assertEquals(
filter3.getFormattedReasonMessage(),
"**Edit summary contains offensive words:** (?i)shitty\\squestion, "
+ "(?i)fuck\\soff, (?i)\\bf([\\Wkcuf]*)ck(s|ers?|ed)?, (?i)jerk\\soff, (?i)this\\s*(\\w+)?\\s*spam"
);

List<String> reasons = List.of(
"Contains offensive word: (?i)shitty\\squestion",
"Contains offensive word: (?i)fuck\\soff",
"Contains offensive word: (?i)\\bf([\\Wkcuf]*)ck(s|ers?|ed)?",
"Contains offensive word: (?i)jerk\\soff",
"Contains offensive word: (?i)this\\s*(\\w+)?\\s*spam"
);
List<String> actual = filter3.getReasonName();
assertTrue(actual.containsAll(reasons) && reasons.containsAll(actual));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,20 @@ public void hitTest() throws IOException {
assertEquals(filter1.getTotalScore(), 2.0);
assertEquals(filter2.getTotalScore(), 4.0);
assertEquals(filter3.getTotalScore(), 5.0);

assertEquals(filter1.getReasonName().get(0), "Contains repeated words");

assertEquals(
filter1.getFormattedReasonMessage(),
"**Post contains repeated words:** repeatedthesearewords"
);
assertEquals(
filter2.getFormattedReasonMessage(),
"**Post contains repeated words:** Issueresolved"
);
assertEquals(
filter3.getFormattedReasonMessage(),
"**Post contains repeated word:** Deleted"
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import org.junit.jupiter.api.Test;

public class RepeatedWordFilterTest {
public class TextRemovedFilterTest {
@Test
public void hitTest() throws IOException {
Post post1 = FilterTestUtils.getSamplePost(
Expand All @@ -20,7 +20,6 @@ public void hitTest() throws IOException {
"question"
);

// https://higgs.sobotics.org/Hippo/report/84303
Post post2 = FilterTestUtils.getSamplePost(
"This text has nothing to do with the above one.",
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, "
Expand Down Expand Up @@ -54,5 +53,13 @@ public void hitTest() throws IOException {
assertEquals(filter3.isHit(), true);
// total weight is always 1.0
assertEquals(filter3.getTotalScore(), 1.0);
assertEquals(
filter3.getReasonName().get(0),
"Lots of text removed with a high JW score"
);
assertEquals(
filter3.getFormattedReasonMessage(),
"**80.0% or more text removed with a JW score of 0.42**"
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,10 @@ public void hitTest() throws IOException {
assertEquals(filter1.isHit(), true);
// total weight is always 1.0
assertEquals(filter1.getTotalScore(), 1.0);
assertEquals(filter1.getReasonName().get(0), "Contains very long word");
assertEquals(
filter1.getFormattedReasonMessage(),
"**Contains very long word:** answerwithaveryveryveryveryverylongwordt..."
);
}
}

0 comments on commit db8c706

Please sign in to comment.