You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
801 B

3 years ago
  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. }