Index: drupal_web_test_case.php =================================================================== RCS file: /cvs/drupal/contributions/modules/simpletest/drupal_web_test_case.php,v retrieving revision 1.2.2.3.2.19 diff -u -r1.2.2.3.2.19 drupal_web_test_case.php --- drupal_web_test_case.php 22 Oct 2008 23:16:46 -0000 1.2.2.3.2.19 +++ drupal_web_test_case.php 16 Nov 2008 10:52:33 -0000 @@ -246,6 +246,60 @@ protected function assertNotIdentical($first, $second, $message = '', $group = 'Other') { return $this->_assert($first !== $second, $message ? $message : t('First value is not identical to second value'), $group); } + + /** Check to see if the positive difference is less than $margin. + * + * More specifically: + * @code + * abs($first - $second) < $margin + * @endcode + * + * This function is especially useful when you want to test a floating point + * value, since exact floating point comparison seldom works. + * + * @param $first + * The first value. + * @param $second + * The second value. + * @param $margin + * The maximum allowed absolute difference between $first and $second. + * @param $message + * The message to display along with the assertion. + * @param $group + * The type of assertion - examples are "Browser", "PHP". + * @return + * The status passed in. + */ + protected function assertWithinMargin($first, $second, $margin, $message = '', $group = 'Other') { + return $this->_assert(abs($first - $second) < $margin, $message ? $message : t('The positive difference between first and second value is less than the stated margin'), $group); + } + + /** Check to see if the positive difference is more than $margin. + * + * More specifically: + * @code + * abs($first - $second) > $margin + * @endcode + * + * This function is especially useful when you want to test a floating point + * value, since exact floating point comparison seldom works. + * + * @param $first + * The first value. + * @param $second + * The second value. + * @param $margin + * The minimum allowed absolute difference between $first and $second. + * @param $message + * The message to display along with the assertion. + * @param $group + * The type of assertion - examples are "Browser", "PHP". + * @return + * The status passed in. + */ + protected function assertOutsideMargin($first, $second, $margin, $message = '', $group = 'Other') { + return $this->_assert(abs($first - $second) > $margin, $message ? $message : t('The positive difference between first and second value is greater than the stated margin'), $group); + } /** * Fire an assertion that is always positive.