tests / router.test.ts
import { describe, expect, it } from "vitest";
import { pickSkills } from "../src/router";
describe("pickSkills", () => {
const probs = { pdf: 0.9, docx: 0.6, xlsx: 0.59, pptx: 0.2 };
it("keeps skills at or above the threshold, sorted by probability desc", () => {
expect(pickSkills(probs, { threshold: 0.6, maxSkills: 5 })).toEqual([
{ name: "pdf", p: 0.9 },
{ name: "docx", p: 0.6 },
]);
});
it("caps at maxSkills", () => {
expect(pickSkills(probs, { threshold: 0.1, maxSkills: 2 })).toEqual([
{ name: "pdf", p: 0.9 },
{ name: "docx", p: 0.6 },
]);
});
it("returns nothing when maxSkills is 0", () => {
expect(pickSkills(probs, { threshold: 0.1, maxSkills: 0 })).toEqual([]);
});
it("breaks ties by name ascending", () => {
expect(pickSkills({ b: 0.7, a: 0.7 }, { threshold: 0.5, maxSkills: 5 })).toEqual([
{ name: "a", p: 0.7 },
{ name: "b", p: 0.7 },
]);
});
it("ignores non-finite probabilities", () => {
expect(pickSkills({ a: NaN, b: 0.8 }, { threshold: 0.5, maxSkills: 5 })).toEqual([{ name: "b", p: 0.8 }]);
});
});
tests / router.test.ts
import { describe, expect, it } from "vitest";
import { pickSkills } from "../src/router";
describe("pickSkills", () => {
const probs = { pdf: 0.9, docx: 0.6, xlsx: 0.59, pptx: 0.2 };
it("keeps skills at or above the threshold, sorted by probability desc", () => {
expect(pickSkills(probs, { threshold: 0.6, maxSkills: 5 })).toEqual([
{ name: "pdf", p: 0.9 },
{ name: "docx", p: 0.6 },
]);
});
it("caps at maxSkills", () => {
expect(pickSkills(probs, { threshold: 0.1, maxSkills: 2 })).toEqual([
{ name: "pdf", p: 0.9 },
{ name: "docx", p: 0.6 },
]);
});
it("returns nothing when maxSkills is 0", () => {
expect(pickSkills(probs, { threshold: 0.1, maxSkills: 0 })).toEqual([]);
});
it("breaks ties by name ascending", () => {
expect(pickSkills({ b: 0.7, a: 0.7 }, { threshold: 0.5, maxSkills: 5 })).toEqual([
{ name: "a", p: 0.7 },
{ name: "b", p: 0.7 },
]);
});
it("ignores non-finite probabilities", () => {
expect(pickSkills({ a: NaN, b: 0.8 }, { threshold: 0.5, maxSkills: 5 })).toEqual([{ name: "b", p: 0.8 }]);
});
});