You are here

public function GdImageAnalysisTest::testEntropy in Image Effects 8.3

Same name and namespace in other branches
  1. 8 tests/src/Unit/GdImageAnalysisTest.php \Drupal\Tests\image_effects\Unit\GdImageAnalysisTest::testEntropy()
  2. 8.2 tests/src/Unit/GdImageAnalysisTest.php \Drupal\Tests\image_effects\Unit\GdImageAnalysisTest::testEntropy()

Verify the entropy calculation with a known image.

File

tests/src/Unit/GdImageAnalysisTest.php, line 76

Class

GdImageAnalysisTest
Tests the image analysis helper methods.

Namespace

Drupal\Tests\image_effects\Unit

Code

public function testEntropy() {

  // Calculate the expected values.
  // There are 9 bins in the histogram, 3 colors * 3 channels.
  $expected_entroy = (1 / 3 * log(1 / 9, 2) + 2 / 3 * log(2 / 9, 2)) * -1;
  $this
    ->assertTrue(GdImageAnalysis::entropy($this->testImage) - $expected_entroy < 0.001);
}