Skip to content

Commit

Permalink
utils: test intersection
Browse files Browse the repository at this point in the history
  • Loading branch information
hbbio committed Feb 5, 2024
1 parent a6626a5 commit acf508c
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { describe, it, expect } from "vitest";

import { intersection } from "./utils";

describe("intersection function", () => {
it("returns the correct intersection of two arrays with common elements", () => {
expect(intersection([1, 2, 3], [2, 3, 4])).toEqual([2, 3]);
});

it("returns an empty array when there are no common elements", () => {
expect(intersection([1, 2, 3], [4, 5, 6])).toEqual([]);
});

it("handles identical arrays correctly", () => {
expect(intersection([1, 2, 3], [1, 2, 3])).toEqual([1, 2, 3]);
});

it("returns an empty array when one or both input arrays are empty", () => {
expect(intersection([], [1, 2, 3])).toEqual([]);
expect(intersection([1, 2, 3], [])).toEqual([]);
expect(intersection([], [])).toEqual([]);
});

it("correctly handles duplicates in the input arrays", () => {
expect(intersection([1, 2, 2, 3], [2, 2, 3, 4])).toEqual([2, 2, 3]);
});
});

0 comments on commit acf508c

Please sign in to comment.