GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — develop ( 7af216...ebf010 )
by Baptiste
13:17
created

MapTest::testTake()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 0
loc 14
rs 9.9332
c 1
b 0
f 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Tests\Innmind\Immutable\Fixtures;
5
6
use Innmind\Immutable\Map as Structure;
7
use Innmind\BlackBox\Set;
8
use Fixtures\Innmind\Immutable\Map;
9
use PHPUnit\Framework\TestCase;
10
11
class MapTest extends TestCase
12
{
13
    public function testInterface()
14
    {
15
        $this->assertInstanceOf(
16
            Set::class,
17
            new Map(
18
                'string',
19
                'string',
20
                new Set\Chars,
21
                new Set\Chars
22
            )
23
        );
24
    }
25
26
    public function testOf()
27
    {
28
        $this->assertInstanceOf(
29
            Map::class,
30
            Map::of(
31
                'string',
32
                'string',
33
                new Set\Chars,
34
                new Set\Chars
35
            )
36
        );
37
    }
38
39
    public function testGenerates100ValuesByDefault()
40
    {
41
        $maps = new Map(
42
            'string',
43
            'int',
44
            new Set\Chars,
45
            Set\Integers::any()
46
        );
47
48
        $this->assertInstanceOf(\Generator::class, $maps->values());
49
        $this->assertCount(100, \iterator_to_array($maps->values()));
50
51
        foreach ($maps->values() as $map) {
52
            $this->assertInstanceOf(Structure::class, $map);
53
            $this->assertSame('string', (string) $map->keyType());
54
            $this->assertSame('int', (string) $map->valueType());
55
        }
56
    }
57
58
    public function testGeneratesSequencesOfDifferentSizes()
59
    {
60
        $maps = new Map(
61
            'string',
62
            'string',
63
            new Set\Chars,
64
            new Set\Chars,
65
            Set\Integers::between(0, 50)
66
        );
67
        $sizes = [];
68
69
        foreach ($maps->values() as $map) {
70
            $sizes[] = $map->size();
71
        }
72
73
        $this->assertTrue(\count(\array_unique($sizes)) > 1);
74
    }
75
76
    public function testTake()
77
    {
78
        $maps1 = new Map(
79
            'string',
80
            'string',
81
            new Set\Chars,
82
            new Set\Chars
83
        );
84
        $maps2 = $maps1->take(50);
85
86
        $this->assertNotSame($maps1, $maps2);
87
        $this->assertInstanceOf(Map::class, $maps2);
88
        $this->assertCount(100, \iterator_to_array($maps1->values()));
89
        $this->assertCount(50, \iterator_to_array($maps2->values()));
90
    }
91
92
    public function testFilter()
93
    {
94
        $maps1 = new Map(
95
            'string',
96
            'string',
97
            new Set\Chars,
98
            new Set\Chars
99
        );
100
        $maps2 = $maps1->filter(static function($map): bool {
101
            return $map->size() % 2 === 0;
102
        });
103
104
        $this->assertNotSame($maps1, $maps2);
105
        $this->assertInstanceOf(Map::class, $maps2);
106
107
        $values1 = \iterator_to_array($maps1->values());
108
        $values2 = \iterator_to_array($maps2->values());
109
        $values1 = \array_map(function($map) {
110
            return $map->size() % 2;
111
        }, $values1);
112
        $values2 = \array_map(function($map) {
113
            return $map->size() % 2;
114
        }, $values2);
115
        $values1 = \array_unique($values1);
116
        $values2 = \array_unique($values2);
117
        \sort($values1);
118
119
        $this->assertSame([0, 1], \array_values($values1));
120
        $this->assertSame([0], \array_values($values2));
121
    }
122
}
123