Increase code coverage (#6)

Increase code coverage
This commit is contained in:
Saif Eddin G 2019-12-26 15:49:09 +01:00 committed by GitHub
commit c3256b0e4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 12 deletions

View File

@ -40,19 +40,21 @@ 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(
Iter\map(
$iterable,
/**
* @psalm-param Tv $value
*
* @psalm-return array{0: Ts, 1: Tv}
*/
fn ($value) => [$scalar_func($value), $value],
),
$tuple_comparator
$sorted = sort_with_keys(
Iter\map(
$iterable,
/**
* @psalm-param Tv $value
*
* @psalm-return array{0: Ts, 1: Tv}
*/
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);

View File

@ -18,6 +18,11 @@ class BytesTest extends TestCase
self::assertSame(32, Str\Byte\length($random));
}
public function testBytesEarlyReturnForZeroLength(): void
{
self::assertSame('', Random\bytes(0));
}
public function testBytesThrowsForNegativeLength(): void
{
$this->expectException(Exception\InvariantViolationException::class);

View File

@ -31,6 +31,11 @@ class StringTest extends TestCase
}
}
public function testStringEarlyReturnForZeroLength(): void
{
self::assertSame('', Random\string(0));
}
public function testStringThrowsForNegativeLength(): void
{
$this->expectException(Exception\InvariantViolationException::class);