IsCloseToTest.php 801 B

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