| 148 |
lars |
1 |
<?php
|
|
|
2 |
namespace Hamcrest\Number;
|
|
|
3 |
|
|
|
4 |
class IsCloseToTest extends \Hamcrest\AbstractMatcherTest
|
|
|
5 |
{
|
|
|
6 |
|
|
|
7 |
protected function createMatcher()
|
|
|
8 |
{
|
|
|
9 |
$irrelevant = 0.1;
|
|
|
10 |
|
|
|
11 |
return \Hamcrest\Number\IsCloseTo::closeTo($irrelevant, $irrelevant);
|
|
|
12 |
}
|
|
|
13 |
|
|
|
14 |
public function testEvaluatesToTrueIfArgumentIsEqualToADoubleValueWithinSomeError()
|
|
|
15 |
{
|
|
|
16 |
$p = closeTo(1.0, 0.5);
|
|
|
17 |
|
|
|
18 |
$this->assertTrue($p->matches(1.0));
|
|
|
19 |
$this->assertTrue($p->matches(0.5));
|
|
|
20 |
$this->assertTrue($p->matches(1.5));
|
|
|
21 |
|
|
|
22 |
$this->assertDoesNotMatch($p, 2.0, 'too large');
|
|
|
23 |
$this->assertMismatchDescription('<2F> differed by <0.5F>', $p, 2.0);
|
|
|
24 |
$this->assertDoesNotMatch($p, 0.0, 'number too small');
|
|
|
25 |
$this->assertMismatchDescription('<0F> differed by <0.5F>', $p, 0.0);
|
|
|
26 |
}
|
|
|
27 |
}
|