Browse Source

add more test cases to Resize_WorksWithAllResamplers

pull/782/head
Anton Firszov 8 years ago
parent
commit
2929fcf8f9
  1. 38
      tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs

38
tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs

@ -24,19 +24,45 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
public static readonly string[] AllResamplerNames = TestUtils.GetAllResamplerNames();
[Theory]
[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<TPixel>(TestImageProvider<TPixel> provider, string samplerName, float ratio)
[WithTestPatternImages(nameof(AllResamplerNames), 100, 100, DefaultPixelType, 0.5f, null, null)]
[WithTestPatternImages(nameof(AllResamplerNames), 50, 50, DefaultPixelType, 8f, null, null)]
[WithTestPatternImages(nameof(AllResamplerNames), 201, 199, DefaultPixelType, null, 100, 99)]
[WithTestPatternImages(nameof(AllResamplerNames), 301, 300, DefaultPixelType, null, 1180, 480)]
[WithTestPatternImages(nameof(AllResamplerNames), 49, 80, DefaultPixelType, null, 301, 100)]
[WithFileCollection(nameof(CommonTestImages), nameof(AllResamplerNames), DefaultPixelType, 0.5f, null, null)]
[WithFileCollection(nameof(CommonTestImages), nameof(AllResamplerNames), DefaultPixelType, 0.3f, null, null)]
public void Resize_WorksWithAllResamplers<TPixel>(
TestImageProvider<TPixel> provider,
string samplerName,
float? ratio,
int? specificDestWidth,
int? specificDestHeight)
where TPixel : struct, IPixel<TPixel>
{
IResampler sampler = TestUtils.GetResampler(samplerName);
using (Image<TPixel> image = provider.GetImage())
{
SizeF newSize = image.Size() * ratio;
SizeF newSize;
string destSizeInfo;
if (ratio.HasValue)
{
newSize = image.Size() * ratio.Value;
destSizeInfo = ratio.Value.ToString(System.Globalization.CultureInfo.InvariantCulture);
}
else
{
if (!specificDestWidth.HasValue || !specificDestHeight.HasValue)
{
throw new InvalidOperationException("invalid dimensional input for Resize_WorksWithAllResamplers!");
}
newSize = new SizeF(specificDestWidth.Value, specificDestHeight.Value);
destSizeInfo = $"{newSize.Width}x{newSize.Height}";
}
image.Mutate(x => x.Resize((Size)newSize, sampler, false));
FormattableString details = $"{samplerName}-{ratio.ToString(System.Globalization.CultureInfo.InvariantCulture)}";
FormattableString details = $"{samplerName}-{destSizeInfo}";
image.DebugSave(provider, details);
image.CompareToReferenceOutput(ImageComparer.TolerantPercentage(0.02f), provider, details);

Loading…
Cancel
Save