endtoend-test-psl/tests/Psl/Iter/RepeatTest.php

39 lines
949 B
PHP
Raw Normal View History

2019-12-24 01:52:07 +01:00
<?php
declare(strict_types=1);
namespace Psl\Tests\Iter;
use PHPUnit\Framework\TestCase;
2020-09-01 07:50:23 +02:00
use Psl;
use Psl\Iter;
use Psl\Math;
2019-12-24 01:52:07 +01:00
final class RepeatTest extends TestCase
2019-12-24 01:52:07 +01:00
{
2020-09-01 07:50:23 +02:00
public function testRepeat(): void
{
$result = Iter\repeat(42, 5);
static::assertSame([42, 42, 42, 42, 42], Iter\to_array($result));
2020-09-01 07:50:23 +02:00
}
public function testRepeatThrowsIfNumIsNegative(): void
{
$this->expectException(Psl\Exception\InvariantViolationException::class);
$this->expectExceptionMessage('Number of repetitions must be non-negative.');
Iter\repeat(4, -1);
}
public function testRepeatToInfinityIfNumIsNotProvided(): void
{
$result = Iter\repeat('hello');
$result->seek((int) Math\INFINITY);
static::assertTrue($result->valid());
static::assertSame('hello', $result->current());
static::assertSame((int) Math\INFINITY, $result->key());
2020-09-01 07:50:23 +02:00
}
2019-12-24 01:52:07 +01:00
}