Browse Source

FillLinearGradientBrushTests #1

af/merge-core
Anton Firszov 8 years ago
parent
commit
15947f84e0
  1. 134
      tests/ImageSharp.Tests/Drawing/FillLinearGradientBrushTests.cs
  2. 2
      tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs

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

@ -20,50 +20,48 @@ namespace SixLabors.ImageSharp.Tests.Drawing
{ {
[Theory] [Theory]
[WithBlankImages(10, 10, PixelTypes.Rgba32)] [WithBlankImages(10, 10, PixelTypes.Rgba32)]
public void WithEqualColorsReturnsUnicolorImage<TPixel>( public void WithEqualColorsReturnsUnicolorImage<TPixel>(TestImageProvider<TPixel> provider)
TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
TPixel red = NamedColors<TPixel>.Red; provider.VerifyOperation(
using (var image = provider.GetImage()) image =>
{ {
LinearGradientBrush<TPixel> unicolorLinearGradientBrush = TPixel red = NamedColors<TPixel>.Red;
new LinearGradientBrush<TPixel>( var unicolorLinearGradientBrush = new LinearGradientBrush<TPixel>(
new SixLabors.Primitives.Point(0, 0), new SixLabors.Primitives.Point(0, 0),
new SixLabors.Primitives.Point(10, 0), new SixLabors.Primitives.Point(10, 0),
GradientRepetitionMode.None, GradientRepetitionMode.None,
new ColorStop<TPixel>(0, red), new ColorStop<TPixel>(0, red),
new ColorStop<TPixel>(1, red)); new ColorStop<TPixel>(1, red));
image.Mutate(x => x.Fill(unicolorLinearGradientBrush)); image.Mutate(x => x.Fill(unicolorLinearGradientBrush));
image.DebugSave(provider); },
image.CompareToReferenceOutput(provider); false,
} false);
} }
[Theory] [Theory]
[WithBlankImages(500, 10, PixelTypes.Rgba32)] [WithBlankImages(500, 10, PixelTypes.Rgba32)]
public void HorizontalReturnsUnicolorColumns<TPixel>( public void HorizontalReturnsUnicolorColumns<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 =>
TPixel red = NamedColors<TPixel>.Red; {
TPixel yellow = NamedColors<TPixel>.Yellow; TPixel red = NamedColors<TPixel>.Red;
TPixel yellow = NamedColors<TPixel>.Yellow;
LinearGradientBrush<TPixel> unicolorLinearGradientBrush =
new LinearGradientBrush<TPixel>( LinearGradientBrush<TPixel> 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,
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); },
image.CompareToReferenceOutput(provider); false,
} false);
} }
[Theory] [Theory]
@ -76,23 +74,23 @@ namespace SixLabors.ImageSharp.Tests.Drawing
GradientRepetitionMode repetitionMode) GradientRepetitionMode repetitionMode)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
using (var image = provider.GetImage()) provider.VerifyOperation(
{ image =>
TPixel red = NamedColors<TPixel>.Red; {
TPixel yellow = NamedColors<TPixel>.Yellow; 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(0, 0),
new SixLabors.Primitives.Point(image.Width / 10, 0), new SixLabors.Primitives.Point(image.Width / 10, 0),
repetitionMode, repetitionMode,
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, repetitionMode); },
image.CompareToReferenceOutput(provider, repetitionMode); false,
} false);
} }
[Theory] [Theory]
@ -104,7 +102,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing
float[] pattern) float[] pattern)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
string variant = string.Join(",", pattern.Select(i => i.ToString(CultureInfo.InvariantCulture))); string variant = string.Join("_", pattern.Select(i => i.ToString(CultureInfo.InvariantCulture)));
// ensure the input data is valid // ensure the input data is valid
Assert.True(pattern.Length > 0); Assert.True(pattern.Length > 0);
@ -127,7 +125,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing
using (Image<TPixel> image = provider.GetImage()) using (Image<TPixel> image = provider.GetImage())
{ {
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(image.Width, 0), new SixLabors.Primitives.Point(image.Width, 0),
@ -135,17 +133,23 @@ namespace SixLabors.ImageSharp.Tests.Drawing
colorStops); colorStops);
image.Mutate(x => x.Fill(unicolorLinearGradientBrush)); image.Mutate(x => x.Fill(unicolorLinearGradientBrush));
image.DebugSave(provider, variant);
using (PixelAccessor<TPixel> sourcePixels = image.Lock())
{
// the result must be a black and white pattern, no other color should occur:
Assert.All(
Enumerable.Range(0, image.Width).Select(i => sourcePixels[i, 0]),
color => Assert.True(color.Equals(black) || color.Equals(white)));
}
image.CompareToReferenceOutput(provider, variant); image.DebugSave(
provider,
variant,
appendPixelTypeToFileName: false,
appendSourceFileOrDescription: false);
// the result must be a black and white pattern, no other color should occur:
Assert.All(
Enumerable.Range(0, image.Width).Select(i => image[i, 0]),
color => Assert.True(color.Equals(black) || color.Equals(white)));
image.CompareToReferenceOutput(
provider,
variant,
appendPixelTypeToFileName: false,
appendSourceFileOrDescription: false);
} }
} }

2
tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs

@ -92,7 +92,7 @@ namespace SixLabors.ImageSharp.Tests
details = '_' + details; details = '_' + details;
} }
return $"{this.GetTestOutputDir()}/{this.TestName}{pixName}{fn}{details}{extension}"; return TestUtils.AsInvariantString($"{this.GetTestOutputDir()}/{this.TestName}{pixName}{fn}{details}{extension}");
} }
/// <summary> /// <summary>

Loading…
Cancel
Save