2020-09-02 02:21:00 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Psl\Tests\Arr;
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Psl;
|
|
|
|
use Psl\Arr;
|
|
|
|
|
2020-10-15 10:18:03 +02:00
|
|
|
final class TakeTest extends TestCase
|
2020-09-02 02:21:00 +02:00
|
|
|
{
|
|
|
|
public function testTake(): void
|
|
|
|
{
|
|
|
|
$result = Arr\take([-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5], 3);
|
|
|
|
|
2020-10-15 10:18:03 +02:00
|
|
|
static::assertSame([-5, -4, -3], $result);
|
2020-09-02 02:21:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testTakeThrowsIfLengthIsNegative(): void
|
|
|
|
{
|
|
|
|
$this->expectException(Psl\Exception\InvariantViolationException::class);
|
|
|
|
$this->expectExceptionMessage('Length must be non-negative.');
|
|
|
|
|
|
|
|
Arr\take([1, 2, 3], -3);
|
|
|
|
}
|
|
|
|
}
|