Files
pepperplus-ui/test/utils/duplicateIndices.test.ts
2026-01-28 10:34:36 +00:00

26 lines
1006 B
TypeScript

// This program has been developed by students from the bachelor Computer Science at Utrecht
// University within the Software Project course.
// © Copyright Utrecht University (Department of Information and Computing Sciences)
import duplicateIndices from "../../src/utils/duplicateIndices.ts";
describe("duplicateIndices (unit)", () => {
it("returns an empty array for empty input", () => {
expect(duplicateIndices<number>([])).toEqual([]);
});
it("returns an empty array when no duplicates exist", () => {
expect(duplicateIndices([1, 2, 3, 4])).toEqual([]);
});
it("returns all positions for every duplicated value", () => {
const result = duplicateIndices(["a", "b", "a", "c", "b", "b"]);
expect(result.sort()).toEqual([0, 1, 2, 4, 5]);
});
it("only treats identical references as duplicate objects", () => {
const shared = { v: 1 };
const result = duplicateIndices([shared, { v: 1 }, shared, shared]);
expect(result.sort()).toEqual([0, 2, 3]);
});
});