* Generate a document with specific keywords embedded.
( wordCount: number, keywords: string[], keywordDensity: number = 0.05, seed: number = 0, )
| 332 | * Generate a document with specific keywords embedded. |
| 333 | */ |
| 334 | function generateDocumentWithKeywords( |
| 335 | wordCount: number, |
| 336 | keywords: string[], |
| 337 | keywordDensity: number = 0.05, |
| 338 | seed: number = 0, |
| 339 | ): string { |
| 340 | const baseDoc = generateDocument(wordCount, seed); |
| 341 | const words = baseDoc.split(/\s+/); |
| 342 | |
| 343 | // Sprinkle keywords throughout the document |
| 344 | const keywordPositions = new Set<number>(); |
| 345 | let random = seed + 1000; |
| 346 | const nextRandom = () => { |
| 347 | random = (random * 1103515245 + 12345) & 0x7fffffff; |
| 348 | return random / 0x7fffffff; |
| 349 | }; |
| 350 | |
| 351 | const numKeywords = Math.floor(wordCount * keywordDensity); |
| 352 | for (let i = 0; i < numKeywords; i++) { |
| 353 | const pos = Math.floor(nextRandom() * words.length); |
| 354 | if (!keywordPositions.has(pos)) { |
| 355 | keywordPositions.add(pos); |
| 356 | words[pos] = keywords[Math.floor(nextRandom() * keywords.length)]!; |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | return words.join(" "); |
| 361 | } |
| 362 | |
| 363 | test("Performance and Large Document Tests large document handling should handle a 1000-word document", () => { |
| 364 | const doc = generateDocument(1000); |
no test coverage detected