From f219dd8ee7ef9d91cff9f73e2df4b9fa456c6976 Mon Sep 17 00:00:00 2001 From: Dimitar Dinchev Date: Mon, 9 Jan 2017 09:54:00 +0200 Subject: [PATCH] Allow comparing floats with delta. --- src/Codeception/Verify.php | 8 ++++---- tests/VerifyTest.php | 11 ++++++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Codeception/Verify.php b/src/Codeception/Verify.php index 0d2d286..ee0cfcc 100644 --- a/src/Codeception/Verify.php +++ b/src/Codeception/Verify.php @@ -30,19 +30,19 @@ public function setIsFileExpectation($isFileExpectation) $this->isFileExpectation = $isFileExpectation; } - public function equals($expected) + public function equals($expected, $delta = 0) { if ( ! $this->isFileExpectation ) { - a::assertEquals($expected, $this->actual, $this->description); + a::assertEquals($expected, $this->actual, $this->description, $delta); } else { a::assertFileEquals($expected, $this->actual, $this->description); } } - public function notEquals($expected) + public function notEquals($expected, $delta = 0) { if ( ! $this->isFileExpectation ) { - a::assertNotEquals($expected, $this->actual, $this->description); + a::assertNotEquals($expected, $this->actual, $this->description, $delta); } else { a::assertFileNotEquals($expected, $this->actual, $this->description); } diff --git a/tests/VerifyTest.php b/tests/VerifyTest.php index c999626..46e3012 100644 --- a/tests/VerifyTest.php +++ b/tests/VerifyTest.php @@ -12,13 +12,22 @@ protected function setUp() $this->xml = new DomDocument; $this->xml->loadXML('BazBaz'); } + public function testEquals() { verify(5)->equals(5); verify("hello")->equals("hello"); verify("user have 5 posts", 5)->equals(5); - verify(3)->notEquals(5); + verify(3.251)->equals(3.25, 0.01); + verify("respects delta", 3.251)->equals(3.25, 0.01); verify_file(__FILE__)->equals(__FILE__); + } + + public function testNotEquals() + { + verify(3)->notEquals(5); + verify(3.252)->notEquals(3.25, 0.001); + verify("respects delta", 3.252, 0.001); verify_file(__FILE__)->notEquals(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'composer.json'); }