Browse Source

Add missing tests

We need to refactor our tests to mostly use the generated patterns.
af/merge-core
James Jackson-South 9 years ago
parent
commit
a066c48e29
  1. 18
      src/ImageSharp/Processing/Effects/BackgroundColor.cs
  2. 6
      src/ImageSharp/Processing/Effects/Brightness.cs
  3. 2
      tests/ImageSharp.Tests/Processors/Filters/AlphaTest.cs
  4. 16
      tests/ImageSharp.Tests/Processors/Filters/BackgroundColorTest.cs
  5. 17
      tests/ImageSharp.Tests/Processors/Filters/BinaryThresholdTest.cs
  6. 16
      tests/ImageSharp.Tests/Processors/Filters/BlackWhiteTest.cs
  7. 17
      tests/ImageSharp.Tests/Processors/Filters/BoxBlurTest.cs
  8. 17
      tests/ImageSharp.Tests/Processors/Filters/BrightnessTest.cs
  9. 17
      tests/ImageSharp.Tests/Processors/Filters/ColorBlindnessTest.cs
  10. 17
      tests/ImageSharp.Tests/Processors/Filters/ContrastTest.cs
  11. 4
      tests/ImageSharp.Tests/Processors/Filters/GaussianBlurTest.cs
  12. 36
      tests/ImageSharp.Tests/Processors/Filters/GaussianSharpenTest.cs
  13. 28
      tests/ImageSharp.Tests/Processors/Filters/GrayscaleTest.cs
  14. 17
      tests/ImageSharp.Tests/Processors/Filters/HueTest.cs
  15. 16
      tests/ImageSharp.Tests/Processors/Filters/KodachromeTest.cs
  16. 16
      tests/ImageSharp.Tests/Processors/Filters/PolaroidTest.cs
  17. 17
      tests/ImageSharp.Tests/Processors/Filters/SaturationTest.cs
  18. 16
      tests/ImageSharp.Tests/Processors/Filters/SepiaTest.cs

18
src/ImageSharp/Processing/Effects/BackgroundColor.cs

@ -26,7 +26,23 @@ namespace ImageSharp
public static Image<TPixel> BackgroundColor<TPixel>(this Image<TPixel> source, TPixel color)
where TPixel : struct, IPixel<TPixel>
{
source.ApplyProcessor(new BackgroundColorProcessor<TPixel>(color), source.Bounds);
return BackgroundColor(source, color, source.Bounds);
}
/// <summary>
/// Replaces the background color of image with the given one.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="color">The color to set as the background.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image"/>.</returns>
public static Image<TPixel> BackgroundColor<TPixel>(this Image<TPixel> source, TPixel color, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
{
source.ApplyProcessor(new BackgroundColorProcessor<TPixel>(color), rectangle);
return source;
}
}

6
src/ImageSharp/Processing/Effects/Brightness.cs

@ -20,12 +20,12 @@ namespace ImageSharp
/// Alters the brightness component of the image.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="source">The image this method extends.</param>
/// <param name="amount">The new brightness of the image. Must be between -100 and 100.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Brightness<TPixel>(this Image<TPixel> source, int amount)
where TPixel : struct, IPixel<TPixel>
{
{
return Brightness(source, amount, source.Bounds);
}
@ -33,7 +33,7 @@ namespace ImageSharp
/// Alters the brightness component of the image.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="source">The image this method extends.</param>
/// <param name="amount">The new brightness of the image. Must be between -100 and 100.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.

2
tests/ImageSharp.Tests/Processors/Filters/AlphaTest.cs

@ -43,7 +43,7 @@ namespace ImageSharp.Tests
foreach (TestFile file in Files)
{
string filename = file.GetFileName(value);
string filename = file.GetFileName(value + "-InBox");
using (Image image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{

16
tests/ImageSharp.Tests/Processors/Filters/BackgroundColorTest.cs

@ -27,5 +27,21 @@ namespace ImageSharp.Tests
}
}
}
[Fact]
public void ImageShouldApplyBackgroundColorFilterInBox()
{
string path = this.CreateOutputDirectory("BackgroundColor");
foreach (TestFile file in Files)
{
string filename = file.GetFileName("-InBox");
using (Image image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.BackgroundColor(Rgba32.HotPink, new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output);
}
}
}
}
}

17
tests/ImageSharp.Tests/Processors/Filters/BinaryThreshold.cs → tests/ImageSharp.Tests/Processors/Filters/BinaryThresholdTest.cs

@ -34,5 +34,22 @@ namespace ImageSharp.Tests
}
}
}
[Theory]
[MemberData(nameof(BinaryThresholdValues))]
public void ImageShouldApplyBinaryThresholdInBox(float value)
{
string path = this.CreateOutputDirectory("BinaryThreshold");
foreach (TestFile file in Files)
{
string filename = file.GetFileName(value + "-InBox");
using (Image image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.BinaryThreshold(value, new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output);
}
}
}
}
}

16
tests/ImageSharp.Tests/Processors/Filters/BlackWhiteTest.cs

@ -25,5 +25,21 @@ namespace ImageSharp.Tests
}
}
}
[Fact]
public void ImageShouldApplyBlackWhiteFilterInBox()
{
string path = this.CreateOutputDirectory("BlackWhite");
foreach (TestFile file in Files)
{
string filename = file.GetFileName("-InBox");
using (Image image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.BlackWhite(new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output);
}
}
}
}
}

17
tests/ImageSharp.Tests/Processors/Filters/BoxBlurTest.cs

@ -34,5 +34,22 @@ namespace ImageSharp.Tests
}
}
}
[Theory]
[MemberData(nameof(BoxBlurValues))]
public void ImageShouldApplyBoxBlurFilterInBox(int value)
{
string path = this.CreateOutputDirectory("BoxBlur");
foreach (TestFile file in Files)
{
string filename = file.GetFileName(value + "-InBox");
using (Image image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.BoxBlur(value, new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output);
}
}
}
}
}

17
tests/ImageSharp.Tests/Processors/Filters/BrightnessTest.cs

@ -34,5 +34,22 @@ namespace ImageSharp.Tests
}
}
}
[Theory]
[MemberData(nameof(BrightnessValues))]
public void ImageShouldApplyBrightnessFilterInBox(int value)
{
string path = this.CreateOutputDirectory("Brightness");
foreach (TestFile file in Files)
{
string filename = file.GetFileName(value + "-InBox");
using (Image image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.Brightness(value, new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output);
}
}
}
}
}

17
tests/ImageSharp.Tests/Processors/Filters/ColorBlindnessTest.cs

@ -41,5 +41,22 @@ namespace ImageSharp.Tests
}
}
}
[Theory]
[MemberData(nameof(ColorBlindnessFilters))]
public void ImageShouldApplyBrightnessFilterInBox(ColorBlindness colorBlindness)
{
string path = this.CreateOutputDirectory("ColorBlindness");
foreach (TestFile file in Files)
{
string filename = file.GetFileName(colorBlindness + "-InBox");
using (Image image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.ColorBlindness(colorBlindness, new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output);
}
}
}
}
}

17
tests/ImageSharp.Tests/Processors/Filters/ContrastTest.cs

@ -33,5 +33,22 @@ namespace ImageSharp.Tests
}
}
}
[Theory]
[MemberData(nameof(ContrastValues))]
public void ImageShouldApplyContrastFilterInBox(int value)
{
string path = this.CreateOutputDirectory("Contrast");
foreach (TestFile file in Files)
{
string filename = file.GetFileName(value + "-InBox");
using (Image image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.Contrast(value, new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output);
}
}
}
}
}

4
tests/ImageSharp.Tests/Processors/Filters/GaussianBlurTest.cs

@ -26,7 +26,7 @@ namespace ImageSharp.Tests
using (Image<TPixel> image = provider.GetImage())
{
image.GaussianBlur(value)
.DebugSave(provider);
.DebugSave(provider, value.ToString());
}
}
@ -40,7 +40,7 @@ namespace ImageSharp.Tests
{
Rectangle rect = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2);
image.GaussianBlur(value, rect)
.DebugSave(provider);
.DebugSave(provider, value.ToString());
// lets draw identical shapes over the blured areas and ensure that it didn't change the outer area
image.Fill(NamedColors<TPixel>.HotPink, rect);

36
tests/ImageSharp.Tests/Processors/Filters/GaussianSharpenTest.cs

@ -6,7 +6,7 @@
namespace ImageSharp.Tests
{
using System.IO;
using ImageSharp.PixelFormats;
using Xunit;
public class GaussianSharpenTest : FileTestBase
@ -19,19 +19,33 @@ namespace ImageSharp.Tests
};
[Theory]
[MemberData(nameof(GaussianSharpenValues))]
public void ImageShouldApplyGaussianSharpenFilter(int value)
[WithTestPatternImages(nameof(GaussianSharpenValues), 320, 240, PixelTypes.StandardImageClass)]
public void ImageShouldApplyGaussianSharpenFilter<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
{
string path = this.CreateOutputDirectory("GaussianSharpen");
using (Image<TPixel> image = provider.GetImage())
{
image.GaussianSharpen(value)
.DebugSave(provider, value.ToString());
}
}
foreach (TestFile file in Files)
[Theory]
[WithTestPatternImages(nameof(GaussianSharpenValues), 320, 240, PixelTypes.StandardImageClass)]
public void ImageShouldApplyGaussianSharpenFilterInBox<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> source = provider.GetImage())
using (Image<TPixel> image = new Image<TPixel>(source))
{
string filename = file.GetFileName(value);
using (Image image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.GaussianSharpen(value).Save(output);
}
Rectangle rect = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2);
image.GaussianSharpen(value, rect)
.DebugSave(provider, value.ToString());
// lets draw identical shapes over the Sharpened areas and ensure that it didn't change the outer area
image.Fill(NamedColors<TPixel>.HotPink, rect);
source.Fill(NamedColors<TPixel>.HotPink, rect);
ImageComparer.CheckSimilarity(image, source);
}
}
}

28
tests/ImageSharp.Tests/Processors/Filters/GrayscaleTest.cs

@ -5,12 +5,8 @@
namespace ImageSharp.Tests
{
using System.IO;
using Xunit;
using ImageSharp.Processing;
using ImageSharp.Tests;
using System.Numerics;
using ImageSharp.PixelFormats;
@ -20,7 +16,7 @@ namespace ImageSharp.Tests
/// Use test patterns over loaded images to save decode time.
/// </summary>
[Theory]
[WithTestPatternImages(50, 50, PixelTypes.StandardImageClass, GrayscaleMode.Bt709)]
[WithTestPatternImages(50, 50, PixelTypes.StandardImageClass, GrayscaleMode.Bt709)]
[WithTestPatternImages(50, 50, PixelTypes.StandardImageClass, GrayscaleMode.Bt601)]
public void ImageShouldApplyGrayscaleFilterAll<TPixel>(TestImageProvider<TPixel> provider, GrayscaleMode value)
where TPixel : struct, IPixel<TPixel>
@ -36,7 +32,27 @@ namespace ImageSharp.Tests
Assert.Equal(data[1], data[2]);
}
image.DebugSave(provider);
image.DebugSave(provider, value.ToString());
}
}
[Theory]
[WithTestPatternImages(50, 50, PixelTypes.StandardImageClass, GrayscaleMode.Bt709)]
[WithTestPatternImages(50, 50, PixelTypes.StandardImageClass, GrayscaleMode.Bt601)]
public void ImageShouldApplyGrayscaleFilterInBox<TPixel>(TestImageProvider<TPixel> provider, GrayscaleMode value)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> source = provider.GetImage())
using (Image<TPixel> image = new Image<TPixel>(source))
{
Rectangle rect = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2);
image.Grayscale(rect, value)
.DebugSave(provider, value.ToString());
// Let's draw identical shapes over the greyed areas and ensure that it didn't change the outer area
image.Fill(NamedColors<TPixel>.HotPink, rect);
source.Fill(NamedColors<TPixel>.HotPink, rect);
ImageComparer.CheckSimilarity(image, source);
}
}
}

17
tests/ImageSharp.Tests/Processors/Filters/HueTest.cs

@ -34,5 +34,22 @@ namespace ImageSharp.Tests
}
}
}
[Theory]
[MemberData(nameof(HueValues))]
public void ImageShouldApplyHueFilterInBox(int value)
{
string path = this.CreateOutputDirectory("Hue");
foreach (TestFile file in Files)
{
string filename = file.GetFileName(value + "-InBox");
using (Image image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.Hue(value, new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output);
}
}
}
}
}

16
tests/ImageSharp.Tests/Processors/Filters/KodachromeTest.cs

@ -25,5 +25,21 @@ namespace ImageSharp.Tests
}
}
}
[Fact]
public void ImageShouldApplyKodachromeFilterInBox()
{
string path = this.CreateOutputDirectory("Kodachrome");
foreach (TestFile file in Files)
{
string filename = file.GetFileName("InBox");
using (Image image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.Kodachrome(new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output);
}
}
}
}
}

16
tests/ImageSharp.Tests/Processors/Filters/PolaroidTest.cs

@ -25,5 +25,21 @@ namespace ImageSharp.Tests
}
}
}
[Fact]
public void ImageShouldApplyPolaroidFilterInBox()
{
string path = this.CreateOutputDirectory("Polaroid");
foreach (TestFile file in Files)
{
string filename = file.GetFileName("InBox");
using (Image image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.Polaroid(new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output);
}
}
}
}
}

17
tests/ImageSharp.Tests/Processors/Filters/SaturationTest.cs

@ -34,5 +34,22 @@ namespace ImageSharp.Tests
}
}
}
[Theory]
[MemberData(nameof(SaturationValues))]
public void ImageShouldApplySaturationFilterInBox(int value)
{
string path = this.CreateOutputDirectory("Saturation");
foreach (TestFile file in Files)
{
string filename = file.GetFileName(value + "-InBox");
using (Image image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.Saturation(value, new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output);
}
}
}
}
}

16
tests/ImageSharp.Tests/Processors/Filters/SepiaTest.cs

@ -25,5 +25,21 @@ namespace ImageSharp.Tests
}
}
}
[Fact]
public void ImageShouldApplySepiaFilterInBox()
{
string path = this.CreateOutputDirectory("Sepia");
foreach (TestFile file in Files)
{
string filename = file.GetFileName("InBox");
using (Image image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.Sepia(new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output);
}
}
}
}
}
Loading…
Cancel
Save