Browse Source

revisted test cases in Resize_WorksWithAllResamplers

af/merge-core
Anton Firszov 8 years ago
parent
commit
5163bbbad0
  1. 82
      tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs
  2. 13
      tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs
  3. 39
      tests/ImageSharp.Tests/TestUtilities/TestUtils.cs
  4. 12
      tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs
  5. 2
      tests/Images/External

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

@ -23,14 +23,24 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
public static readonly string[] AllResamplerNames = TestUtils.GetAllResamplerNames();
public static readonly string[] SmokeTestResamplerNames =
{
nameof(KnownResamplers.NearestNeighbor),
nameof(KnownResamplers.Bicubic),
nameof(KnownResamplers.Box),
nameof(KnownResamplers.Lanczos5),
};
[Theory]
[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)]
[WithFileCollection(nameof(CommonTestImages), nameof(SmokeTestResamplerNames), DefaultPixelType, 0.3f, null, null)]
[WithFileCollection(nameof(CommonTestImages), nameof(SmokeTestResamplerNames), DefaultPixelType, 1.8f, null, null)]
[WithTestPatternImages(nameof(SmokeTestResamplerNames), 100, 100, DefaultPixelType, 0.5f, null, null)]
[WithTestPatternImages(nameof(SmokeTestResamplerNames), 100, 100, DefaultPixelType, 1f, null, null)]
[WithTestPatternImages(nameof(SmokeTestResamplerNames), 50, 50, DefaultPixelType, 8f, null, null)]
[WithTestPatternImages(nameof(SmokeTestResamplerNames), 201, 199, DefaultPixelType, null, 100, 99)]
[WithTestPatternImages(nameof(SmokeTestResamplerNames), 301, 1180, DefaultPixelType, null, 300, 480)]
[WithTestPatternImages(nameof(SmokeTestResamplerNames), 49, 80, DefaultPixelType, null, 301, 100)]
public void Resize_WorksWithAllResamplers<TPixel>(
TestImageProvider<TPixel> provider,
string samplerName,
@ -41,32 +51,42 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
{
IResampler sampler = TestUtils.GetResampler(samplerName);
using (Image<TPixel> image = provider.GetImage())
{
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}-{destSizeInfo}";
var comparer = ImageComparer.TolerantPercentage(0.02f);
image.DebugSave(provider, details);
image.CompareToReferenceOutput(ImageComparer.TolerantPercentage(0.02f), provider, details);
}
provider.RunValidatingProcessorTest(
ctx =>
{
SizeF newSize;
string destSizeInfo;
if (ratio.HasValue)
{
newSize = ctx.GetCurrentSize() * 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}";
}
FormattableString testOutputDetails = $"{samplerName}-{destSizeInfo}";
ctx.Apply(
img => img.DebugSave(
provider,
$"{testOutputDetails}-ORIGINAL",
appendPixelTypeToFileName: false));
ctx.Resize((Size)newSize, sampler, false);
return testOutputDetails;
},
comparer,
appendPixelTypeToFileName: false);
}
[Theory]

13
tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs

@ -16,10 +16,9 @@ namespace SixLabors.ImageSharp.Tests
/// <summary>
/// A test image provider that produces test patterns.
/// </summary>
/// <typeparam name="TPixel"></typeparam>
private class TestPatternProvider : BlankProvider
{
static Dictionary<string, Image<TPixel>> testImages = new Dictionary<string, Image<TPixel>>();
static readonly Dictionary<string, Image<TPixel>> TestImages = new Dictionary<string, Image<TPixel>>();
public TestPatternProvider(int width, int height)
: base(width, height)
@ -35,17 +34,17 @@ namespace SixLabors.ImageSharp.Tests
public override Image<TPixel> GetImage()
{
lock (testImages)
lock (TestImages)
{
if (!testImages.ContainsKey(this.SourceFileOrDescription))
if (!TestImages.ContainsKey(this.SourceFileOrDescription))
{
Image<TPixel> image = new Image<TPixel>(this.Width, this.Height);
DrawTestPattern(image);
testImages.Add(this.SourceFileOrDescription, image);
TestImages.Add(this.SourceFileOrDescription, image);
}
}
return testImages[this.SourceFileOrDescription].Clone();
return TestImages[this.SourceFileOrDescription].Clone();
}
/// <summary>
@ -202,6 +201,7 @@ namespace SixLabors.ImageSharp.Tests
Rgba32 t = new Rgba32(0);
for (int x = left; x < right; x++)
{
for (int y = top; y < bottom; y++)
{
t.PackedValue += stepsPerPixel;
@ -210,6 +210,7 @@ namespace SixLabors.ImageSharp.Tests
c.FromVector4(v);
pixels[x, y] = c;
}
}
}
}
}

39
tests/ImageSharp.Tests/TestUtilities/TestUtils.cs

@ -193,6 +193,45 @@ namespace SixLabors.ImageSharp.Tests
}
}
internal static void RunValidatingProcessorTest<TPixel>(
this TestImageProvider<TPixel> provider,
Func<IImageProcessingContext<TPixel>, FormattableString> processAndGetTestOutputDetails,
ImageComparer comparer = null,
bool appendPixelTypeToFileName = true,
bool appendSourceFileOrDescription = true)
where TPixel : struct, IPixel<TPixel>
{
if (comparer == null)
{
comparer = ImageComparer.TolerantPercentage(0.001f);
}
using (Image<TPixel> image = provider.GetImage())
{
FormattableString testOutputDetails = $"";
image.Mutate(
ctx => { testOutputDetails = processAndGetTestOutputDetails(ctx); }
);
image.DebugSave(
provider,
testOutputDetails,
appendPixelTypeToFileName: appendPixelTypeToFileName,
appendSourceFileOrDescription: appendSourceFileOrDescription);
// TODO: Investigate the cause of pixel inaccuracies under Linux
if (TestEnvironment.IsWindows)
{
image.CompareToReferenceOutput(
comparer,
provider,
testOutputDetails,
appendPixelTypeToFileName: appendPixelTypeToFileName,
appendSourceFileOrDescription: appendSourceFileOrDescription);
}
}
}
public static void RunValidatingProcessorTestOnWrappedMemoryImage<TPixel>(
this TestImageProvider<TPixel> provider,
Action<IImageProcessingContext<TPixel>> process,

12
tests/ImageSharp.Tests/TestUtilities/Tests/TestImageProviderTests.cs

@ -9,6 +9,7 @@ using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using Xunit;
using Xunit.Abstractions;
// ReSharper disable InconsistentNaming
namespace SixLabors.ImageSharp.Tests
{
@ -313,6 +314,17 @@ namespace SixLabors.ImageSharp.Tests
}
[Theory]
[WithTestPatternImages(49,20, PixelTypes.Rgba32)]
public void Use_WithTestPatternImages<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> img = provider.GetImage())
{
img.DebugSave(provider);
}
}
public static readonly TheoryData<object> BasicData = new TheoryData<object>()
{
TestImageProvider<Rgba32>.Blank(10, 20),

2
tests/Images/External

@ -1 +1 @@
Subproject commit 5b18d8c95acffb773012881870ba6f521ba13128
Subproject commit 1edb0f3e04c18974821a3012a87f7c2e073c8019
Loading…
Cancel
Save