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

Loading…
Cancel
Save