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 — master ( fd060d...258593 )
by Baptiste
03:01 queued 10s
created

SetTest::testTake()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 9
rs 10
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\Set as Structure;
7
use Innmind\BlackBox\Set as DataSet;
8
use Fixtures\Innmind\Immutable\Set;
9
use PHPUnit\Framework\TestCase;
10
11
class SetTest extends TestCase
12
{
13
    public function testInterface()
14
    {
15
        $this->assertInstanceOf(
16
            DataSet::class,
17
            new Set('string', new DataSet\Chars)
18
        );
19
    }
20
21
    public function testOf()
22
    {
23
        $this->assertInstanceOf(
24
            Set::class,
25
            Set::of('string', new DataSet\Chars)
26
        );
27
    }
28
29
    public function testGenerates100ValuesByDefault()
30
    {
31
        $sets = new Set('string', new DataSet\Chars);
32
33
        $this->assertInstanceOf(\Generator::class, $sets->values());
34
        $this->assertCount(100, \iterator_to_array($sets->values()));
35
36
        foreach ($sets->values() as $set) {
37
            $this->assertInstanceOf(Structure::class, $set);
38
            $this->assertSame('string', (string) $set->type());
39
        }
40
    }
41
42
    public function testGeneratesSequencesOfDifferentSizes()
43
    {
44
        $sets = new Set(
45
            'string',
46
            new DataSet\Chars,
47
            DataSet\Integers::between(0, 50)
48
        );
49
        $sizes = [];
50
51
        foreach ($sets->values() as $set) {
52
            $sizes[] = $set->size();
53
        }
54
55
        $this->assertTrue(\count(\array_unique($sizes)) > 1);
56
    }
57
58
    public function testTake()
59
    {
60
        $sets1 = new Set('string', new DataSet\Chars);
61
        $sets2 = $sets1->take(50);
62
63
        $this->assertNotSame($sets1, $sets2);
64
        $this->assertInstanceOf(Set::class, $sets2);
65
        $this->assertCount(100, \iterator_to_array($sets1->values()));
66
        $this->assertCount(50, \iterator_to_array($sets2->values()));
67
    }
68
69
    public function testFilter()
70
    {
71
        $sets1 = new Set('string', new DataSet\Chars);
72
        $sets2 = $sets1->filter(static function($set): bool {
73
            return $set->size() % 2 === 0;
74
        });
75
76
        $this->assertNotSame($sets1, $sets2);
77
        $this->assertInstanceOf(Set::class, $sets2);
78
79
        $values1 = \iterator_to_array($sets1->values());
80
        $values2 = \iterator_to_array($sets2->values());
81
        $values1 = \array_map(function($set) {
82
            return $set->size() % 2;
83
        }, $values1);
84
        $values2 = \array_map(function($set) {
85
            return $set->size() % 2;
86
        }, $values2);
87
        $values1 = \array_unique($values1);
88
        $values2 = \array_unique($values2);
89
        \sort($values1);
90
91
        $this->assertSame([0, 1], \array_values($values1));
92
        $this->assertSame([0], \array_values($values2));
93
    }
94
}
95