Browse Source

add tolerance to comparison in tests

af/merge-core
Anton Firszov 8 years ago
parent
commit
4601ecc7f9
  1. 6
      tests/ImageSharp.Tests/Drawing/FillEllipticGradientBrushTest.cs
  2. 8
      tests/ImageSharp.Tests/Drawing/FillLinearGradientBrushTests.cs
  3. 5
      tests/ImageSharp.Tests/Drawing/FillRadialGradientBrushTests.cs
  4. 81
      tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs

6
tests/ImageSharp.Tests/Drawing/FillEllipticGradientBrushTest.cs

@ -12,9 +12,13 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Drawing namespace SixLabors.ImageSharp.Tests.Drawing
{ {
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
[GroupOutput("Drawing/GradientBrushes")] [GroupOutput("Drawing/GradientBrushes")]
public class FillEllipticGradientBrushTests public class FillEllipticGradientBrushTests
{ {
public static ImageComparer TolerantComparer = ImageComparer.TolerantPercentage(0.01f);
[Theory] [Theory]
[WithBlankImages(10, 10, PixelTypes.Rgba32)] [WithBlankImages(10, 10, PixelTypes.Rgba32)]
public void WithEqualColorsReturnsUnicolorImage<TPixel>( public void WithEqualColorsReturnsUnicolorImage<TPixel>(
@ -61,6 +65,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing
TPixel black = NamedColors<TPixel>.Black; TPixel black = NamedColors<TPixel>.Black;
provider.VerifyOperation( provider.VerifyOperation(
TolerantComparer,
image => image =>
{ {
var unicolorLinearGradientBrush = new EllipticGradientBrush<TPixel>( var unicolorLinearGradientBrush = new EllipticGradientBrush<TPixel>(
@ -108,6 +113,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing
FormattableString variant = $"{ratio:F2}_AT_{rotationInDegree:00}deg"; FormattableString variant = $"{ratio:F2}_AT_{rotationInDegree:00}deg";
provider.VerifyOperation( provider.VerifyOperation(
TolerantComparer,
image => image =>
{ {
TPixel yellow = NamedColors<TPixel>.Yellow; TPixel yellow = NamedColors<TPixel>.Yellow;

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

@ -17,10 +17,13 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Drawing namespace SixLabors.ImageSharp.Tests.Drawing
{ {
using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
[GroupOutput("Drawing/GradientBrushes")] [GroupOutput("Drawing/GradientBrushes")]
public class FillLinearGradientBrushTests public class FillLinearGradientBrushTests
{ {
public static ImageComparer TolerantComparer = ImageComparer.TolerantPercentage(0.01f);
[Theory] [Theory]
[WithBlankImages(10, 10, PixelTypes.Rgba32)] [WithBlankImages(10, 10, PixelTypes.Rgba32)]
public void WithEqualColorsReturnsUnicolorImage<TPixel>(TestImageProvider<TPixel> provider) public void WithEqualColorsReturnsUnicolorImage<TPixel>(TestImageProvider<TPixel> provider)
@ -54,6 +57,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
provider.VerifyOperation( provider.VerifyOperation(
TolerantComparer,
image => image =>
{ {
var unicolorLinearGradientBrush = new LinearGradientBrush<TPixel>( var unicolorLinearGradientBrush = new LinearGradientBrush<TPixel>(
@ -74,6 +78,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
provider.VerifyOperation( provider.VerifyOperation(
TolerantComparer,
image => image =>
{ {
TPixel red = NamedColors<TPixel>.Red; TPixel red = NamedColors<TPixel>.Red;
@ -103,6 +108,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
provider.VerifyOperation( provider.VerifyOperation(
TolerantComparer,
image => image =>
{ {
TPixel red = NamedColors<TPixel>.Red; TPixel red = NamedColors<TPixel>.Red;
@ -175,6 +181,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing
color => Assert.True(color.Equals(black) || color.Equals(white))); color => Assert.True(color.Equals(black) || color.Equals(white)));
image.CompareToReferenceOutput( image.CompareToReferenceOutput(
TolerantComparer,
provider, provider,
variant, variant,
appendPixelTypeToFileName: false, appendPixelTypeToFileName: false,
@ -286,6 +293,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing
} }
image.CompareToReferenceOutput( image.CompareToReferenceOutput(
TolerantComparer,
provider, provider,
startCorner, startCorner,
appendPixelTypeToFileName: false, appendPixelTypeToFileName: false,

5
tests/ImageSharp.Tests/Drawing/FillRadialGradientBrushTests.cs

@ -9,9 +9,13 @@ namespace SixLabors.ImageSharp.Tests.Drawing
{ {
using System; using System;
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
[GroupOutput("Drawing/GradientBrushes")] [GroupOutput("Drawing/GradientBrushes")]
public class FillRadialGradientBrushTests public class FillRadialGradientBrushTests
{ {
public static ImageComparer TolerantComparer = ImageComparer.TolerantPercentage(0.01f);
[Theory] [Theory]
[WithBlankImages(200, 200, PixelTypes.Rgba32)] [WithBlankImages(200, 200, PixelTypes.Rgba32)]
public void WithEqualColorsReturnsUnicolorImage<TPixel>( public void WithEqualColorsReturnsUnicolorImage<TPixel>(
@ -52,6 +56,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
provider.VerifyOperation( provider.VerifyOperation(
TolerantComparer,
image => image =>
{ {
var brush = new RadialGradientBrush<TPixel>( var brush = new RadialGradientBrush<TPixel>(

81
tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs

@ -544,6 +544,7 @@ namespace SixLabors.ImageSharp.Tests
/// </summary> /// </summary>
internal static void VerifyOperation<TPixel>( internal static void VerifyOperation<TPixel>(
this TestImageProvider<TPixel> provider, this TestImageProvider<TPixel> provider,
ImageComparer comparer,
Action<Image<TPixel>> operation, Action<Image<TPixel>> operation,
FormattableString testOutputDetails, FormattableString testOutputDetails,
bool appendPixelTypeToFileName = true, bool appendPixelTypeToFileName = true,
@ -560,13 +561,58 @@ namespace SixLabors.ImageSharp.Tests
appendPixelTypeToFileName: appendPixelTypeToFileName, appendPixelTypeToFileName: appendPixelTypeToFileName,
appendSourceFileOrDescription: appendSourceFileOrDescription); appendSourceFileOrDescription: appendSourceFileOrDescription);
image.CompareToReferenceOutput(provider, image.CompareToReferenceOutput(comparer,
provider,
testOutputDetails, testOutputDetails,
appendPixelTypeToFileName: appendPixelTypeToFileName, appendPixelTypeToFileName: appendPixelTypeToFileName,
appendSourceFileOrDescription: appendSourceFileOrDescription); appendSourceFileOrDescription: appendSourceFileOrDescription);
} }
} }
/// <summary>
/// Utility method for doing the following in one step:
/// 1. Executing an operation (taken as a delegate)
/// 2. Executing DebugSave()
/// 3. Executing CopareToReferenceOutput()
/// </summary>
internal static void VerifyOperation<TPixel>(
this TestImageProvider<TPixel> provider,
Action<Image<TPixel>> operation,
FormattableString testOutputDetails,
bool appendPixelTypeToFileName = true,
bool appendSourceFileOrDescription = true)
where TPixel : struct, IPixel<TPixel>
{
provider.VerifyOperation(
ImageComparer.Tolerant(),
operation,
testOutputDetails,
appendPixelTypeToFileName,
appendSourceFileOrDescription);
}
/// <summary>
/// Utility method for doing the following in one step:
/// 1. Executing an operation (taken as a delegate)
/// 2. Executing DebugSave()
/// 3. Executing CopareToReferenceOutput()
/// </summary>
internal static void VerifyOperation<TPixel>(
this TestImageProvider<TPixel> provider,
ImageComparer comparer,
Action<Image<TPixel>> operation,
bool appendPixelTypeToFileName = true,
bool appendSourceFileOrDescription = true)
where TPixel : struct, IPixel<TPixel>
{
provider.VerifyOperation(
comparer,
operation,
$"",
appendPixelTypeToFileName,
appendSourceFileOrDescription);
}
/// <summary> /// <summary>
/// Utility method for doing the following in one step: /// Utility method for doing the following in one step:
/// 1. Executing an operation (taken as a delegate) /// 1. Executing an operation (taken as a delegate)
@ -582,23 +628,28 @@ namespace SixLabors.ImageSharp.Tests
{ {
provider.VerifyOperation(operation, $"", appendPixelTypeToFileName, appendSourceFileOrDescription); provider.VerifyOperation(operation, $"", appendPixelTypeToFileName, appendSourceFileOrDescription);
} }
/// <summary> /// <summary>
/// Loads the expected image with a reference decoder + compares it to <paramref name="image"/>. /// Loads the expected image with a reference decoder + compares it to <paramref name="image"/>.
/// Also performs a debug save using <see cref="ImagingTestCaseUtility.SaveTestOutputFile{TPixel}"/>. /// Also performs a debug save using <see cref="ImagingTestCaseUtility.SaveTestOutputFile{TPixel}"/>.
/// </summary> /// </summary>
internal static void VerifyEncoder<TPixel>(this Image<TPixel> image, internal static void VerifyEncoder<TPixel>(
ITestImageProvider provider, this Image<TPixel> image,
string extension, ITestImageProvider provider,
object testOutputDetails, string extension,
IImageEncoder encoder, object testOutputDetails,
ImageComparer customComparer = null, IImageEncoder encoder,
bool appendPixelTypeToFileName = true, ImageComparer customComparer = null,
string referenceImageExtension = null bool appendPixelTypeToFileName = true,
) string referenceImageExtension = null)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
string actualOutputFile = provider.Utility.SaveTestOutputFile(image, extension, encoder, testOutputDetails, appendPixelTypeToFileName); string actualOutputFile = provider.Utility.SaveTestOutputFile(
image,
extension,
encoder,
testOutputDetails,
appendPixelTypeToFileName);
IImageDecoder referenceDecoder = TestEnvironment.GetReferenceDecoder(actualOutputFile); IImageDecoder referenceDecoder = TestEnvironment.GetReferenceDecoder(actualOutputFile);
using (var actualImage = Image.Load<TPixel>(actualOutputFile, referenceDecoder)) using (var actualImage = Image.Load<TPixel>(actualOutputFile, referenceDecoder))

Loading…
Cancel
Save