2019-12-24 01:52:07 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Psl\Tests\Arr;
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
2019-12-25 00:35:14 +01:00
|
|
|
use Psl\Arr;
|
|
|
|
use Psl\Collection;
|
2019-12-24 01:52:07 +01:00
|
|
|
|
|
|
|
class UniqueTest extends TestCase
|
|
|
|
{
|
2019-12-25 00:35:14 +01:00
|
|
|
public function testUnique(): void
|
|
|
|
{
|
|
|
|
$array = Arr\fill('foo', 0, 10);
|
|
|
|
|
|
|
|
$unique = Arr\unique($array);
|
|
|
|
|
|
|
|
static::assertCount(1, $unique);
|
|
|
|
|
|
|
|
static::assertSame('foo', Arr\firstx($unique));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUniqueWithObjects(): void
|
|
|
|
{
|
|
|
|
$array = Arr\fill('foo', 0, 10);
|
|
|
|
$object = new Collection\Map([]);
|
|
|
|
$array = Arr\concat($array, Arr\fill($object, 0, 10));
|
|
|
|
|
|
|
|
$unique = Arr\unique($array);
|
|
|
|
|
|
|
|
static::assertCount(2, $unique);
|
|
|
|
|
|
|
|
static::assertSame('foo', Arr\firstx($unique));
|
|
|
|
static::assertSame($object, Arr\lastx($unique));
|
|
|
|
}
|
2019-12-24 01:52:07 +01:00
|
|
|
}
|