comparison vendor/sebastian/comparator/src/NumericComparator.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents 4c8ae668cc8c
children
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
1 <?php 1 <?php
2 /* 2 /*
3 * This file is part of the Comparator package. 3 * This file is part of sebastian/comparator.
4 * 4 *
5 * (c) Sebastian Bergmann <sebastian@phpunit.de> 5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
6 * 6 *
7 * For the full copyright and license information, please view the LICENSE 7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code. 8 * file that was distributed with this source code.
16 class NumericComparator extends ScalarComparator 16 class NumericComparator extends ScalarComparator
17 { 17 {
18 /** 18 /**
19 * Returns whether the comparator can compare two values. 19 * Returns whether the comparator can compare two values.
20 * 20 *
21 * @param mixed $expected The first value to compare 21 * @param mixed $expected The first value to compare
22 * @param mixed $actual The second value to compare 22 * @param mixed $actual The second value to compare
23 *
23 * @return bool 24 * @return bool
24 */ 25 */
25 public function accepts($expected, $actual) 26 public function accepts($expected, $actual)
26 { 27 {
27 // all numerical values, but not if one of them is a double 28 // all numerical values, but not if one of them is a double
28 // or both of them are strings 29 // or both of them are strings
29 return is_numeric($expected) && is_numeric($actual) && 30 return \is_numeric($expected) && \is_numeric($actual) &&
30 !(is_double($expected) || is_double($actual)) && 31 !(\is_float($expected) || \is_float($actual)) &&
31 !(is_string($expected) && is_string($actual)); 32 !(\is_string($expected) && \is_string($actual));
32 } 33 }
33 34
34 /** 35 /**
35 * Asserts that two values are equal. 36 * Asserts that two values are equal.
36 * 37 *
42 * 43 *
43 * @throws ComparisonFailure 44 * @throws ComparisonFailure
44 */ 45 */
45 public function assertEquals($expected, $actual, $delta = 0.0, $canonicalize = false, $ignoreCase = false) 46 public function assertEquals($expected, $actual, $delta = 0.0, $canonicalize = false, $ignoreCase = false)
46 { 47 {
47 if (is_infinite($actual) && is_infinite($expected)) { 48 if (\is_infinite($actual) && \is_infinite($expected)) {
48 return; 49 return;
49 } 50 }
50 51
51 if ((is_infinite($actual) xor is_infinite($expected)) || 52 if ((\is_infinite($actual) xor \is_infinite($expected)) ||
52 (is_nan($actual) or is_nan($expected)) || 53 (\is_nan($actual) or \is_nan($expected)) ||
53 abs($actual - $expected) > $delta) { 54 \abs($actual - $expected) > $delta) {
54 throw new ComparisonFailure( 55 throw new ComparisonFailure(
55 $expected, 56 $expected,
56 $actual, 57 $actual,
57 '', 58 '',
58 '', 59 '',
59 false, 60 false,
60 sprintf( 61 \sprintf(
61 'Failed asserting that %s matches expected %s.', 62 'Failed asserting that %s matches expected %s.',
62 $this->exporter->export($actual), 63 $this->exporter->export($actual),
63 $this->exporter->export($expected) 64 $this->exporter->export($expected)
64 ) 65 )
65 ); 66 );