Browse Source

Add previously skipped pad and resize tests

af/merge-core
James Jackson-South 8 years ago
parent
commit
28eb6d4bcb
  1. 6
      src/ImageSharp/Processing/Transforms/Pad.cs
  2. 24
      tests/ImageSharp.Tests/Processing/Transforms/PadTest.cs
  3. 84
      tests/ImageSharp.Tests/Processing/Transforms/ResizeTests.cs

6
src/ImageSharp/Processing/Transforms/Pad.cs

@ -1,10 +1,8 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives; using SixLabors.Primitives;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp
@ -25,11 +23,11 @@ namespace SixLabors.ImageSharp
public static IImageProcessingContext<TPixel> Pad<TPixel>(this IImageProcessingContext<TPixel> source, int width, int height) public static IImageProcessingContext<TPixel> Pad<TPixel>(this IImageProcessingContext<TPixel> source, int width, int height)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
ResizeOptions options = new ResizeOptions var options = new ResizeOptions
{ {
Size = new Size(width, height), Size = new Size(width, height),
Mode = ResizeMode.BoxPad, Mode = ResizeMode.BoxPad,
Sampler = new NearestNeighborResampler() Sampler = KnownResamplers.NearestNeighbor
}; };
return Resize(source, options); return Resize(source, options);

24
tests/ImageSharp.Tests/Processing/Transforms/PadTest.cs

@ -1,20 +1,30 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System; using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors;
using Xunit; using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Transforms namespace SixLabors.ImageSharp.Tests.Processing.Transforms
{ {
public class PadTest : BaseImageOperationsExtensionTest public class PadTest : BaseImageOperationsExtensionTest
{ {
#pragma warning disable xUnit1004 // Test methods should not be skipped [Fact]
[Fact(Skip = "Skip this is a helper around resize, skip until resize can be refactord")] public void PadWidthHeightResizeProcessorWithCorrectOptionsSet()
#pragma warning restore xUnit1004 // Test methods should not be skipped
public void Pad_width_height_ResizeProcessorWithCorrectOPtionsSet()
{ {
throw new NotImplementedException("Write test here"); int width = 500;
int height = 565;
IResampler sampler = KnownResamplers.NearestNeighbor;
this.operations.Pad(width, height);
ResizeProcessor<Rgba32> resizeProcessor = this.Verify<ResizeProcessor<Rgba32>>();
Assert.Equal(width, resizeProcessor.Width);
Assert.Equal(height, resizeProcessor.Height);
Assert.Equal(sampler, resizeProcessor.Sampler);
} }
} }
} }

84
tests/ImageSharp.Tests/Processing/Transforms/ResizeTests.cs

@ -1,23 +1,91 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
using SixLabors.Primitives; using SixLabors.Primitives;
using Xunit; using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Transforms namespace SixLabors.ImageSharp.Tests.Processing.Transforms
{ {
using SixLabors.ImageSharp.Processing.Processors;
public class ResizeTests : BaseImageOperationsExtensionTest public class ResizeTests : BaseImageOperationsExtensionTest
{ {
#pragma warning disable xUnit1004 // Test methods should not be skipped [Fact]
[Fact(Skip = "Skip resize tests as they need refactoring to be simpler and just pass data into the resize processor.")] public void ResizeWidthAndHeight()
#pragma warning restore xUnit1004 // Test methods should not be skipped {
public void TestMissing() int width = 50;
int height = 100;
this.operations.Resize(width, height);
ResizeProcessor<Rgba32> resizeProcessor = this.Verify<ResizeProcessor<Rgba32>>();
Assert.Equal(width, resizeProcessor.Width);
Assert.Equal(height, resizeProcessor.Height);
}
[Fact]
public void ResizeWidthAndHeightAndSampler()
{
int width = 50;
int height = 100;
IResampler sampler = KnownResamplers.Lanczos3;
this.operations.Resize(width, height, sampler);
ResizeProcessor<Rgba32> resizeProcessor = this.Verify<ResizeProcessor<Rgba32>>();
Assert.Equal(width, resizeProcessor.Width);
Assert.Equal(height, resizeProcessor.Height);
Assert.Equal(sampler, resizeProcessor.Sampler);
}
[Fact]
public void ResizeWidthAndHeightAndSamplerAndCompand()
{ {
// int width = 50;
throw new NotImplementedException("Write test here"); int height = 100;
IResampler sampler = KnownResamplers.Lanczos3;
bool compand = true;
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
this.operations.Resize(width, height, sampler, compand);
ResizeProcessor<Rgba32> resizeProcessor = this.Verify<ResizeProcessor<Rgba32>>();
Assert.Equal(width, resizeProcessor.Width);
Assert.Equal(height, resizeProcessor.Height);
Assert.Equal(sampler, resizeProcessor.Sampler);
Assert.Equal(compand, resizeProcessor.Compand);
}
[Fact]
public void ResizeWithOptions()
{
int width = 50;
int height = 100;
IResampler sampler = KnownResamplers.Lanczos3;
bool compand = true;
ResizeMode mode = ResizeMode.Stretch;
var resizeOptions = new ResizeOptions
{
Size = new Size(width, height),
Sampler = sampler,
Compand = compand,
Mode = mode
};
this.operations.Resize(resizeOptions);
ResizeProcessor<Rgba32> resizeProcessor = this.Verify<ResizeProcessor<Rgba32>>();
Assert.Equal(width, resizeProcessor.Width);
Assert.Equal(height, resizeProcessor.Height);
Assert.Equal(sampler, resizeProcessor.Sampler);
Assert.Equal(compand, resizeProcessor.Compand);
// Ensure options are not altered.
Assert.Equal(width, resizeOptions.Size.Width);
Assert.Equal(height, resizeOptions.Size.Height);
Assert.Equal(sampler, resizeOptions.Sampler);
Assert.Equal(compand, resizeOptions.Compand);
Assert.Equal(mode, resizeOptions.Mode);
} }
} }
} }
Loading…
Cancel
Save