32 lines
1.0 KiB
JavaScript
32 lines
1.0 KiB
JavaScript
const fs = require("fs");
|
|
const assert = require("assert");
|
|
const { analyzeSinglePost } = require("../ai-analyzer-local");
|
|
|
|
console.log("AI Analyzer logic tests");
|
|
|
|
const testData = JSON.parse(
|
|
fs.readFileSync(__dirname + "/test-data.json", "utf-8")
|
|
);
|
|
const aiResults = testData.positive;
|
|
const context = "job layoffs and workforce reduction";
|
|
const model = "mistral"; // or your default model
|
|
|
|
(async () => {
|
|
for (let i = 0; i < aiResults.length; i++) {
|
|
const post = aiResults[i];
|
|
const aiOutput = await analyzeSinglePost(post.text, context, model);
|
|
assert.strictEqual(
|
|
aiOutput.isRelevant,
|
|
post.aiRelevant,
|
|
`Post ${i} relevance mismatch: expected ${post.aiRelevant}, got ${aiOutput.isRelevant}`
|
|
);
|
|
assert(
|
|
Math.abs(aiOutput.confidence - post.aiConfidence) < 0.05,
|
|
`Post ${i} confidence mismatch: expected ${post.aiConfidence}, got ${aiOutput.confidence}`
|
|
);
|
|
}
|
|
console.log(
|
|
"PASS: AI analyzer matches expected relevance and confidence for all test posts."
|
|
);
|
|
})();
|