fix(core): update

This commit is contained in:
2023-08-02 14:39:58 +02:00
parent 9c5cc17968
commit 64557a8ac3
12 changed files with 2270 additions and 29555 deletions

View File

@ -1,13 +1,36 @@
import { expect, tap } from '@pushrocks/tapbundle';
import * as smartarray from '../ts/index';
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).to.contain(2);
expect(originalArray).to.contain(3);
const result = await smartarray.filter(originalArray, async itemArg => itemArg !== 3);
expect(originalArray).to.contain(2);
expect(result).to.not.contain(3);
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);
});