Skip to content

Commit b0b9ee6

Browse files
committed
Added extra unit test for the compare method that tests all error metrics.
1 parent aaf715a commit b0b9ee6

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/Magick.NET.Tests/MagickImageTests/TheCompareMethod.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,5 +154,34 @@ public void ShouldUseTheColorFuzz()
154154
Assert.Equal(0, result);
155155
ColorAssert.Equal(new MagickColor("#fd2ff729f28b"), diff, 0, 0);
156156
}
157+
158+
[Theory]
159+
[InlineData(ErrorMetric.Undefined, 0.0682)]
160+
[InlineData(ErrorMetric.Absolute, 6462)]
161+
[InlineData(ErrorMetric.Fuzz, 0.4726)]
162+
[InlineData(ErrorMetric.MeanAbsolute, 0.2714)]
163+
#if Q8
164+
[InlineData(ErrorMetric.MeanErrorPerPixel, 4536868.5411)]
165+
#else
166+
[InlineData(ErrorMetric.MeanErrorPerPixel, 1165975215.0823)]
167+
#endif
168+
[InlineData(ErrorMetric.MeanSquared, 0.2233)]
169+
[InlineData(ErrorMetric.NormalizedCrossCorrelation, 0.0682)]
170+
[InlineData(ErrorMetric.PeakAbsolute, 1)]
171+
[InlineData(ErrorMetric.PeakSignalToNoiseRatio, 0.1441)]
172+
[InlineData(ErrorMetric.PerceptualHash, 0)]
173+
[InlineData(ErrorMetric.RootMeanSquared, 0.4726)]
174+
[InlineData(ErrorMetric.StructuralSimilarity, 0.4220)]
175+
[InlineData(ErrorMetric.StructuralDissimilarity, 0.2889)]
176+
[InlineData(ErrorMetric.PhaseCorrelation, 0.0682)]
177+
[InlineData(ErrorMetric.DotProductCorrelation, 0.0682)]
178+
public void ShouldReturnTheCorrectValueForEachErrorMetric(ErrorMetric errorMetric, double expectedResult)
179+
{
180+
using var image = new MagickImage(Files.MagickNETIconPNG);
181+
using var other = image.CloneAndMutate(image => image.Rotate(180));
182+
183+
var result = image.Compare(other, errorMetric);
184+
Assert.InRange(result, expectedResult, expectedResult + 0.0001);
185+
}
157186
}
158187
}

0 commit comments

Comments
 (0)