generated from spawnia/php-package-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumberTest.php
More file actions
39 lines (35 loc) · 1.04 KB
/
NumberTest.php
File metadata and controls
39 lines (35 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php declare(strict_types=1);
namespace MLL\Utils\Tests;
use MLL\Utils\Number;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
final class NumberTest extends TestCase
{
/**
* @dataProvider clampProvider
*
* @param float|int $min
* @param float|int $max
* @param float|int $current
* @param float|int $expected
*/
#[DataProvider('clampProvider')]
public function testClamp($min, $max, $current, $expected): void
{
self::assertSame($expected, Number::clamp($min, $max, $current));
}
/** @return iterable<array{int|float, int|float, int|float, int|float}> */
public static function clampProvider(): iterable
{
yield [1, 2, 3, 2];
yield [1, 2, 0, 1];
yield [-1, 2, 0, 0];
yield [1, 3, 2, 2];
yield [0.001, 0.003, 0.002, 0.002];
yield [0.001, 0.003, 0.004, 0.003];
yield [0.001, 0.003, 0.000, 0.001];
yield [-1, +1, 0, 0];
yield [-1, +1, 0.5, 0.5];
yield [-1, +1, -2, -1];
}
}