You are here

public function ImageEffectsTestBase::assertColorsAreNotClose in Image Effects 8.3

Same name and namespace in other branches
  1. 8 tests/src/Functional/ImageEffectsTestBase.php \Drupal\Tests\image_effects\Functional\ImageEffectsTestBase::assertColorsAreNotClose()
  2. 8.2 tests/src/Functional/ImageEffectsTestBase.php \Drupal\Tests\image_effects\Functional\ImageEffectsTestBase::assertColorsAreNotClose()

Asserts two colors are *not* close by RGBA within a tolerance.

Very basic, just compares the sum of the squared differences for each of the R, G, B, A components of two colors against a 'tolerance' value.

Parameters

int[] $actual: The actual RGBA array.

int[] $expected: The expected RGBA array.

int $tolerance: The acceptable difference between the colors.

2 calls to ImageEffectsTestBase::assertColorsAreNotClose()
ImageEffectsTestBase::assertColorsAreNotEqual in tests/src/Functional/ImageEffectsTestBase.php
Assert two colors are not equal by RGBA.
WatermarkTest::testWatermarkEffect in tests/src/Functional/Effect/WatermarkTest.php
Watermark effect test.

File

tests/src/Functional/ImageEffectsTestBase.php, line 323

Class

ImageEffectsTestBase
Base test class for image_effects tests.

Namespace

Drupal\Tests\image_effects\Functional

Code

public function assertColorsAreNotClose(array $actual, array $expected, $tolerance) : void {
  $distance = pow($actual[0] - $expected[0], 2) + pow($actual[1] - $expected[1], 2) + pow($actual[2] - $expected[2], 2) + pow($actual[3] - $expected[3], 2);
  $this
    ->assertGreaterThan($tolerance, $distance, "Actual: {" . implode(',', $actual) . "}, Expected: {" . implode(',', $expected) . "}, Distance: " . $distance . ", Tolerance: " . $tolerance);
}