import { describe, expect, it, jest } from '@jest/globals';
import * as arr from '../js/ext/array.js';

describe('filterWithin(<array>, <test>)', () => {

    it('Calls <test> on every element of <array> and removes in-place those on which the test fails.', () => {
        const array = [3,4,7,8,10];
        const expected = [3,7];
        const test = jest.fn(num => num & 0x01)

        const removed = arr.filterWithin(array, test)
        expect(test).toBeCalledTimes(5)
        expect(array).toStrictEqual(expected)
        expect(removed).toStrictEqual(3)
    })

})

describe('removeWithin(<array>, <test>)', () => {

    it('Calls <test> on every element of <array> and removes in-place those that satisfy the test', () => {
        const array = [3,4,7,8,10];
        const expected = [4,8,10];
        const test = jest.fn(num => num & 0x01)

        const removed = arr.removeWithin(array, test)
        expect(test).toBeCalledTimes(5)
        expect(array).toStrictEqual(expected)
        expect(removed).toStrictEqual(2)
    })

})
