Skip to content

Commit

Permalink
#30 - make DrawingHelper.RenderPreview testable
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeclayton committed Oct 12, 2023
1 parent e92747c commit 6062600
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/FancyMouse.UnitTests/Helpers/DrawingHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,16 @@ private static void AssertImagesEqual(Bitmap expected, Bitmap actual)
{
for (var x = 0; x < expected.Width; x++)
{
Assert.AreEqual(
expected.GetPixel(x, y),
actual.GetPixel(x, y),
$"images differ at pixel ({x}, {y}) - expected: {expected.GetPixel(x, y)}, actual: {actual.GetPixel(x, y)}");
var expectedPixel = expected.GetPixel(x, y);
var actualPixel = actual.GetPixel(x, y);

// allow a small tolerance for rounding differences in gdi
Assert.IsTrue(
(Math.Abs(expectedPixel.A - actualPixel.A) <= 1) &&
(Math.Abs(expectedPixel.R - actualPixel.R) <= 1) &&
(Math.Abs(expectedPixel.G - actualPixel.G) <= 1) &&
(Math.Abs(expectedPixel.B - actualPixel.B) <= 1),
$"images differ at pixel ({x}, {y}) - expected: {expectedPixel}, actual: {actualPixel}");
}
}
}
Expand Down

0 comments on commit 6062600

Please sign in to comment.