endtoend-test-psl/tests/Psl/Math/MaxByTest.php

55 lines
1.1 KiB
PHP
Raw Normal View History

2019-12-24 01:52:07 +01:00
<?php
declare(strict_types=1);
namespace Psl\Tests\Math;
use PHPUnit\Framework\TestCase;
2019-12-26 21:03:29 +01:00
use Psl\Iter;
use Psl\Math;
use Psl\Str;
2019-12-24 01:52:07 +01:00
class MaxByTest extends TestCase
{
2019-12-26 21:03:29 +01:00
/**
* @dataProvider provideData
*/
public function testMaxBy($expected, iterable $values, callable $fun): void
{
self::assertSame($expected, Math\max_by($values, $fun));
}
public function provideData(): array
{
return [
[
'bazqux',
['foo', 'bar', 'baz', 'qux', 'foobar', 'bazqux'],
fn ($value) => Str\length($value)
],
[
['foo', 'bar', 'baz'],
[
['foo'],
['foo', 'bar'],
['foo', 'bar', 'baz']
],
fn ($arr) => Iter\count($arr)
],
[
9,
Iter\range(0, 9),
fn ($i) => $i
],
[
null,
[],
fn ($i) => $i
]
];
}
2019-12-24 01:52:07 +01:00
}