[Arr] increase code coverage

This commit is contained in:
azjezz 2019-12-26 15:45:26 +01:00
parent 1d27476584
commit 5bf80569ec
2 changed files with 22 additions and 12 deletions

View File

@ -40,8 +40,7 @@ function sort_with_keys_by(iterable $iterable, callable $scalar_func, ?callable
fn ($a, $b): int => $a[0] <=> $b[0];
}
$result = Iter\map_with_key(
sort_with_keys(
$sorted = sort_with_keys(
Iter\map(
$iterable,
/**
@ -52,7 +51,10 @@ function sort_with_keys_by(iterable $iterable, callable $scalar_func, ?callable
fn ($value) => [$scalar_func($value), $value],
),
$tuple_comparator
),
);
$result = Iter\map_with_key(
$sorted,
/**
* @psalm-param Tk $k
* @psalm-param array{0: Ts, 1: Tv} $v

View File

@ -19,6 +19,14 @@ class RandomTest extends TestCase
static::assertContains($value, $values);
}
public function testRandomWithOneItem(): void
{
$values = ['a'];
$value = Arr\random($values);
static::assertSame('a', $value);
}
public function testRandomThrowsWhenTheGivenArrayIsEmpty(): void
{
$this->expectException(Exception\InvariantViolationException::class);