endtoend-test-psl/tests/Psl/Math/MinByTest.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 MinByTest extends TestCase
{
2019-12-26 21:03:29 +01:00
/**
* @dataProvider provideData
*/
2020-08-27 16:44:22 +02:00
public function testMinBy($expected, array $values, callable $fun): void
2019-12-26 21:03:29 +01:00
{
self::assertSame($expected, Math\min_by($values, $fun));
}
public function provideData(): array
{
return [
[
'qux',
['foo', 'bar', 'baz', 'qux', 'foobar', 'bazqux'],
fn ($value) => Str\length($value)
],
[
['foo'],
[
['foo'],
['foo', 'bar'],
['foo', 'bar', 'baz']
],
fn ($arr) => Iter\count($arr)
],
[
2019-12-26 21:03:29 +01:00
0,
2020-08-27 16:44:22 +02:00
[...Iter\range(0, 9)],
2019-12-26 21:03:29 +01:00
fn ($i) => $i
],
[
2019-12-26 21:03:29 +01:00
null,
[],
fn ($i) => $i
]
];
}
2019-12-24 01:52:07 +01:00
}