Skip to content

Commit

Permalink
Improve test so that is passes.
Browse files Browse the repository at this point in the history
The underlying maths for some statistics changed: ImageMagick/ImageMagick#6924 so the tests need to pass on both before and after maths.
  • Loading branch information
Danack committed Feb 9, 2024
1 parent 6114c6f commit 944b67f
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 3 deletions.
61 changes: 61 additions & 0 deletions bisect/bisect_analyze.sh
@@ -0,0 +1,61 @@
#!/bin/sh


#########################################################
# How to run git bisect
#########################################################

## Check out ImageMagick
# git clone https://github.com/ImageMagick/ImageMagick.git

## Put a known good version of Imagick into the directory /var/app/bisect/ImageMagick/imagick

## Update this script to run the relevant tests
## e.g. change php run-tests.php tests/316_Imagick_getImageKurtosis.phpt

## Start bisect session
# git bisect start

## Find bad version of ImageMagick e.g. a particular tag that is broken
# git checkout 963f5fa

## Mark that version as bad.
# git bisect bad


## Find a good version
# git checkout 99da019

## Mark that version as good.
# git bisect good


## Run the bisect automatically
# git bisect run sh bisect_analyze.sh


cd /var/app/bisect/ImageMagick

./configure --with-quantum-depth=16 \
--disable-dependency-tracking \
--with-magick-plus-plus=no \
--without-perl \
--disable-docs \
--with-openexr=yes \
--with-fontconfig=yes \
--with-fftw \
--with-heic=yes \
--with-jpeg=yes \
--with-png=yes \
--with-tiff=yes \
--with-urw-base35-font-dir=/usr/share/fonts/type1/urw-base35 \
--with-webp=yes

make clean
make install -j20

cd /var/app/bisect/ImageMagick/imagick
phpize
./configure
make install
php run-tests.php tests/316_Imagick_getImageKurtosis.phpt
12 changes: 10 additions & 2 deletions tests/316_Imagick_getImageKurtosis.phpt
Expand Up @@ -14,8 +14,16 @@ function getImageKurtosis() {
$imagick = new \Imagick(__DIR__ . '/Biter_500.jpg');
$values = $imagick->getImageKurtosis();

check_value($values, "kurtosis", -0.9379261035010518);
check_value($values, "skewness", 0.4562517200972045);
check_value_posibilities(
$values,
"kurtosis",
[-0.9379261035010518, -0.70925995674921]
);
check_value_posibilities(
$values,
"skewness",
[0.4562517200972045, 0.56839010636614]
);
}

getImageKurtosis() ;
Expand Down
40 changes: 39 additions & 1 deletion tests/functions.inc
Expand Up @@ -111,7 +111,10 @@ function setFontForImagickDraw(\ImagickDraw $imagickDraw)
$imagickDraw->setFont($font);
}


/**
* Checks that a named value exists in an array and it matches
* an expected value.
*/
function check_value(array $values, $name, $expected_value)
{
if (array_key_exists($name, $values) !== true) {
Expand All @@ -136,6 +139,41 @@ function check_value(array $values, $name, $expected_value)
}


/**
* Checks that a named value exists in an array and it matches
* one of a number of expected values.
* This function exists because the expected values for Kurtosis can
* change when the underlying maths changes: https://github.com/ImageMagick/ImageMagick/issues/6924
*/
function check_value_posibilities(array $values, $name, array $expected_values)
{
if (array_key_exists($name, $values) !== true) {

$message = "Expected key '$name' not set. Array contains:\n";
$message .= var_export($values, true);

throw new \Exception($message);
}


$value = $values[$name];

$epsilon = 0.01;

foreach ($expected_values as $expected_value) {
if (($value > $expected_value - $epsilon) && ($value < $expected_value + $epsilon)) {
echo "Value for '$name' is $value which is close enough to expected $expected_value\n";
return;
}
}

$expected_string = implode(", ", $expected_values);

$message = "Value for $name doesn't match expected possibilities. Expected one of: $expected_string, actual: $value";
throw new \Exception($message);
}


function check_value_with_epsilon(array $values, $name, $expected_value, $epsilon)
{
if (array_key_exists($name, $values) !== true) {
Expand Down

0 comments on commit 944b67f

Please sign in to comment.