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 f574478 commit 95753ae
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public boolean isHit() {
String original = "";
String target = "";

if (this.post.getBody() != null && this.post.getLastBody() != null) {
original = this.post.getLastBody();
target = this.post.getBody();
if (post.getBody() != null && post.getLastBody() != null) {
original = post.getLastBody();
target = post.getBody();
}

this.score = CheckUtils.getJaroWinklerScore(original, target, percentage);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
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>This is a normal edit to my question</p>",
"<p>This is my question</p>",
"title",
null,
"added some important info",
"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, "
+ "sed do eiusmod tempor incididunt ut labore et dolore magna "
+ "aliqua. Ut enim ad minim veniam, quis nostrud exercitation "
+ "ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis "
+ "aute irure dolor in reprehenderit in voluptate velit esse cillum "
+ "dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat "
+ "non proident, sunt in culpa qui officia deserunt mollit anim id "
+ "est laborum.",
"Does this code work?",
null,
"deleted 169 characters in body",
"answer"
);

Post post3 = FilterTestUtils.getSamplePost(
"I removed my question",
"<p>" + "This is a valid question no doubt. ".repeat(100) + "</p>",
"How can I do this?",
null,
"deleted my question",
"question"
);


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

TextRemovedFilter filter3 = new TextRemovedFilter(0, post3);
assertEquals(filter3.isHit(), true);
// total weight is always 1.0
assertEquals(filter3.getTotalScore(), 1.0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
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 VeryLongWordFilterTest {
@Test
public void hitTest() throws IOException {
Post post1 = FilterTestUtils.getSamplePost(
"<p>This is my answerwithaveryveryveryveryverylongwordthatwillbecaught</p>",
"<p>This is my answer</p>",
"title",
null,
"added some important info",
"answer"
);

// very long word already existed
Post post2 = FilterTestUtils.getSamplePost(
"this is my question thisisaveryverylongwordwhichismorethanfiftycharacters",
"thisisaveryverylongwordwhichismorethanfiftycharacters this is my question",
"Does this code work?",
null,
"deleted some characters in body",
"question"
);

Post post3 = FilterTestUtils.getSamplePost(
"<p>This is my question and thisisnotalongword.</p>",
"<p>This is my question</p>",
"How can I do this?",
null,
"deleted my question",
"question"
);

// very long word inside HTML tag
Post post4 = FilterTestUtils.getSamplePost(
"<p>This is my question and <code>thisisaveryverylongwordwhichismorethanfiftycharacters</code>.</p>",
"<p>This is my question</p>",
"How can I do this?",
null,
"deleted my question",
"question"
);

assertEquals(new VeryLongWordFilter(0, post2).isHit(), false);
assertEquals(new VeryLongWordFilter(0, post3).isHit(), false);
assertEquals(new VeryLongWordFilter(0, post4).isHit(), false);

VeryLongWordFilter filter1 = new VeryLongWordFilter(0, post1);
assertEquals(filter1.isHit(), true);
// total weight is always 1.0
assertEquals(filter1.getTotalScore(), 1.0);
}
}

0 comments on commit 95753ae

Please sign in to comment.