Skip to content

Commit

Permalink
FillLinearGradientBrushTests #1
Browse files Browse the repository at this point in the history
  • Loading branch information
antonfirsov committed May 11, 2018
1 parent e3889ab commit ce8ca97
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 66 deletions.
134 changes: 69 additions & 65 deletions tests/ImageSharp.Tests/Drawing/FillLinearGradientBrushTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,50 +20,48 @@ public class FillLinearGradientBrushTests
{
[Theory]
[WithBlankImages(10, 10, PixelTypes.Rgba32)]
public void WithEqualColorsReturnsUnicolorImage<TPixel>(
TestImageProvider<TPixel> provider)
public void WithEqualColorsReturnsUnicolorImage<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
TPixel red = NamedColors<TPixel>.Red;
using (var image = provider.GetImage())
{
LinearGradientBrush<TPixel> unicolorLinearGradientBrush =
new LinearGradientBrush<TPixel>(
new SixLabors.Primitives.Point(0, 0),
new SixLabors.Primitives.Point(10, 0),
GradientRepetitionMode.None,
new ColorStop<TPixel>(0, red),
new ColorStop<TPixel>(1, red));

image.Mutate(x => x.Fill(unicolorLinearGradientBrush));
image.DebugSave(provider);
image.CompareToReferenceOutput(provider);
}
provider.VerifyOperation(
image =>
{
TPixel red = NamedColors<TPixel>.Red;
var unicolorLinearGradientBrush = new LinearGradientBrush<TPixel>(
new SixLabors.Primitives.Point(0, 0),
new SixLabors.Primitives.Point(10, 0),
GradientRepetitionMode.None,
new ColorStop<TPixel>(0, red),
new ColorStop<TPixel>(1, red));

image.Mutate(x => x.Fill(unicolorLinearGradientBrush));
},
false,
false);
}

[Theory]
[WithBlankImages(500, 10, PixelTypes.Rgba32)]
public void HorizontalReturnsUnicolorColumns<TPixel>(
TestImageProvider<TPixel> provider)
public void HorizontalReturnsUnicolorColumns<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (var image = provider.GetImage())
{
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(image.Width, 0),
GradientRepetitionMode.None,
new ColorStop<TPixel>(0, red),
new ColorStop<TPixel>(1, yellow));

image.Mutate(x => x.Fill(unicolorLinearGradientBrush));
image.DebugSave(provider);
image.CompareToReferenceOutput(provider);
}
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(image.Width, 0),
GradientRepetitionMode.None,
new ColorStop<TPixel>(0, red),
new ColorStop<TPixel>(1, yellow));

image.Mutate(x => x.Fill(unicolorLinearGradientBrush));
},
false,
false);
}

[Theory]
Expand All @@ -76,23 +74,23 @@ public void HorizontalGradientWithRepMode<TPixel>(
GradientRepetitionMode repetitionMode)
where TPixel : struct, IPixel<TPixel>
{
using (var image = provider.GetImage())
{
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(image.Width / 10, 0),
repetitionMode,
new ColorStop<TPixel>(0, red),
new ColorStop<TPixel>(1, yellow));

image.Mutate(x => x.Fill(unicolorLinearGradientBrush));
image.DebugSave(provider, repetitionMode);
image.CompareToReferenceOutput(provider, repetitionMode);
}
provider.VerifyOperation(
image =>
{
TPixel red = NamedColors<TPixel>.Red;
TPixel yellow = NamedColors<TPixel>.Yellow;

var unicolorLinearGradientBrush = new LinearGradientBrush<TPixel>(
new SixLabors.Primitives.Point(0, 0),
new SixLabors.Primitives.Point(image.Width / 10, 0),
repetitionMode,
new ColorStop<TPixel>(0, red),
new ColorStop<TPixel>(1, yellow));

image.Mutate(x => x.Fill(unicolorLinearGradientBrush));
},
false,
false);
}

[Theory]
Expand All @@ -104,7 +102,7 @@ public void WithDoubledStopsProduceDashedPatterns<TPixel>(
float[] pattern)
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
Assert.True(pattern.Length > 0);
Expand All @@ -127,25 +125,31 @@ public void WithDoubledStopsProduceDashedPatterns<TPixel>(

using (Image<TPixel> image = provider.GetImage())
{
LinearGradientBrush<TPixel> unicolorLinearGradientBrush =
var unicolorLinearGradientBrush =
new LinearGradientBrush<TPixel>(
new SixLabors.Primitives.Point(0, 0),
new SixLabors.Primitives.Point(image.Width, 0),
GradientRepetitionMode.None,
colorStops);

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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private string GetTestOutputFileNameImpl(
details = '_' + details;
}

return $"{this.GetTestOutputDir()}/{this.TestName}{pixName}{fn}{details}{extension}";
return TestUtils.AsInvariantString($"{this.GetTestOutputDir()}/{this.TestName}{pixName}{fn}{details}{extension}");
}

/// <summary>
Expand Down

0 comments on commit ce8ca97

Please sign in to comment.