import { describe, expect, it } from "vitest"; import { HPO_LABEL_TO_ORGAN, HPO_LABELS, ORGAN_IDS, ORGAN_TO_HPO_LABEL } from "../constants"; import type { HPOLabel, OrganId } from "../types"; describe("HPO Labels", () => { describe("HPO_LABELS", () => { it("should contain all 24 HPO labels", () => { expect(HPO_LABELS).toHaveLength(24); }); it("should include 'others' label", () => { expect(HPO_LABELS).toContain("others"); }); }); describe("HPO_LABEL_TO_ORGAN mapping", () => { it("should map all HPO labels except 'others' to OrganId", () => { const labelsWithoutOthers = HPO_LABELS.filter((label) => label !== "others"); expect(Object.keys(HPO_LABEL_TO_ORGAN)).toHaveLength(labelsWithoutOthers.length); }); it("should map each HPO label to a valid OrganId", () => { for (const [_label, organId] of Object.entries(HPO_LABEL_TO_ORGAN)) { expect(ORGAN_IDS).toContain(organId); } }); it("should correctly map specific HPO labels", () => { expect(HPO_LABEL_TO_ORGAN["Abnormality of the digestive system"]).toBe("digestive"); expect(HPO_LABEL_TO_ORGAN["Growth abnormality"]).toBe("growth"); expect(HPO_LABEL_TO_ORGAN["Abnormality of the eye"]).toBe("eye"); }); }); describe("ORGAN_TO_HPO_LABEL mapping", () => { it("should map all OrganIds to HPO labels", () => { expect(Object.keys(ORGAN_TO_HPO_LABEL)).toHaveLength(ORGAN_IDS.length); }); it("should map each OrganId to a valid HPO label", () => { for (const [_organId, label] of Object.entries(ORGAN_TO_HPO_LABEL)) { expect(HPO_LABELS).toContain(label); } }); it("should correctly map specific OrganIds", () => { expect(ORGAN_TO_HPO_LABEL.digestive).toBe("Abnormality of the digestive system"); expect(ORGAN_TO_HPO_LABEL.growth).toBe("Growth abnormality"); expect(ORGAN_TO_HPO_LABEL.eye).toBe("Abnormality of the eye"); }); }); describe("Bidirectional mapping consistency", () => { it("should have consistent bidirectional mapping", () => { // HPO_LABEL_TO_ORGAN → ORGAN_TO_HPO_LABEL should return original label for (const [label, organId] of Object.entries(HPO_LABEL_TO_ORGAN)) { const reverseLabel = ORGAN_TO_HPO_LABEL[organId as OrganId]; expect(reverseLabel).toBe(label); } }); it("should have consistent reverse mapping", () => { // ORGAN_TO_HPO_LABEL → HPO_LABEL_TO_ORGAN should return original organId for (const [organId, label] of Object.entries(ORGAN_TO_HPO_LABEL)) { const reverseOrganId = HPO_LABEL_TO_ORGAN[label as Exclude]; expect(reverseOrganId).toBe(organId); } }); }); });