-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayGroupByTest.php
More file actions
49 lines (43 loc) · 1.05 KB
/
ArrayGroupByTest.php
File metadata and controls
49 lines (43 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
declare(strict_types=1);
namespace Recruiter\Array\Tests;
use PHPUnit\Framework\TestCase;
use function Recruiter\Array\array_group_by;
class ArrayGroupByTest extends TestCase
{
public function testArrayGroupBy(): void
{
$this->assertSame([], array_group_by([]));
$this->assertSame(
[
1 => [1],
2 => [2, 2],
3 => [3, 3],
4 => [4],
],
array_group_by([1, 2, 2, 3, 3, 4]),
);
$this->assertSame(
[
1 => [1, 3, 5],
0 => [2, 4, 6],
],
array_group_by(
[1, 2, 3, 4, 5, 6],
fn ($n): int => $n % 2,
),
);
}
public function testIterator(): void
{
$this->assertSame(
[
1 => [1],
2 => [2, 2],
3 => [3, 3],
4 => [4],
],
array_group_by(new \ArrayIterator([1, 2, 2, 3, 3, 4])),
);
}
}