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\Arr;
|
|
|
|
use Psl\Iter;
|
|
|
|
use Psl\Math;
|
2019-12-24 01:52:07 +01:00
|
|
|
|
|
|
|
class MedianTest extends TestCase
|
|
|
|
{
|
2019-12-26 21:03:29 +01:00
|
|
|
/**
|
|
|
|
* @dataProvider provideData
|
|
|
|
*/
|
2020-08-27 16:44:22 +02:00
|
|
|
public function testMedian($expected, array $numbers): void
|
2019-12-26 21:03:29 +01:00
|
|
|
{
|
|
|
|
self::assertSame($expected, Math\median($numbers));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideData(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
5.0,
|
|
|
|
[
|
|
|
|
10,
|
|
|
|
5,
|
|
|
|
...Iter\range(0, 9, 2),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
|
|
|
|
[
|
|
|
|
6.5,
|
|
|
|
[
|
|
|
|
18,
|
|
|
|
15,
|
2020-08-27 16:44:22 +02:00
|
|
|
...Iter\range(0, 10),
|
2019-12-26 21:03:29 +01:00
|
|
|
15,
|
|
|
|
],
|
|
|
|
],
|
|
|
|
|
|
|
|
[
|
|
|
|
22.5,
|
|
|
|
[
|
|
|
|
19,
|
|
|
|
15,
|
|
|
|
...Iter\range(0, 45, 5),
|
|
|
|
52,
|
|
|
|
64,
|
|
|
|
],
|
|
|
|
],
|
|
|
|
|
|
|
|
[
|
|
|
|
100.0,
|
|
|
|
Arr\fill(100, 0, 100)
|
|
|
|
],
|
|
|
|
|
|
|
|
[
|
|
|
|
null,
|
|
|
|
[]
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
2019-12-24 01:52:07 +01:00
|
|
|
}
|