Browse Source

VerticalReturnsUnicolorColumns -> VerticalBrushReturnsUnicolorRows (+ simplify test code)

af/merge-core
Anton Firszov 8 years ago
parent
commit
96dfbcaf94
  1. 69
      tests/ImageSharp.Tests/Drawing/FillLinearGradientBrushTests.cs

69
tests/ImageSharp.Tests/Drawing/FillLinearGradientBrushTests.cs

@ -12,9 +12,12 @@ using SixLabors.ImageSharp.Processing.Drawing;
using SixLabors.ImageSharp.Processing.Drawing.Brushes.GradientBrushes; using SixLabors.ImageSharp.Processing.Drawing.Brushes.GradientBrushes;
using Xunit; using Xunit;
// ReSharper disable InconsistentNaming
namespace SixLabors.ImageSharp.Tests.Drawing namespace SixLabors.ImageSharp.Tests.Drawing
{ {
using SixLabors.ImageSharp.Advanced;
[GroupOutput("Drawing/GradientBrushes")] [GroupOutput("Drawing/GradientBrushes")]
public class FillLinearGradientBrushTests public class FillLinearGradientBrushTests
{ {
@ -51,7 +54,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing
TPixel red = NamedColors<TPixel>.Red; TPixel red = NamedColors<TPixel>.Red;
TPixel yellow = NamedColors<TPixel>.Yellow; TPixel yellow = NamedColors<TPixel>.Yellow;
LinearGradientBrush<TPixel> unicolorLinearGradientBrush = new LinearGradientBrush<TPixel>( var unicolorLinearGradientBrush = new LinearGradientBrush<TPixel>(
new SixLabors.Primitives.Point(0, 0), new SixLabors.Primitives.Point(0, 0),
new SixLabors.Primitives.Point(image.Width, 0), new SixLabors.Primitives.Point(image.Width, 0),
GradientRepetitionMode.None, GradientRepetitionMode.None,
@ -155,57 +158,41 @@ namespace SixLabors.ImageSharp.Tests.Drawing
[Theory] [Theory]
[WithBlankImages(10, 500, PixelTypes.Rgba32)] [WithBlankImages(10, 500, PixelTypes.Rgba32)]
public void VerticalReturnsUnicolorColumns<TPixel>( public void VerticalBrushReturnsUnicolorRows<TPixel>(
TestImageProvider<TPixel> provider) TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
using (var image = provider.GetImage()) provider.VerifyOperation(
{ image =>
int lastRowIndex = image.Height - 1; {
TPixel red = NamedColors<TPixel>.Red;
TPixel red = NamedColors<TPixel>.Red; TPixel yellow = NamedColors<TPixel>.Yellow;
TPixel yellow = NamedColors<TPixel>.Yellow;
LinearGradientBrush<TPixel> unicolorLinearGradientBrush = var unicolorLinearGradientBrush = new LinearGradientBrush<TPixel>(
new LinearGradientBrush<TPixel>( new SixLabors.Primitives.Point(0, 0),
new SixLabors.Primitives.Point(0, 0), new SixLabors.Primitives.Point(0, image.Height),
new SixLabors.Primitives.Point(0, image.Height), GradientRepetitionMode.None,
GradientRepetitionMode.None, new ColorStop<TPixel>(0, red),
new ColorStop<TPixel>(0, red), new ColorStop<TPixel>(1, yellow));
new ColorStop<TPixel>(1, yellow));
image.Mutate(x => x.Fill(unicolorLinearGradientBrush)); image.Mutate(x => x.Fill(unicolorLinearGradientBrush));
image.DebugSave(provider);
Random random = new Random(); VerifyAllRowsAreUnicolor(image);
},
false,
false);
using (PixelAccessor<TPixel> sourcePixels = image.Lock()) void VerifyAllRowsAreUnicolor(Image<TPixel> image)
{
for (int y = 0; y < image.Height; y++)
{ {
TPixel firstRowColor = sourcePixels[0, 0]; Span<TPixel> row = image.GetPixelRowSpan(y);
TPixel firstColorOfRow = row[0];
int columnA = random.Next(0, image.Height); foreach (TPixel p in row)
int columnB = random.Next(0, image.Height);
int columnC = random.Next(0, image.Height);
TPixel columnColorA = sourcePixels[0, columnA];
TPixel columnColorB = sourcePixels[0, columnB];
TPixel columnColorC = sourcePixels[0, columnC];
TPixel lastRowColor = sourcePixels[0, lastRowIndex];
for (int i = 0; i < image.Width; i++)
{ {
// check first and last column, these are known: Assert.Equal(firstColorOfRow, p);
Assert.Equal(firstRowColor, sourcePixels[i, 0]);
Assert.Equal(lastRowColor, sourcePixels[i, lastRowIndex]);
// check the random colors:
Assert.Equal(columnColorA, sourcePixels[i, columnA]);
Assert.Equal(columnColorB, sourcePixels[i, columnB]);
Assert.Equal(columnColorC, sourcePixels[i, columnC]);
} }
} }
image.CompareToReferenceOutput(provider);
} }
} }

Loading…
Cancel
Save