Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
FloatComparatorTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
11 use PHPUnit\Framework\TestCase;
12 
13 class FloatComparatorTest extends TestCase
14 {
18  private $comparator;
19 
23  protected function setUp()
24  {
25  $this->comparator = new FloatComparator();
26  }
27 
36  public function testEq(float $a, float $b, bool $expected)
37  {
38  self::assertEquals($expected, $this->comparator->equal($a, $b));
39  }
40 
46  public function eqDataProvider(): array
47  {
48  return [
49  [10, 10.00001, true],
50  [10, 10.000001, true],
51  [10.0000099, 10.00001, true],
52  [1, 1.0001, false],
53  [1, -1.00001, false],
54  ];
55  }
56 
65  public function testGt(float $a, float $b, bool $expected)
66  {
67  self::assertEquals($expected, $this->comparator->greaterThan($a, $b));
68  }
69 
75  public function gtDataProvider(): array
76  {
77  return [
78  [10, 10.00001, false],
79  [10, 10.000001, false],
80  [10.0000099, 10.00001, false],
81  [1.0001, 1, true],
82  [1, -1.00001, true],
83  ];
84  }
85 
94  public function testGte(float $a, float $b, bool $expected)
95  {
96  self::assertEquals($expected, $this->comparator->greaterThanOrEqual($a, $b));
97  }
98 
104  public function gteDataProvider(): array
105  {
106  return [
107  [10, 10.00001, true],
108  [10, 10.000001, true],
109  [10.0000099, 10.00001, true],
110  [1.0001, 1, true],
111  [1, -1.00001, true],
112  [1.0001, 1.001, false],
113  ];
114  }
115 }