import { describe, it, expect } from "bun:test";
import { calculateIntersectionWeight, getIntersection } from "./code";
describe("Intersection", () => {
it("Identical Arrays (1)", () => {
const aTerms = ["apple", "banana", "cherry"];
const bTerms = ["apple", "banana", "cherry"];
const result = calculateIntersectionWeight(aTerms, bTerms);
expect(result).toBe(1);
});
it("Disjoint Arrays (0)", () => {
const aTerms = ["apple", "banana", "cherry"];
const bTerms = ["date", "fig", "grape"];
const result = calculateIntersectionWeight(aTerms, bTerms);
expect(result).toBe(0);
});
it("Partial Intersection", () => {
const aTerms = ["apple", "banana", "cherry"];
const bTerms = ["banana", "cherry", "date"];
const result = calculateIntersectionWeight(aTerms, bTerms);
expect(result).toBe(2 / 3);
});
it("Duplicate Items", () => {
const aTerms = ["apple", "banana", "banana", "cherry"];
const bTerms = ["banana", "cherry", "cherry", "date"];
const result = calculateIntersectionWeight(aTerms, bTerms);
expect(result).toBe(2 / 4); // Intersection size is 2, min length is 4
});
it("One Empty Array (0)", () => {
const aTerms: string[] = [];
const bTerms = ["apple", "banana", "cherry"];
const result = calculateIntersectionWeight(aTerms, bTerms);
expect(result).toBe(0);
});
it("Two Empty Arrays (0)", () => {
const aTerms: string[] = [];
const bTerms: string[] = [];
const result = calculateIntersectionWeight(aTerms, bTerms);
expect(result).toBe(0);
});
it("Case Sensitive", () => {
const aTerms = ["apple", "Banana", "cherry"];
const bTerms = ["Apple", "banana", "Cherry"];
const result = calculateIntersectionWeight(aTerms, bTerms);
expect(result).toBe(0); // Case-sensitive comparison
});
it("Subsets", () => {
const aTerms = ["apple", "banana"];
const bTerms = ["apple", "banana", "cherry", "date"];
const result = calculateIntersectionWeight(aTerms, bTerms);
expect(result).toBe(2 / 2); // Intersection size is 2, min length is 2
});
it("Two Arrays", () => {
const aTerms = ["apple", "banana", "cherry"];
const bTerms = ["banana", "cherry", "date"];
const result = getIntersection(aTerms, bTerms);
expect(result).toEqual(["banana", "cherry"]);
});
it("Disjoint Result", () => {
const aTerms = ["apple", "banana", "cherry"];
const bTerms = ["date", "fig", "grape"];
const result = getIntersection(aTerms, bTerms);
expect(result).toEqual([]);
});
it("Removes Duplicates", () => {
const aTerms = ["apple", "banana", "banana", "cherry"];
const bTerms = ["banana", "cherry", "cherry", "date"];
const result = getIntersection(aTerms, bTerms);
expect(result).toEqual(["banana", "cherry"]);
});
});