exceptions
1 year ago
ArrayComparator.php
1 year ago
Comparator.php
1 year ago
ComparisonFailure.php
1 year ago
DOMNodeComparator.php
1 year ago
DateTimeComparator.php
1 year ago
DoubleComparator.php
1 year ago
ExceptionComparator.php
1 year ago
Factory.php
1 year ago
MockObjectComparator.php
1 year ago
NumericComparator.php
1 year ago
ObjectComparator.php
1 year ago
ResourceComparator.php
1 year ago
ScalarComparator.php
1 year ago
SplObjectStorageComparator.php
1 year ago
TypeComparator.php
1 year ago
DoubleComparator.php
62 lines
| 1 | <?php declare(strict_types=1); |
| 2 | /* |
| 3 | * This file is part of sebastian/comparator. |
| 4 | * |
| 5 | * (c) Sebastian Bergmann <sebastian@phpunit.de> |
| 6 | * |
| 7 | * For the full copyright and license information, please view the LICENSE |
| 8 | * file that was distributed with this source code. |
| 9 | */ |
| 10 | namespace SebastianBergmann\Comparator; |
| 11 | |
| 12 | use function is_float; |
| 13 | use function is_numeric; |
| 14 | |
| 15 | /** |
| 16 | * Compares doubles for equality. |
| 17 | * |
| 18 | * @deprecated since v3.0.5 and v4.0.8 |
| 19 | */ |
| 20 | class DoubleComparator extends NumericComparator |
| 21 | { |
| 22 | /** |
| 23 | * Smallest value available in PHP. |
| 24 | * |
| 25 | * @var float |
| 26 | */ |
| 27 | public const EPSILON = 0.0000000001; |
| 28 | |
| 29 | /** |
| 30 | * Returns whether the comparator can compare two values. |
| 31 | * |
| 32 | * @param mixed $expected The first value to compare |
| 33 | * @param mixed $actual The second value to compare |
| 34 | * |
| 35 | * @return bool |
| 36 | */ |
| 37 | public function accepts($expected, $actual) |
| 38 | { |
| 39 | return (is_float($expected) || is_float($actual)) && is_numeric($expected) && is_numeric($actual); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Asserts that two values are equal. |
| 44 | * |
| 45 | * @param mixed $expected First value to compare |
| 46 | * @param mixed $actual Second value to compare |
| 47 | * @param float $delta Allowed numerical distance between two values to consider them equal |
| 48 | * @param bool $canonicalize Arrays are sorted before comparison when set to true |
| 49 | * @param bool $ignoreCase Case is ignored when set to true |
| 50 | * |
| 51 | * @throws ComparisonFailure |
| 52 | */ |
| 53 | public function assertEquals($expected, $actual, $delta = 0.0, $canonicalize = false, $ignoreCase = false)/*: void*/ |
| 54 | { |
| 55 | if ($delta == 0) { |
| 56 | $delta = self::EPSILON; |
| 57 | } |
| 58 | |
| 59 | parent::assertEquals($expected, $actual, $delta, $canonicalize, $ignoreCase); |
| 60 | } |
| 61 | } |
| 62 |