Skip to content

Commit 56c0bd8

Browse files
committed
toBeMaxOf()
1 parent a74d6d3 commit 56c0bd8

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/Expectation.php

+9
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,13 @@ public function toBeAbsoluteOf(int|float $number): PestExpectation
135135
{
136136
return expect($this->value === abs($number))->toBeTrue("$this->value doesn't equal abs($number)");
137137
}
138+
139+
/**
140+
* @param array<int|float> $stack
141+
* @return PestExpectation<TValue>
142+
*/
143+
public function toBeMaxOf(array $stack): PestExpectation
144+
{
145+
return expect($this->value === max($stack))->toBeTrue();
146+
}
138147
}

tests/toBeMaxOf.php

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
use PHPUnit\Framework\ExpectationFailedException;
4+
5+
it('passes', function (int|float $value, array $stack): void {
6+
expect($value)->toBeMaxOf($stack);
7+
})->with([
8+
[1, [-6, 0, 1]],
9+
[6, [-6, 0, 6]],
10+
[5.5, [2, 4.2, 5.5]],
11+
]);
12+
13+
it('passes not', function (int|float $value, array $stack): void {
14+
expect($value)->not->toBeMaxOf($stack);
15+
})->with([
16+
[4, [2, 4, 6]],
17+
[6, [2, 4]],
18+
[5.5, [2, 4.2, 5.5, 6]],
19+
]);
20+
21+
test('failures', function (): void {
22+
expect(4)->toBeMaxOf([2, 4, 6]);
23+
})->throws(ExpectationFailedException::class);
24+
25+
test('failures not', function (): void {
26+
expect(6)->not->toBeMaxOf([2, 4, 6]);
27+
})->throws(ExpectationFailedException::class);

0 commit comments

Comments
 (0)