Skip to content

Commit

Permalink
Add assertNotWithinRange() and add tests for both methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
euromark committed Dec 26, 2014
1 parent d5efea3 commit 60600fd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/TestSuite/TestCase.php
Expand Up @@ -510,6 +510,21 @@ protected static function assertWithinRange($expected, $result, $margin, $messag
static::assertTrue((($expected <= $upper) && ($expected >= $lower)), $message);
}

/**
* Compatibility function to test if a value is not between an acceptable range.
*
* @param float $expected
* @param float $result
* @param float $margin the rage of acceptation
* @param string $message the text to display if the assertion is not correct
* @return void
*/
protected static function assertNotWithinRange($expected, $result, $margin, $message = '') {
$upper = $result + $margin;
$lower = $result - $margin;
static::assertTrue((($expected > $upper) || ($expected < $lower)), $message);
}

/**
* Compatibility function to test paths.
*
Expand Down
20 changes: 20 additions & 0 deletions tests/TestCase/TestSuite/TestCaseTest.php
Expand Up @@ -320,6 +320,26 @@ public function testAssertTextNotContains() {
$this->assertTextNotContains("different\rlines", $stringDirty);
}

/**
* test testAssertWithinRange()
*
* @return void
*/
public function testAssertWithinRange() {
$this->assertWithinRange(21, 22, 1, 'Not within range');
$this->assertWithinRange(21.3, 22.2, 1.0, 'Not within range');
}

/**
* test testAssertNotWithinRange()
*
* @return void
*/
public function testAssertNotWithinRange() {
$this->assertNotWithinRange(21, 23, 1, 'Within range');
$this->assertNotWithinRange(21.3, 22.2, 0.7, 'Within range');
}

/**
* test getMockForModel()
*
Expand Down

0 comments on commit 60600fd

Please sign in to comment.