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;
2020-08-27 16:44:22 +02:00
use Psl\Arr;
2019-12-26 21:03:29 +01:00
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
*/
2020-08-27 16:44:22 +02:00
public function testMaxBy($expected, array $values, callable $fun): void
2019-12-26 21:03:29 +01:00
{
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']
],
2020-08-27 16:44:22 +02:00
fn ($arr) => Arr\count($arr)
2019-12-26 21:03:29 +01:00
],
[
9,
2020-08-27 16:44:22 +02:00
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
2019-12-26 21:03:29 +01:00
fn ($i) => $i
],
[
null,
[],
fn ($i) => $i
]
];
}
2019-12-24 01:52:07 +01:00
}