summaryrefslogtreecommitdiffstats
path: root/imagick-tests.patch
blob: 7f6990b8f00a56289ff5edcf938844fd949c708a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
From 944b67fce68bcb5835999a149f917670555b6fcb Mon Sep 17 00:00:00 2001
From: Danack <Danack@basereality.com>
Date: Fri, 9 Feb 2024 13:59:39 +0000
Subject: [PATCH] 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.
---
 bisect/bisect_analyze.sh                | 61 +++++++++++++++++++++++++
 tests/316_Imagick_getImageKurtosis.phpt | 12 ++++-
 tests/functions.inc                     | 40 +++++++++++++++-
 3 files changed, 110 insertions(+), 3 deletions(-)
 create mode 100644 bisect/bisect_analyze.sh

diff --git a/tests/316_Imagick_getImageKurtosis.phpt b/tests/316_Imagick_getImageKurtosis.phpt
index 2618924a..61370b57 100644
--- a/tests/316_Imagick_getImageKurtosis.phpt
+++ b/tests/316_Imagick_getImageKurtosis.phpt
@@ -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() ;
diff --git a/tests/functions.inc b/tests/functions.inc
index bbd60ac0..11012864 100644
--- a/tests/functions.inc
+++ b/tests/functions.inc
@@ -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) {