mirror of
https://github.com/danog/endtoend-test-psl.git
synced 2024-11-27 04:46:00 +01:00
commit
c3256b0e4f
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user