Skip to content

Commit

Permalink
Merge pull request #29 from ddinchev/master
Browse files Browse the repository at this point in the history
Allow comparing floats with delta.
  • Loading branch information
sergeyklay authored Jan 9, 2017
2 parents b06d706 + f219dd8 commit 5d649dd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/Codeception/Verify.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
11 changes: 10 additions & 1 deletion tests/VerifyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,22 @@ protected function setUp()
$this->xml = new DomDocument;
$this->xml->loadXML('<foo><bar>Baz</bar><bar>Baz</bar></foo>');
}

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');
}

Expand Down

0 comments on commit 5d649dd

Please sign in to comment.