Browse Source

DetectEdgesTest.DetectEdges_InBox issue isolated in a failing test for ParallelHelper.IterateRows()

af/merge-core
Anton Firszov 8 years ago
parent
commit
9e51f4b002
  1. 52
      tests/ImageSharp.Tests/Helpers/ParallelHelperTests.cs
  2. 16
      tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs

52
tests/ImageSharp.Tests/Helpers/ParallelHelperTests.cs

@ -9,6 +9,7 @@ using System.Threading;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.ParallelUtils; using SixLabors.ImageSharp.ParallelUtils;
using SixLabors.Memory;
using SixLabors.Primitives; using SixLabors.Primitives;
using Xunit; using Xunit;
@ -195,5 +196,56 @@ namespace SixLabors.ImageSharp.Tests.Helpers
Assert.Equal(expectedNumberOfSteps, actualNumberOfSteps); Assert.Equal(expectedNumberOfSteps, actualNumberOfSteps);
} }
public static readonly TheoryData<int, int, int, int, int, int, int> IterateRectangularBuffer_Data =
new TheoryData<int, int, int, int, int, int, int>()
{
{ 8, 582, 453, 10, 10, 291, 226 }, // bounds in DetectEdgesTest.DetectEdges_InBox
{ 2, 582, 453, 10, 10, 291, 226 },
};
[Theory]
[MemberData(nameof(IterateRectangularBuffer_Data))]
public void IterateRectangularBuffer(
int maxDegreeOfParallelism,
int bufferWidth,
int bufferHeight,
int rectX,
int rectY,
int rectWidth,
int rectHeight)
{
MemoryAllocator memoryAllocator = Configuration.Default.MemoryAllocator;
using (Buffer2D<int> expected = memoryAllocator.Allocate2D<int>(bufferWidth, bufferHeight, AllocationOptions.Clean))
using (Buffer2D<int> actual = memoryAllocator.Allocate2D<int>(bufferWidth, bufferHeight, AllocationOptions.Clean))
{
var rect = new Rectangle(rectX, rectY, rectWidth, rectHeight);
for (int y = rectY; y < rect.Bottom; y++)
{
for (int x = rect.Left; x < rect.Right; x++)
{
expected[x, y] = y * 10000 + x;
}
}
var settings = new ParallelExecutionSettings(maxDegreeOfParallelism, memoryAllocator);
ParallelHelper.IterateRows(rect, settings,
rows =>
{
for (int y = rows.Min; y < rows.Max; y++)
{
for (int x = rect.Left; x < rect.Right; x++)
{
actual[x, y] = y * 10000 + x;
}
}
});
TestImageExtensions.CompareBuffers(expected.Span, actual.Span);
}
}
} }
} }

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

@ -441,14 +441,20 @@ namespace SixLabors.ImageSharp.Tests
{ {
Span<TPixel> actualPixels = image.GetPixelSpan(); Span<TPixel> actualPixels = image.GetPixelSpan();
Assert.True(expectedPixels.Length == actualPixels.Length, "Buffer sizes are not equal!"); CompareBuffers(expectedPixels, actualPixels);
for (int i = 0; i < expectedPixels.Length; i++) return image;
}
public static void CompareBuffers<T>(Span<T> expected, Span<T> actual)
where T : struct, IEquatable<T>
{
Assert.True(expected.Length == actual.Length, "Buffer sizes are not equal!");
for (int i = 0; i < expected.Length; i++)
{ {
Assert.True(expectedPixels[i].Equals(actualPixels[i]), $"Pixels are different on position {i}!"); Assert.True(expected[i].Equals(actual[i]), $"Buffers differ at position {i}!");
} }
return image;
} }
/// <summary> /// <summary>

Loading…
Cancel
Save