1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
|
4
|
|
|
namespace Tests\Innmind\Immutable\Monoid; |
5
|
|
|
|
6
|
|
|
use Innmind\Immutable\{ |
7
|
|
|
Monoid\MergeSet, |
8
|
|
|
Monoid, |
9
|
|
|
Set, |
10
|
|
|
}; |
11
|
|
|
use PHPUnit\Framework\TestCase; |
12
|
|
|
use Innmind\BlackBox\{ |
13
|
|
|
PHPUnit\BlackBox, |
14
|
|
|
Set as DataSet, |
15
|
|
|
}; |
16
|
|
|
use Fixtures\Innmind\Immutable\Set as FSet; |
17
|
|
|
use Properties\Innmind\Immutable\Monoid as PMonoid; |
18
|
|
|
|
19
|
|
|
class MergeSetTest extends TestCase |
20
|
|
|
{ |
21
|
|
|
use BlackBox; |
22
|
|
|
|
23
|
|
|
public function testInterface() |
24
|
|
|
{ |
25
|
|
|
$this->assertInstanceOf(Monoid::class, MergeSet::of()); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testCombine() |
29
|
|
|
{ |
30
|
|
|
$set = MergeSet::of()->combine( |
31
|
|
|
Set::of(1, 3), |
|
|
|
|
32
|
|
|
Set::of(2, 4, 3), |
33
|
|
|
); |
34
|
|
|
|
35
|
|
|
$this->assertInstanceOf(Set::class, $set); |
36
|
|
|
$this->assertSame( |
37
|
|
|
[1, 3, 2, 4], |
38
|
|
|
$set->toList(), |
39
|
|
|
); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @dataProvider properties |
44
|
|
|
*/ |
45
|
|
|
public function testHoldProperty($property) |
46
|
|
|
{ |
47
|
|
|
$this |
48
|
|
|
->forAll($property) |
49
|
|
|
->then(static function($property) { |
50
|
|
|
$property->ensureHeldBy(MergeSet::of()); |
51
|
|
|
}); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testHoldProperties() |
55
|
|
|
{ |
56
|
|
|
$this |
57
|
|
|
->forAll(PMonoid::properties($this->set(), $this->equals())) |
58
|
|
|
->then(static function($properties) { |
59
|
|
|
$properties->ensureHeldBy(MergeSet::of()); |
60
|
|
|
}); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function properties(): iterable |
64
|
|
|
{ |
65
|
|
|
foreach (PMonoid::list($this->set(), $this->equals()) as $property) { |
66
|
|
|
yield [$property]; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function equals(): callable |
71
|
|
|
{ |
72
|
|
|
return static fn($a, $b) => $a->equals($b); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
private function set(): DataSet |
76
|
|
|
{ |
77
|
|
|
return FSet::of( |
78
|
|
|
DataSet\AnyType::any(), |
79
|
|
|
DataSet\Integers::between(1, 10), |
80
|
|
|
); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|