Improve test so that is passes.

The underlying maths for some statistics changed: https://github.com/ImageMagick/ImageMagick/issues/6924 so the tests need to pass on both before and after maths.
This commit is contained in:
Danack
2024-02-09 13:59:39 +00:00
committed by Jakub Zelenka
parent 5f25163cce
commit 69e50ab0a1
3 changed files with 110 additions and 3 deletions
+61
View File
@@ -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
+10 -2
View File
@@ -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() ;
+39 -1
View File
@@ -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) {
@@ -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) {