From 508d707a7ac9128bac504aaeba9aac16c715e68c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Lorenzo=20Rodr=C3=ADguez?= Date: Sun, 9 May 2010 18:16:42 -0430 Subject: [PATCH] Adding another compatibility test method: assertWithinMargin --- cake/tests/lib/cake_test_case.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cake/tests/lib/cake_test_case.php b/cake/tests/lib/cake_test_case.php index e56cfbf3f..55778491b 100644 --- a/cake/tests/lib/cake_test_case.php +++ b/cake/tests/lib/cake_test_case.php @@ -480,5 +480,19 @@ class CakeTestCase extends PHPUnit_Framework_TestCase { protected function assertReference(&$first, &$second, $message = '') { return $this->assertSame($first, $second, $message); } + +/** +* Compatibility function to test if value is between an acceptable range +* @param mixed $value +* @param mixed $expected +* @param mixed $margin the rage of acceptation +* @param string $message the text to display if the assertion is not correct +* @return void +*/ + protected function assertWithinMargin($value, $expected, $margin, $message = '') { + $upper = $value + $margin; + $lower = $value - $margin; + $this->assertTrue((($expected <= $upper) && ($expected >= $lower)), $message); + } } ?> \ No newline at end of file