test(danmaku): cover rankCandidates confidence paths

This commit is contained in:
noelorin 2026-09-26 19:26:44 +08:00
parent 967ef58503
commit 5ce1f91a26
1 changed files with 47 additions and 0 deletions

View File

@ -29,4 +29,51 @@ describe("rankCandidates", () => {
const r = rankCandidates(list); const r = rankCandidates(list);
expect(r.highConfidence).toBe(false); expect(r.highConfidence).toBe(false);
}); });
it("empty candidates are not high confidence", () => {
const r = rankCandidates([]);
expect(r.highConfidence).toBe(false);
expect(r.candidates).toEqual([]);
});
it("score gap >= default lead (0.15) is high confidence", () => {
const list = [
{ episodeId: 2, animeId: 1, animeTitle: "Show", episodeTitle: null, imageUrl: "img" },
{ episodeId: 1, animeId: 1, animeTitle: "Show", episodeTitle: "01", imageUrl: null },
];
const r = rankCandidates(list);
expect(r.highConfidence).toBe(true);
expect(r.candidates[0]?.episodeId).toBe(1);
});
it("custom lead is honored", () => {
const list = [
{ episodeId: 2, animeId: 1, animeTitle: "Show", episodeTitle: null, imageUrl: "img" },
{ episodeId: 1, animeId: 1, animeTitle: "Show", episodeTitle: "01", imageUrl: null },
];
expect(rankCandidates(list, { lead: 0.5 }).highConfidence).toBe(false);
expect(rankCandidates(list, { lead: 0.3 }).highConfidence).toBe(true);
});
it("returns candidates sorted by score desc", () => {
const hi = {
episodeId: 1,
animeId: 1,
animeTitle: "A",
episodeTitle: "01",
imageUrl: "img",
};
const mid = {
episodeId: 2,
animeId: 1,
animeTitle: "B",
episodeTitle: "02",
imageUrl: null,
};
const low = {
episodeId: 3,
animeId: null,
animeTitle: null,
episodeTitle: null,
imageUrl: "x",
};
const r = rankCandidates([low, mid, hi]);
expect(r.candidates.map((c) => c.episodeId)).toEqual([1, 2, 3]);
});
}); });