You are here

function LocationTestCase::assertArrayEpsilon in Location 7.5

Same name and namespace in other branches
  1. 6.3 tests/location_testcase.php \LocationTestCase::assertArrayEpsilon()
  2. 7.3 tests/location_testcase.test \LocationTestCase::assertArrayEpsilon()
  3. 7.4 tests/location_testcase.php \LocationTestCase::assertArrayEpsilon()

Custom assertion -- will check each element of an array against a reference value.

2 calls to LocationTestCase::assertArrayEpsilon()
LocationEarthTest::testXYZ in tests/earth.test
LocationGoogleGeocoderTest::testUSA in tests/google_geocoder.test

File

tests/location_testcase.php, line 13
Common functions for Location tests.

Class

LocationTestCase
@file Common functions for Location tests.

Code

function assertArrayEpsilon($result, $expected, $epsilon, $message = '', $group = 'Other') {
  foreach ($expected as $k => $test) {
    $lower = $test - $epsilon;
    $upper = $test + $epsilon;
    if ($result[$k] < $lower || $result[$k] > $upper) {
      $this
        ->_assert('fail', $message ? $message : t('Value deviates by @amt, which is more than @maxdev.', array(
        '@amt' => abs($test - $result[$k]),
        '@maxdev' => $epsilon,
      )), $group);
    }
    else {
      $this
        ->_assert('pass', $message ? $message : t('Value within expected margin.'), $group);
    }
  }
}