first
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
const test = require("node:test");
|
||||
const assert = require("node:assert/strict");
|
||||
const { tokenize, findRepeatedTail, createDetector } = require("../repetition");
|
||||
|
||||
function detect(text, options) {
|
||||
return findRepeatedTail(tokenize(text), options);
|
||||
}
|
||||
|
||||
test("ordinary prose does not trigger", () => {
|
||||
assert.equal(detect("The same word may appear again, but ordinary prose keeps moving forward."), null);
|
||||
});
|
||||
|
||||
test("a phrase may recur fewer than seven times", () => {
|
||||
assert.equal(detect("try again. ".repeat(6)), null);
|
||||
});
|
||||
|
||||
test("one token repeated seven times triggers", () => {
|
||||
const hit = detect("no ".repeat(7));
|
||||
assert.ok(hit);
|
||||
assert.equal(hit.repeatCount, 7);
|
||||
assert.equal(hit.periodTokens, 1);
|
||||
});
|
||||
|
||||
test("special token garbage repeated seven times triggers", () => {
|
||||
const hit = detect("<unused49>".repeat(7));
|
||||
assert.ok(hit);
|
||||
assert.equal(hit.periodTokens, 1);
|
||||
});
|
||||
|
||||
test("a multi-token phrase repeated seven times triggers", () => {
|
||||
const hit = detect("let us try again. ".repeat(7));
|
||||
assert.ok(hit);
|
||||
assert.ok(hit.periodTokens > 1);
|
||||
});
|
||||
|
||||
test("a larger block repeated seven times triggers", () => {
|
||||
const block = "I will use this wording, but no, that is wrong. Let me correct it. ";
|
||||
const hit = detect(block.repeat(7));
|
||||
assert.ok(hit);
|
||||
assert.ok(hit.periodTokens > 5);
|
||||
});
|
||||
|
||||
test("meaningful token variance prevents a false positive", () => {
|
||||
const text = Array.from({ length: 12 }, (_, i) => `Attempt ${i + 1}: I reconsidered the wording and chose option ${i + 1}.`).join(" ");
|
||||
assert.equal(detect(text), null);
|
||||
});
|
||||
|
||||
test("detector works across arbitrary stream chunk boundaries", () => {
|
||||
const detector = createDetector();
|
||||
const text = "Okay, use אש instead. ".repeat(7);
|
||||
let hit = null;
|
||||
for (let i = 0; i < text.length; i += 3) {
|
||||
hit = detector.push(text.slice(i, i + 3)) || hit;
|
||||
}
|
||||
assert.ok(hit);
|
||||
});
|
||||
|
||||
test("pure formatting does not accidentally tokenize as many punctuation characters", () => {
|
||||
assert.deepStrictEqual(tokenize("----------"), ["----------"]);
|
||||
assert.equal(detect("----------"), null);
|
||||
});
|
||||
Reference in New Issue
Block a user