1 import { deduplicate } from './duplicate';
3 describe('deduplicate function', () => {
4 it('should remove duplicate items based on provided equality function', () => {
5 const eq = (a: number) => (b: number) => a === b;
6 const arr = [1, 2, 2, 3, 3, 3];
7 expect(deduplicate(arr, eq)).toEqual([1, 2, 3]);
10 it('should handle empty array', () => {
11 const eq = (a: string) => (b: string) => a === b;
12 const arr: string[] = [];
13 expect(deduplicate(arr, eq)).toEqual([]);
16 it('should handle custom equality function', () => {
17 type TestItem = { itemId: number; shareId: number };
18 const eq = (a: TestItem) => (b: TestItem) => a.itemId === b.itemId && a.shareId === b.shareId;
20 const arr: TestItem[] = [
21 { itemId: 0, shareId: 1 },
22 { itemId: 1, shareId: 2 },
23 { itemId: 1, shareId: 2 },
26 expect(deduplicate(arr, eq)).toEqual([
27 { itemId: 0, shareId: 1 },
28 { itemId: 1, shareId: 2 },