Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
- `Innmind\BlackBox\Set::disableShrinking()`
- `Innmind\BlackBox\Set::toSet()`
- `Innmind\BlackBox\Set::zip()`
- `Innmind\BlackBox\Set::properties()`
- `Innmind\BlackBox\Set::slice()`
- `Innmind\BlackBox\Set\Provider\Strings::mutuallyExclusive()`
- `Innmind\BlackBox\Runner\Proof::tagged()`
- `Innmind\BlackBox\Runner\Proof::disableShrinking()`
- `Innmind\BlackBox\Application::mapProof()`
Expand All @@ -27,6 +30,9 @@
- PHPUnit attributes `Group` and `DataProvider` are now longer read when running tests with BlackBox, use the `Innmind\BlackBox\` prefixed ones instead
- All proofs will fail if they throw an exception (instead of stopping the script)
- `Innmind\BlackBox\Runner\Printer` is now a final class
- `Innmind\BlackBox\Set\MadeOf` have been moved to `Innmind\BlackBox\Set\Provider\Strings\MadeOf`
- `Innmind\BlackBox\Set\Properties` have been moved to `Innmind\BlackBox\Set\Provider\Properties`
- `Innmind\BlackBox\Set\Slice` have been moved to `Innmind\BlackBox\Set\Provider\Slice`

### Removed

Expand Down Expand Up @@ -79,6 +85,7 @@
- `Innmind\BlackBox\Set\Tuple`
- `Innmind\BlackBox\Set\Type`
- `Innmind\BlackBox\Set\Unicode`
- `Innmind\BlackBox\Set\MutuallyExclusive`
- `Innmind\BlackBox\Set\UnsafeStrings::any()`
- `Innmind\BlackBox\Set\Uuid`
- `Innmind\BlackBox\Set::decorate()`
Expand Down
2 changes: 1 addition & 1 deletion fixtures/proofs.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
yield $prove
->properties(
'Counter properties',
Set\Properties::any(
Set::properties(
DownAndUpIsAnIdentityFunction::any(),
DownChangeState::any(),
LowerBoundAtZero::any(),
Expand Down
2 changes: 1 addition & 1 deletion proofs/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
->tryToProve(static function($prove) {
yield $prove->properties(
'Counter properties',
Set\Properties::any(
Set::properties(
DownAndUpIsAnIdentityFunction::any(),
DownChangeState::any(),
LowerBoundAtZero::any(),
Expand Down
4 changes: 2 additions & 2 deletions proofs/set/mutuallyExclusive.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

return static function($prove) {
yield $prove
->proof('Set\MutuallyExclusive')
->given(Set\MutuallyExclusive::of(
->proof('Set::strings()->mutuallyExclusive()')
->given(Set::strings()->mutuallyExclusive(
Set::strings()->madeOf(Set::strings()->unicode()->char(), Set::strings()->chars()),
Set::strings()->madeOf(Set::strings()->unicode()->char(), Set::strings()->chars()),
Set::strings()->madeOf(Set::strings()->unicode()->char(), Set::strings()->chars()),
Expand Down
8 changes: 4 additions & 4 deletions proofs/set/slice.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

return static function($prove) {
yield $prove
->proof('Set\Slice')
->proof('Set::slice()')
->given(
Set::sequence(Set::type())->atLeast(11),
Set\Slice::between(10, 20),
Set::slice()->between(10, 20),
)
->test(static function($assert, $values, $slice) {
$subset = $slice($values);
Expand All @@ -31,10 +31,10 @@
->tag(Tag::ci, Tag::local);

yield $prove
->proof('Set\Slice min length')
->proof('Set::slice() min length')
->given(
Set::sequence(Set::type())->atLeast(2),
Set\Slice::any()->atLeast(2),
Set::slice()->atLeast(2),
)
->test(static function($assert, $values, $slice) {
$subset = $slice($values);
Expand Down
23 changes: 23 additions & 0 deletions src/Set.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,29 @@ public static function strings(): Provider\Strings
return Provider\Strings::of(self::build(...));
}

/**
* @psalm-pure
*
* @no-named-arguments
*
* @param self<Property>|Provider<Property> $first
* @param self<Property>|Provider<Property> $properties
*/
#[\NoDiscard]
public static function properties(self|Provider $first, self|Provider ...$properties): Provider\Properties
{
return Provider\Properties::any($first, ...$properties);
}

/**
* @psalm-pure
*/
#[\NoDiscard]
public static function slice(): Provider\Slice
{
return Provider\Slice::any();
}

/**
* @psalm-pure
*
Expand Down
47 changes: 0 additions & 47 deletions src/Set/MutuallyExclusive.php

This file was deleted.

5 changes: 4 additions & 1 deletion src/Set/Properties.php → src/Set/Provider/Properties.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php
declare(strict_types = 1);

namespace Innmind\BlackBox\Set;
namespace Innmind\BlackBox\Set\Provider;

use Innmind\BlackBox\{
Set,
Set\Provider,
Set\Seed,
Property as Concrete,
Properties as Ensure,
Exception\EmptySet,
Expand All @@ -25,6 +27,7 @@ private function __construct(private Set|Provider $properties)
}

/**
* @internal
* @psalm-pure
*
* @no-named-arguments
Expand Down
14 changes: 10 additions & 4 deletions src/Set/Slice.php → src/Set/Provider/Slice.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php
declare(strict_types = 1);

namespace Innmind\BlackBox\Set;
namespace Innmind\BlackBox\Set\Provider;

use Innmind\BlackBox\{
Set,
Set\Provider,
Set\Seed,
Util\Slice as Util,
Exception\EmptySet,
};
Expand Down Expand Up @@ -38,15 +40,19 @@ public static function any(): self
}

/**
* @psalm-pure
* @psalm-mutation-free
*
* @param int<0, max> $min
* @param int<0, max> $max
*/
#[\NoDiscard]
public static function between(int $min, int $max): self
public function between(int $min, int $max): self
{
return new self($min, $max, 0);
return new self(
$min,
$max,
$this->atLeast,
);
}

/**
Expand Down
42 changes: 40 additions & 2 deletions src/Set/Provider/Strings.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,47 @@ public function unsafe(): Set
* @param Set<string>|Provider<string> $rest
*/
#[\NoDiscard]
public function madeOf(Set|Provider $first, Set|Provider ...$rest): Set\MadeOf
public function madeOf(Set|Provider $first, Set|Provider ...$rest): Strings\MadeOf
{
return Set\MadeOf::of($first, ...$rest);
return Strings\MadeOf::of($first, ...$rest);
}

/**
* @psalm-pure
* @no-named-arguments
*
* @param Set<string>|Provider<string> $first
* @param Set<string>|Provider<string> $second
* @param Set<string>|Provider<string> $rest
*
* @return Set<non-empty-list<string>>
*/
#[\NoDiscard]
public function mutuallyExclusive(
Set|Provider $first,
Set|Provider $second,
Set|Provider ...$rest,
): Set {
/** @var Set<non-empty-list<string>> */
return Set::tuple(
$first,
$second,
...$rest,
)->filter(static function($strings) {
foreach ($strings as $i => $a) {
foreach ($strings as $j => $b) {
if ($i === $j) {
continue;
}

if (\str_contains(\strtolower($a), \strtolower($b))) {
return false;
}
}
}

return true;
});
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/Set/MadeOf.php → src/Set/Provider/Strings/MadeOf.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php
declare(strict_types = 1);

namespace Innmind\BlackBox\Set;
namespace Innmind\BlackBox\Set\Provider\Strings;

use Innmind\BlackBox\{
Set,
Set\Provider,
Set\Seed,
Exception\EmptySet,
};

Expand All @@ -23,6 +25,7 @@ private function __construct(private Set|Provider $chars)
}

/**
* @internal
* @psalm-pure
*
* @no-named-arguments
Expand Down
1 change: 0 additions & 1 deletion src/Set/Provider/Strings/Unicode.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
Set,
Set\Provider,
Set\Seed,
Set\MadeOf,
Exception\EmptySet,
};

Expand Down
19 changes: 9 additions & 10 deletions tests/Set/PropertiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
namespace Tests\Innmind\BlackBox\Set;

use Innmind\BlackBox\{
Set\Properties,
Set,
Properties as PropertiesModel,
Properties,
Random,
PHPUnit\BlackBox,
};
Expand All @@ -20,15 +19,15 @@ public function testInterface()
{
$this->assertInstanceOf(
Set\Provider::class,
Properties::any(
Set::properties(
Set::of(new LowerBoundAtZero),
),
);
}

public function testGenerate100ScenariiByDefault()
{
$properties = Properties::any(
$properties = Set::properties(
Set::of(new LowerBoundAtZero),
);

Expand All @@ -45,18 +44,18 @@ public function testGenerate100ScenariiByDefault()

public function testGeneratePropertiesModel()
{
$properties = Properties::any(
$properties = Set::properties(
Set::of(new LowerBoundAtZero),
);

foreach ($properties->toSet()->take(100)->values(Random::mersenneTwister) as $scenario) {
$this->assertInstanceOf(PropertiesModel::class, $scenario->unwrap());
$this->assertInstanceOf(Properties::class, $scenario->unwrap());
}
}

public function testScenariiAreOfDifferentSizes()
{
$properties = Properties::any(
$properties = Set::properties(
Set::of(new LowerBoundAtZero),
);
$sizes = [];
Expand All @@ -70,7 +69,7 @@ public function testScenariiAreOfDifferentSizes()

public function testTake()
{
$properties = Properties::any(
$properties = Set::properties(
Set::of(new LowerBoundAtZero),
)->take(100);
$properties2 = $properties->take(50);
Expand All @@ -83,7 +82,7 @@ public function testTake()

public function testFilter()
{
$properties = Properties::any(
$properties = Set::properties(
Set::of(new LowerBoundAtZero),
);
$properties2 = $properties->filter(static fn($scenario) => \count($scenario->properties()) > 50);
Expand Down Expand Up @@ -111,7 +110,7 @@ public function testFilter()

public function testMaxNumberOfPropertiesGeneratedAtOnce()
{
$properties = Properties::any(
$properties = Set::properties(
Set::of(new LowerBoundAtZero),
)->atMost(50);
$sizes = [];
Expand Down
Loading