Browse Source

Higher threshold for LomographTest

af/merge-core
Anton Firszov 8 years ago
parent
commit
fe20e71c09
  1. 4
      tests/ImageSharp.Tests/Processing/Processors/Filters/LomographTest.cs
  2. 2
      tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs
  3. 4
      tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs
  4. 13
      tests/ImageSharp.Tests/TestUtilities/Tests/ImageComparerTests.cs

4
tests/ImageSharp.Tests/Processing/Processors/Filters/LomographTest.cs

@ -7,6 +7,8 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters
{
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
[GroupOutput("Filters")]
public class LomographTest
{
@ -15,7 +17,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Filters
public void ApplyLomographFilter<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
provider.RunValidatingProcessorTest(x => x.Lomograph());
provider.RunValidatingProcessorTest(x => x.Lomograph(), comparer: ImageComparer.Tolerant(-2));
}
}
}

2
tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs

@ -18,7 +18,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison
/// <summary>
/// Returns an instance of <see cref="TolerantImageComparer"/>.
/// Individual manhattan pixel difference is only added to total image difference when the individual difference is over 'perPixelManhattanThreshold'.
/// Negative value for 'imageThreshold' indicates default threshold (see <see cref="TolerantImageComparer.DefaultImageThreshold"/>).
/// Negative value for 'imageThreshold' indicates multiplier to be applied to the default threshold (see <see cref="TolerantImageComparer.DefaultImageThreshold"/>).
/// </summary>
public static ImageComparer Tolerant(
float imageThreshold = -1,

4
tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs

@ -15,14 +15,14 @@
public static readonly float DefaultImageThreshold = GetDefaultImageThreshold();
/// <summary>
/// Negative value for 'imageThreshold' indicates default threshold (see <see cref="DefaultImageThreshold"/>).
/// Negative value for 'imageThreshold' indicates a multiplier to be applied to the default threshold (see <see cref="DefaultImageThreshold"/>).
/// Individual manhattan pixel difference is only added to total image difference when the individual difference is over 'perPixelManhattanThreshold'.
/// </summary>
public TolerantImageComparer(float imageThreshold, int perPixelManhattanThreshold = 0)
{
if (imageThreshold < 0)
{
imageThreshold = DefaultImageThreshold;
imageThreshold *= -DefaultImageThreshold;
}
this.ImageThreshold = imageThreshold;

13
tests/ImageSharp.Tests/TestUtilities/Tests/ImageComparerTests.cs

@ -23,6 +23,19 @@ namespace SixLabors.ImageSharp.Tests
private ITestOutputHelper Output { get; }
[Fact]
public void TolerantImageComparer_NegativeThresholdIsMultiplierForDefault()
{
var c1 = (TolerantImageComparer)ImageComparer.Tolerant();
var c2 = (TolerantImageComparer)ImageComparer.Tolerant(-2);
var c3 = (TolerantImageComparer)ImageComparer.Tolerant(-42);
Assert.True(c1.ImageThreshold > 0);
Assert.Equal(TolerantImageComparer.DefaultImageThreshold, c1.ImageThreshold);
Assert.Equal(c1.ImageThreshold * 2, c2.ImageThreshold);
Assert.Equal(c1.ImageThreshold * 42, c3.ImageThreshold);
}
[Theory]
[WithTestPatternImages(100,100,PixelTypes.Rgba32, 0.0001f, 1)]
[WithTestPatternImages(100, 100, PixelTypes.Rgba32, 0, 0)]

Loading…
Cancel
Save