Skip to content

Commit

Permalink
toBeMinOf()
Browse files Browse the repository at this point in the history
  • Loading branch information
faissaloux committed Jul 31, 2024
1 parent 6d150d6 commit b211a66
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Expectation.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,13 @@ public function toBeMaxOf(array $stack): PestExpectation
{
return expect($this->value === max($stack))->toBeTrue();
}

/**
* @param array<int|float> $stack
* @return PestExpectation<TValue>
*/
public function toBeMinOf(array $stack): PestExpectation
{
return expect($this->value === min($stack))->toBeTrue();
}
}
27 changes: 27 additions & 0 deletions tests/toBeMinOf.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use PHPUnit\Framework\ExpectationFailedException;

it('passes', function (int|float $value, array $stack): void {
expect($value)->toBeMinOf($stack);
})->with([
[-6, [-6, 0, 1]],
[-6, [-6, -2, -1]],
[2.4, [2.4, 4.2, 6]],
]);

it('passes not', function (int|float $value, array $stack): void {
expect($value)->not->toBeMinOf($stack);
})->with([
[4, [2, 4, 6]],
[0, [2, 4]],
[5.5, [2, 4.2, 5.5, 6]],
]);

test('failures', function (): void {
expect(4)->toBeMinOf([2, 4, 6]);
})->throws(ExpectationFailedException::class);

test('failures not', function (): void {
expect(2)->not->toBeMinOf([2, 4, 6]);
})->throws(ExpectationFailedException::class);

0 comments on commit b211a66

Please sign in to comment.