From 8b9600f9df91f2b32ee62fb229d4cbdb019d1749 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Thu, 29 Nov 2018 16:26:15 +0100 Subject: [PATCH] wip --- .../Transforms/ResizeKernelMapTests.cs | 5 +-- .../Processors/Transforms/ResizeTests.cs | 33 +++++-------------- .../TestUtilities/TestUtils.cs | 8 +++++ 3 files changed, 18 insertions(+), 28 deletions(-) diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeKernelMapTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeKernelMapTests.cs index 08b294913..5d3790f07 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeKernelMapTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeKernelMapTests.cs @@ -208,10 +208,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms { var result = new TheoryData(); - string[] resamplerNames = typeof(KnownResamplers).GetProperties(BindingFlags.Public | BindingFlags.Static) - .Select(p => p.Name) - .Where(name => name != nameof(KnownResamplers.NearestNeighbor)) - .ToArray(); + string[] resamplerNames = TestUtils.GetAllResamplerNames(false); int[] dimensionVals = { diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs index b4aff53e8..fc4cd3f11 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs @@ -20,38 +20,23 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms public static readonly string[] CommonTestImages = { TestImages.Png.CalliphoraPartial }; private static readonly ImageComparer ValidatorComparer = ImageComparer.TolerantPercentage(0.07F); - - public static readonly TheoryData AllResamplers = - new TheoryData - { - { "Bicubic", KnownResamplers.Bicubic }, - { "Triangle", KnownResamplers.Triangle}, - { "NearestNeighbor", KnownResamplers.NearestNeighbor }, - { "Box", KnownResamplers.Box }, - // { "Lanczos2", KnownResamplers.Lanczos2 }, TODO: Add expected file - { "Lanczos3", KnownResamplers.Lanczos3 }, - { "Lanczos5", KnownResamplers.Lanczos5 }, - { "MitchellNetravali", KnownResamplers.MitchellNetravali }, - { "Lanczos8", KnownResamplers.Lanczos8 }, - { "Hermite", KnownResamplers.Hermite }, - { "Spline", KnownResamplers.Spline }, - { "Robidoux", KnownResamplers.Robidoux }, - { "RobidouxSharp", KnownResamplers.RobidouxSharp }, - { "Welch", KnownResamplers.Welch } - }; + + public static readonly string[] AllResamplerNames = TestUtils.GetAllResamplerNames(); [Theory] - [WithTestPatternImages(nameof(AllResamplers), 100, 100, DefaultPixelType, 0.5f)] - [WithFileCollection(nameof(CommonTestImages), nameof(AllResamplers), DefaultPixelType, 0.5f)] - [WithFileCollection(nameof(CommonTestImages), nameof(AllResamplers), DefaultPixelType, 0.3f)] - public void Resize_WorksWithAllResamplers(TestImageProvider provider, string name, IResampler sampler, float ratio) + [WithTestPatternImages(nameof(AllResamplerNames), 100, 100, DefaultPixelType, 0.5f)] + [WithFileCollection(nameof(CommonTestImages), nameof(AllResamplerNames), DefaultPixelType, 0.5f)] + [WithFileCollection(nameof(CommonTestImages), nameof(AllResamplerNames), DefaultPixelType, 0.3f)] + public void Resize_WorksWithAllResamplers(TestImageProvider provider, string samplerName, float ratio) where TPixel : struct, IPixel { + IResampler sampler = TestUtils.GetResampler(samplerName); + using (Image image = provider.GetImage()) { SizeF newSize = image.Size() * ratio; image.Mutate(x => x.Resize((Size)newSize, sampler, false)); - FormattableString details = $"{name}-{ratio.ToString(System.Globalization.CultureInfo.InvariantCulture)}"; + FormattableString details = $"{samplerName}-{ratio.ToString(System.Globalization.CultureInfo.InvariantCulture)}"; image.DebugSave(provider, details); image.CompareToReferenceOutput(ImageComparer.TolerantPercentage(0.02f), provider, details); diff --git a/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs b/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs index 5ea0bccf0..a21e55e2b 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs @@ -297,5 +297,13 @@ namespace SixLabors.ImageSharp.Tests return (IResampler)property.GetValue(null); } + + public static string[] GetAllResamplerNames(bool includeNearestNeighbour = true) + { + return typeof(KnownResamplers).GetProperties(BindingFlags.Public | BindingFlags.Static) + .Select(p => p.Name) + .Where(name => includeNearestNeighbour || name != nameof(KnownResamplers.NearestNeighbor)) + .ToArray(); + } } } \ No newline at end of file