From fe20e71c090f97c79e45f0b42e8b169bdca9b8fd Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Sun, 21 Jan 2018 19:40:37 +0100 Subject: [PATCH] Higher threshold for LomographTest --- .../Processing/Processors/Filters/LomographTest.cs | 4 +++- .../TestUtilities/ImageComparison/ImageComparer.cs | 2 +- .../ImageComparison/TolerantImageComparer.cs | 4 ++-- .../TestUtilities/Tests/ImageComparerTests.cs | 13 +++++++++++++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/tests/ImageSharp.Tests/Processing/Processors/Filters/LomographTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Filters/LomographTest.cs index 09c8becec..622d7554b 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Filters/LomographTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Filters/LomographTest.cs @@ -7,6 +7,8 @@ using Xunit; namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters { + using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; + [GroupOutput("Filters")] public class LomographTest { @@ -15,7 +17,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters public void ApplyLomographFilter(TestImageProvider provider) where TPixel : struct, IPixel { - provider.RunValidatingProcessorTest(x => x.Lomograph()); + provider.RunValidatingProcessorTest(x => x.Lomograph(), comparer: ImageComparer.Tolerant(-2)); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs index d65653016..2820e9399 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs @@ -18,7 +18,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison /// /// Returns an instance of . /// Individual manhattan pixel difference is only added to total image difference when the individual difference is over 'perPixelManhattanThreshold'. - /// Negative value for 'imageThreshold' indicates default threshold (see ). + /// Negative value for 'imageThreshold' indicates multiplier to be applied to the default threshold (see ). /// public static ImageComparer Tolerant( float imageThreshold = -1, diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs index db0048558..549786d8b 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs @@ -15,14 +15,14 @@ public static readonly float DefaultImageThreshold = GetDefaultImageThreshold(); /// - /// Negative value for 'imageThreshold' indicates default threshold (see ). + /// Negative value for 'imageThreshold' indicates a multiplier to be applied to the default threshold (see ). /// Individual manhattan pixel difference is only added to total image difference when the individual difference is over 'perPixelManhattanThreshold'. /// public TolerantImageComparer(float imageThreshold, int perPixelManhattanThreshold = 0) { if (imageThreshold < 0) { - imageThreshold = DefaultImageThreshold; + imageThreshold *= -DefaultImageThreshold; } this.ImageThreshold = imageThreshold; diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/ImageComparerTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/ImageComparerTests.cs index 59e6ec5fb..cfc7a10a4 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/ImageComparerTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/ImageComparerTests.cs @@ -23,6 +23,19 @@ namespace SixLabors.ImageSharp.Tests private ITestOutputHelper Output { get; } + [Fact] + public void TolerantImageComparer_NegativeThresholdIsMultiplierForDefault() + { + var c1 = (TolerantImageComparer)ImageComparer.Tolerant(); + var c2 = (TolerantImageComparer)ImageComparer.Tolerant(-2); + var c3 = (TolerantImageComparer)ImageComparer.Tolerant(-42); + + Assert.True(c1.ImageThreshold > 0); + Assert.Equal(TolerantImageComparer.DefaultImageThreshold, c1.ImageThreshold); + Assert.Equal(c1.ImageThreshold * 2, c2.ImageThreshold); + Assert.Equal(c1.ImageThreshold * 42, c3.ImageThreshold); + } + [Theory] [WithTestPatternImages(100,100,PixelTypes.Rgba32, 0.0001f, 1)] [WithTestPatternImages(100, 100, PixelTypes.Rgba32, 0, 0)]