From 1b296c9109d75720179dc2652fe689e58242328b Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Fri, 13 Nov 2020 21:17:37 +0100 Subject: [PATCH] Use tolerant comparer for lossy webp encoder tests --- .../Formats/WebP/WebPEncoderTests.cs | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/tests/ImageSharp.Tests/Formats/WebP/WebPEncoderTests.cs b/tests/ImageSharp.Tests/Formats/WebP/WebPEncoderTests.cs index 90f3a3f427..51276962fc 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/WebPEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/WebP/WebPEncoderTests.cs @@ -3,6 +3,7 @@ using SixLabors.ImageSharp.Formats.WebP; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using Xunit; namespace SixLabors.ImageSharp.Tests.Formats.WebP @@ -67,7 +68,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.WebP using Image image = provider.GetImage(); var testOutputDetails = string.Concat("lossy", "_q", quality); - image.VerifyEncoder(provider, "webp", testOutputDetails, encoder); + image.VerifyEncoder(provider, "webp", testOutputDetails, encoder, customComparer: GetComparer(quality)); } [Theory] @@ -81,16 +82,29 @@ namespace SixLabors.ImageSharp.Tests.Formats.WebP public void Encode_Lossy_WithDifferentMethods_Works(TestImageProvider provider, int method) where TPixel : unmanaged, IPixel { + int quality = 75; var encoder = new WebPEncoder() { Lossy = true, Method = method, - Quality = 75 + Quality = quality }; using Image image = provider.GetImage(); var testOutputDetails = string.Concat("lossy", "_m", method); - image.VerifyEncoder(provider, "webp", testOutputDetails, encoder); + image.VerifyEncoder(provider, "webp", testOutputDetails, encoder, customComparer: GetComparer(quality)); + } + + private static ImageComparer GetComparer(int quality) + { + float tolerance = 0.01f; // ~1.0% + + if (quality < 30) + { + tolerance = 0.02f; // ~2.0% + } + + return ImageComparer.Tolerant(tolerance); } } }