You are here

protected function CtoolsMathExpressionTestCase::assertFloat in Chaos Tool Suite (ctools) 7

A custom assertion with checks the values in a certain range.

Parameters

float $first: A value to check for equality.

float $second: A value to check for equality.

string $message: The message describing the correct behaviour, eg. "2/4 equals 1/2". The default message is used if this value is empty.

float $delta: The precision with which values must match. This accounts for rounding errors and imprecise representation errors in the floating point format. The value passed in should ideally be proportional to the values being compared.

string $group: Which group this assert belongs to.

Return value

bool TRUE if the assertion was correct (that is, $first == $second within the given limits), FALSE otherwise.

3 calls to CtoolsMathExpressionTestCase::assertFloat()
CtoolsMathExpressionTestCase::testArithmetic in tests/math_expression.test
Test some arithmetic handling.
CtoolsMathExpressionTestCase::testBuildInFunctions in tests/math_expression.test
Test various built-in transcendental and extended functions.
CtoolsMathExpressionTestCase::testVariables in tests/math_expression.test
Test variable handling.

File

tests/math_expression.test, line 78

Class

CtoolsMathExpressionTestCase
Tests the MathExpression library of ctools.

Code

protected function assertFloat($first, $second, $message = '', $delta = 1.0E-8, $group = 'Other') {

  // Check for NaN and Inf because the abs() and sign() code won't like those.
  $equal = FALSE || is_infinite($first) && is_infinite($second) || is_nan($first) && is_nan($second) || abs($first - $second) <= $delta && self::sign($first) === self::sign($second);
  if (empty($message)) {
    $default = t('Value !first is equal to value !second.', array(
      '!first' => var_export($first, TRUE),
      '!second' => var_export($second, TRUE),
    ));
    $message = $default;
  }
  return $this
    ->assert($equal, $message, $group);
}