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

54 lines
1.0 KiB
PHP
Raw Normal View History

2019-12-24 01:52:07 +01:00
<?php
declare(strict_types=1);
namespace Psl\Tests\Math;
use Generator;
2019-12-24 01:52:07 +01:00
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
final class MinByTest extends TestCase
2019-12-24 01:52:07 +01:00
{
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
{
static::assertSame($expected, Math\min_by($values, $fun));
2019-12-26 21:03:29 +01:00
}
public function provideData(): Generator
2019-12-26 21:03:29 +01:00
{
yield [
'qux',
['foo', 'bar', 'baz', 'qux', 'foobar', 'bazqux'],
static fn ($value) => Str\length($value),
];
2019-12-26 21:03:29 +01:00
yield [
['foo'],
2019-12-26 21:03:29 +01:00
[
['foo'],
['foo', 'bar'],
['foo', 'bar', 'baz']
2019-12-26 21:03:29 +01:00
],
static fn ($arr) => Iter\count($arr),
];
2019-12-26 21:03:29 +01:00
yield [
0,
[...Iter\range(0, 9)],
static fn ($i) => $i,
];
2019-12-26 21:03:29 +01:00
yield [
null,
[],
static fn ($i) => $i,
2019-12-26 21:03:29 +01:00
];
}
2019-12-24 01:52:07 +01:00
}