59 lines
1.8 KiB
PHP
59 lines
1.8 KiB
PHP
<?php
|
|
/**
|
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
|
* @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('::map()', function () {
|
|
test('maps an array', function () {
|
|
expect([1, 2, 3] |> Arr::map(fn ($it) => $it * 2))->toEqual([2, 4, 6]);
|
|
});
|
|
});
|