38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import { expect, tap } from '@push.rocks/tapbundle';
|
|
import * as smartarray from '../ts/index.js';
|
|
|
|
tap.test('should filter', async () => {
|
|
const originalArray = [1, 2, 3, 4, 5, 6];
|
|
expect(originalArray).toContain(2);
|
|
expect(originalArray).toContain(3);
|
|
const result = await smartarray.filter(originalArray, async (itemArg) => itemArg !== 3);
|
|
expect(originalArray).toContain(2);
|
|
expect(result).not.toContain(3);
|
|
console.log(result);
|
|
});
|
|
|
|
tap.test('should deduplicate', async () => {
|
|
const originalArray = [1, 2, 2, 3, 3, 3, 4, 5, 6, 6];
|
|
const result = await smartarray.deduplicate(originalArray, async (itemArg) => itemArg);
|
|
|
|
// Check the length of the array after deduplication
|
|
expect(result.length).toEqual(6);
|
|
|
|
// Check if the result contains only unique values
|
|
expect(result).toContain(1);
|
|
expect(result).toContain(2);
|
|
expect(result).toContain(3);
|
|
expect(result).toContain(4);
|
|
expect(result).toContain(5);
|
|
expect(result).toContain(6);
|
|
|
|
// Make sure duplicates have been removed
|
|
expect(result.filter(item => item === 2).length).toEqual(1);
|
|
expect(result.filter(item => item === 3).length).toEqual(1);
|
|
expect(result.filter(item => item === 6).length).toEqual(1);
|
|
|
|
console.log(result);
|
|
});
|
|
|
|
tap.start();
|