smartarray/test/test.ts

38 lines
1.2 KiB
TypeScript
Raw Normal View History

2023-08-02 12:39:58 +00:00
import { expect, tap } from '@push.rocks/tapbundle';
import * as smartarray from '../ts/index.js';
2021-06-29 18:41:15 +00:00
2021-06-29 22:30:11 +00:00
tap.test('should filter', async () => {
2023-08-02 12:39:58 +00:00
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);
2021-06-29 22:30:11 +00:00
console.log(result);
2021-06-29 18:41:15 +00:00
});
tap.start();