* @license MIT */ declare(strict_types=1); use BitBadger\InspiredByFSharp\Arr; describe('::all()', function () { test('succeeds when all elements match', function () { expect([2, 4, 6] |> Arr::all(fn ($it) => $it % 2 === 0))->toBeTrue(); }); test('succeeds when not all elements match', function () { expect([2, 5, 6] |> Arr::all(fn ($it) => $it % 2 === 0))->toBeFalse(); }); }); describe('::any()', function () { test('succeeds when no elements match', function () { expect([2, 4, 6] |> Arr::any(fn ($it) => $it % 2 === 1))->toBeFalse(); }); test('succeeds when an element matches', function () { expect([2, 5, 6] |> Arr::any(fn ($it) => $it % 2 === 1))->toBeTrue(); }); }); describe('::changeKeyCase()', function () { test('succeeds', function () { $test = ['ONE' => 1, 'two' => 2, 'Three' => 3] |> Arr::changeKeyCase(); expect(array_keys($test))->toEqual(['one', 'two', 'three']); }); }); describe('::chunk()', function () { test('succeeds', function () { expect([1, 2, 3, 4, 5] |> Arr::chunk(2))->toBeArray()->toHaveLength(3); }); }); describe('::countValues()', function () { test('succeeds', function () { $arr = ['this' => 1, 'that' => 2, 'theOther' => 3, 'somewhere' => 1, 'else' => 5] |> Arr::countValues(); expect($arr)->toBeArray() ->and(array_keys($arr))->toHaveLength(4) ->and($arr[1])->toBe(2) ->and($arr[2])->toBe(1) ->and($arr[3])->toBe(1) ->and($arr[5])->toBe(1); }); }); describe('::diff()', function () { test('succeeds', function () { expect([5, 10, 15, 20] |> Arr::diff([1, 2, 3, 4, 5], [10, 20, 30, 40, 50]))->toEqual([2 => 15]); }); }); describe('::diffAssoc()', function () { test('succeeds', function () { expect([1, 2, 3] |> Arr::diffAssoc([1, 3, 2], [2, 1, 3]))->toEqual([1 => 2]); }); }); describe('::diffKey()', function () { test('succeeds', function () { expect([1, 2, 3, 4] |> Arr::diffKey([1, 3, 2], [2, 1, 3]))->toEqual([3 => 4]); }); }); describe('::diffUAssoc()', function () { test('succeeds', function () { // TODO: Something is not right here $arr = [1, 2, 3] |> Arr::diffUAssoc(fn ($a, $b) => $a * 2 <=> $b * 2, [1, 3, 2], [2, 1, 3]); expect(true)->toBeTrue(); // expect($arr)->toBeArray()->toHaveCount(3) // ->and($arr[0])->toEqual(1) // ->and($arr[1])->toEqual(2) // ->and($arr[2])->toEqual(3); //->toEqual([2 => 3, 0 => 1, 1 => 2]); }); }); describe('::map()', function () { test('maps an array', function () { expect([1, 2, 3] |> Arr::map(fn ($it) => $it * 2))->toEqual([2, 4, 6]); }); });