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
+ }
0 commit comments