From b439136ed5bdfc2abc1bbda8bd5922854c959a1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Wed, 14 Sep 2022 15:50:39 +0200 Subject: [PATCH] Drop comparison /w `PHP_FLOAT_EPSILON` --- src/Framework/Constraint/IsIdentical.php | 13 +------------ tests/unit/Framework/AssertTest.php | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/Framework/Constraint/IsIdentical.php b/src/Framework/Constraint/IsIdentical.php index b4beac3c9ec..99ab65848f0 100644 --- a/src/Framework/Constraint/IsIdentical.php +++ b/src/Framework/Constraint/IsIdentical.php @@ -9,13 +9,8 @@ */ namespace PHPUnit\Framework\Constraint; -use const PHP_FLOAT_EPSILON; -use function abs; use function get_class; use function is_array; -use function is_float; -use function is_infinite; -use function is_nan; use function is_object; use function is_string; use function sprintf; @@ -60,13 +55,7 @@ public function __construct($value) */ public function evaluate($other, string $description = '', bool $returnResult = false) { - if (is_float($this->value) && is_float($other) && - !is_infinite($this->value) && !is_infinite($other) && - !is_nan($this->value) && !is_nan($other)) { - $success = abs($this->value - $other) < PHP_FLOAT_EPSILON; - } else { - $success = $this->value === $other; - } + $success = $this->value === $other; if ($returnResult) { return $success; diff --git a/tests/unit/Framework/AssertTest.php b/tests/unit/Framework/AssertTest.php index 51d0cdd2855..f51975c3ead 100644 --- a/tests/unit/Framework/AssertTest.php +++ b/tests/unit/Framework/AssertTest.php @@ -2418,9 +2418,15 @@ protected function sameValues(): array // integers [0, 0], // floats + [1.0, 1.0], [2.3, 2.3], - [1 / 3, 1 - 2 / 3], + [1 / 3, 1 / 3], + [1 - 2 / 3, 1 - 2 / 3], + [5.5E+123, 5.5E+123], + [5.5E-123, 5.5E-123], [log(0), log(0)], + [INF, INF], + [-INF, -INF], // arrays [[], []], [[0 => 1], [0 => 1]], @@ -2474,6 +2480,12 @@ protected function notEqualValues(): array [[[2.3]], [[4.2]], 0.5], [new Struct(2.3), new Struct(4.2), 0.5], [[new Struct(2.3)], [new Struct(4.2)], 0.5], + [1 / 3, 1 - 2 / 3], + [1 / 3, '0.33333333333333337'], + [1 - 2 / 3, '3333333333333333'], + [5.5E+123, 5.6E+123], + [5.5E-123, 5.6E-123], + [5.5E+123, 5.5E-123], // NAN [NAN, NAN], // arrays @@ -2648,8 +2660,12 @@ protected function equalValues(): array ['0', 0], [2.3, '2.3'], ['2.3', 2.3], - [(string) (1 / 3), 1 - 2 / 3], - [1 / 3, (string) (1 - 2 / 3)], + [1, 1.0], + [1.0, '1'], + [1 / 3, '0.3333333333333333'], + [1 - 2 / 3, '0.33333333333333337'], + [5.5E+123, '5.5E+123'], + [5.5E-123, '5.5E-123'], ['string representation', new ClassWithToString], [new ClassWithToString, 'string representation'], ];