-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8038418
commit f574478
Showing
5 changed files
with
197 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/test/java/bugs/stackoverflow/belisarius/filters/FewUniqueCharactersFilterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
src/test/java/bugs/stackoverflow/belisarius/filters/OffensiveWordFilterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/test/java/bugs/stackoverflow/belisarius/filters/RepeatedWordFilterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters