|
1 | 1 | import assert from "node:assert"; |
2 | 2 | import { describe, it } from "node:test"; |
3 | | -import { replaceSpoilerHack, stripCode, stripEmoji } from "./messages.js"; |
| 3 | +import { replaceSpoilerHack, stripCode, stripEmoji, jaccardSimilarity } from "./messages.js"; |
4 | 4 |
|
5 | 5 | describe("utils/messages -> stripCode", () => { |
6 | 6 | it("should remove inline code blocks", () => { |
@@ -71,3 +71,36 @@ describe("utils/messages -> replaceSpoilerHack", () => { |
71 | 71 | assert.strictEqual(actual, expected); |
72 | 72 | }); |
73 | 73 | }); |
| 74 | + |
| 75 | +describe("jaccardSimilarity - crosspost detection", () => { |
| 76 | + it("catches identical self-promotion spam", () => { |
| 77 | + const msg1 = "Check out my new portfolio website! Built with React and Tailwind"; |
| 78 | + const msg2 = "Check out my new portfolio website! Built with React and Tailwind"; |
| 79 | + const actual = jaccardSimilarity(msg1, msg2); |
| 80 | + |
| 81 | + assert.strictEqual(actual, 1); |
| 82 | + }); |
| 83 | + |
| 84 | + it("catches copy-paste spam with minor punctuation differences", () => { |
| 85 | + const msg1 = "hey guys check out my new website!"; |
| 86 | + const msg2 = "hey guys, check out my new website"; |
| 87 | + const actual = jaccardSimilarity(msg1, msg2); |
| 88 | + |
| 89 | + assert.strictEqual(actual, 1); |
| 90 | + }); |
| 91 | + |
| 92 | + it("catches reordered messages", () => { |
| 93 | + const msg1 = "I just launched my SaaS app! Check it out and let me know what you think"; |
| 94 | + const msg2 = "Check it out and let me know what you think! I just launched my SaaS app"; |
| 95 | + const actual = jaccardSimilarity(msg1, msg2); |
| 96 | + assert.strictEqual(actual, 1); |
| 97 | + }); |
| 98 | + |
| 99 | + it("does not flag similar but different questions", () => { |
| 100 | + const msg1 = "How do I center a div in CSS?"; |
| 101 | + const msg2 = "How do I align a div to the right in CSS?"; |
| 102 | + const actual = jaccardSimilarity(msg1, msg2); // 0.5833333333333334 |
| 103 | + |
| 104 | + assert.ok(actual > 0.5 && actual < 0.8); |
| 105 | + }); |
| 106 | +}); |
0 commit comments