@@ -70,14 +70,15 @@ public void ShouldVerifyThatImageStreamsSizeAreEqual(string pathActual, string p
7070 }
7171
7272 [ Test ]
73- [ TestCase ( jpg0Rgb24 , jpg0Rgb24 ) ]
74- [ TestCase ( png0Rgba32 , png0Rgba32 ) ]
75- public void ShouldVerifyThatImagesAreEqual ( string pathActual , string pathExpected )
73+ [ TestCase ( jpg0Rgb24 , jpg0Rgb24 , 0 ) ]
74+ [ TestCase ( png0Rgba32 , png0Rgba32 , 0 ) ]
75+ [ TestCase ( colorShift1 , colorShift2 , 15 ) ]
76+ public void ShouldVerifyThatImagesAreEqual ( string pathActual , string pathExpected , int pixelColorShiftTolerance )
7677 {
7778 var absolutePathActual = Path . Combine ( AppContext . BaseDirectory , pathActual ) ;
7879 var absolutePathExpected = Path . Combine ( AppContext . BaseDirectory , pathExpected ) ;
7980
80- Assert . That ( Compare . ImagesAreEqual ( absolutePathActual , absolutePathExpected ) , Is . True ) ;
81+ Assert . That ( Compare . ImagesAreEqual ( absolutePathActual , absolutePathExpected , pixelColorShiftTolerance : pixelColorShiftTolerance ) , Is . True ) ;
8182 }
8283
8384 [ Test ]
@@ -209,7 +210,7 @@ public void Diffmask(string pathPic1, string pathPic2, int expectedMeanError, in
209210 using ( var fileStreamDifferenceMask = File . Create ( differenceMask ) )
210211 using ( var maskImage = Compare . CalcDiffMaskImage ( absolutePathPic1 , absolutePathPic2 , resizeOption ) )
211212 {
212- SaveAsPng ( maskImage , fileStreamDifferenceMask ) ;
213+ IntegrationTest . SaveAsPng ( maskImage , fileStreamDifferenceMask ) ;
213214 }
214215
215216 var maskedDiff = Compare . CalcDiff ( absolutePathPic1 , absolutePathPic2 , differenceMask , resizeOption ) ;
@@ -221,7 +222,7 @@ public void Diffmask(string pathPic1, string pathPic2, int expectedMeanError, in
221222 Assert . That ( maskedDiff . PixelErrorPercentage , Is . EqualTo ( expectedPixelErrorPercentage ) , "PixelErrorPercentage" ) ;
222223 }
223224
224- private void SaveAsPng ( SKBitmap maskImage , FileStream fileStreamDifferenceMask )
225+ private static void SaveAsPng ( SKBitmap maskImage , FileStream fileStreamDifferenceMask )
225226 {
226227 var encodedData = maskImage . Encode ( SKEncodedImageFormat . Png , 100 ) ;
227228 encodedData . SaveTo ( fileStreamDifferenceMask ) ;
@@ -243,7 +244,7 @@ public void ShouldCalcDiffMaskSKBitmapAndUseOutcome(string pathPic1, string path
243244 using ( var fileStreamDifferenceMask = File . Create ( differenceMaskPicPath ) )
244245 using ( var maskImage = Compare . CalcDiffMaskImage ( absolutePic1 , absolutePic2 , resizeOption ) )
245246 {
246- SaveAsPng ( maskImage , fileStreamDifferenceMask ) ;
247+ IntegrationTest . SaveAsPng ( maskImage , fileStreamDifferenceMask ) ;
247248 }
248249
249250 using var differenceMaskPic = SKBitmap . Decode ( differenceMaskPicPath ) ;
@@ -318,9 +319,10 @@ public void DiffMaskStreams(string pathPic1, string pathPic2, int expectedMeanEr
318319 Assert . That ( maskedDiff . PixelErrorPercentage , Is . EqualTo ( expectedPixelErrorPercentage ) , "PixelErrorPercentage" ) ;
319320 }
320321
321- [ TestCase ( png0Rgba32 , png1Rgba32 , 0 ) ]
322- [ TestCase ( colorShift1 , colorShift2 , 20 ) ]
323- public void CalcDiffMaskImage_WhenSupplyingDiffMaskOfTwoImagesByFilePath_NoDifferences ( string image1RelativePath , string image2RelativePath , int pixelColorShiftTolerance )
322+ [ TestCase ( png0Rgba32 , png1Rgba32 , 0 , true ) ]
323+ [ TestCase ( colorShift1 , colorShift2 , 20 , false ) ]
324+ [ TestCase ( colorShift1 , colorShift2 , 0 , true ) ]
325+ public void CalcDiffMaskImage_WhenSupplyingDiffMaskOfTwoImagesByFilePath_NoDifferences ( string image1RelativePath , string image2RelativePath , int pixelColorShiftTolerance , bool expectIsImageEntirelyBlack )
324326 {
325327 var image1Path = Path . Combine ( AppContext . BaseDirectory , image1RelativePath ) ;
326328 var image2Path = Path . Combine ( AppContext . BaseDirectory , image2RelativePath ) ;
@@ -339,7 +341,7 @@ public void CalcDiffMaskImage_WhenSupplyingDiffMaskOfTwoImagesByFilePath_NoDiffe
339341 ImageExtensions . SaveAsPng ( diffMask2Image , diffMask2Stream ) ;
340342 }
341343
342- Assert . That ( IsImageEntirelyBlack ( diffMask2Image ) , Is . True ) ;
344+ Assert . That ( IsImageEntirelyBlack ( diffMask2Image ) , Is . EqualTo ( expectIsImageEntirelyBlack ) ) ;
343345
344346 File . Delete ( diffMask1Path ) ;
345347 }
@@ -373,22 +375,42 @@ public void CalcDiffMaskImage_WhenSupplyingDiffMaskOfTwoImagesByStream_NoDiffere
373375 File . Delete ( diffMask1Path ) ;
374376 }
375377
376- [ TestCase ( png0Rgba32 , png1Rgba32 ) ]
377- public void CalcDiffMaskImage_WhenSupplyingDiffMaskOfTwoImagesByImage_NoDifferences ( string image1RelativePath , string image2RelativePath )
378+ [ TestCase ( png0Rgba32 , png1Rgba32 , png1Rgba32 , 0 , false ) ]
379+ [ TestCase ( colorShift1 , colorShift1 , colorShift2 , 15 , true ) ]
380+ public void CalcDiffMaskImage_WhenSupplyingDiffMaskOfTwoImagesByImage_NoDifferences ( string image1RelativePath , string image2RelativePath , string image3RelativePath , int expectedPixelColorShiftTolerance , bool expectToleranceMaskToEntirelyBlack )
378381 {
379382 var image1Path = Path . Combine ( AppContext . BaseDirectory , image1RelativePath ) ;
380383 var image2Path = Path . Combine ( AppContext . BaseDirectory , image2RelativePath ) ;
384+ var image3Path = Path . Combine ( AppContext . BaseDirectory , image3RelativePath ) ;
381385
382386 using var image1 = SKBitmap . Decode ( image1Path ) ;
383387 using var image2 = SKBitmap . Decode ( image2Path ) ;
388+ using var image3 = SKBitmap . Decode ( image3Path ) ;
384389
385390 using var diffMask1Image = Compare . CalcDiffMaskImage ( image1 , image2 ) ;
386391
387- using var diffMask2Image = Compare . CalcDiffMaskImage ( image1 , image2 , diffMask1Image ) ;
392+ using var diffMask2Image = Compare . CalcDiffMaskImage ( image1 , image3 , diffMask1Image , pixelColorShiftTolerance : expectedPixelColorShiftTolerance ) ;
388393
394+ Assert . That ( IsImageEntirelyBlack ( diffMask1Image ) , Is . EqualTo ( expectToleranceMaskToEntirelyBlack ) ) ;
389395 Assert . That ( IsImageEntirelyBlack ( diffMask2Image ) , Is . True ) ;
390396 }
391397
398+ [ TestCase ( png0Rgba32 , png0Rgba32 , 0 ) ]
399+ [ TestCase ( png0Rgba32 , png0Rgba32 , 15 ) ]
400+ [ TestCase ( colorShift1 , colorShift2 , 15 ) ]
401+ public void CalcDiffMaskImage_ToleranceColorShift_NoDifferences ( string image1RelativePath , string image2RelativePath , int expectedPixelColorShiftTolerance )
402+ {
403+ var image1Path = Path . Combine ( AppContext . BaseDirectory , image1RelativePath ) ;
404+ var image2Path = Path . Combine ( AppContext . BaseDirectory , image2RelativePath ) ;
405+
406+ using var image1 = SKBitmap . Decode ( image1Path ) ;
407+ using var image2 = SKBitmap . Decode ( image2Path ) ;
408+
409+ using var diffMask1Image = Compare . CalcDiffMaskImage ( image1 , image2 , pixelColorShiftTolerance : expectedPixelColorShiftTolerance ) ;
410+
411+ Assert . That ( IsImageEntirelyBlack ( diffMask1Image ) , Is . True ) ;
412+ }
413+
392414 [ Test ]
393415 [ TestCase ( jpg0Rgb24 , jpg1Rgb24 ) ]
394416 [ TestCase ( png0Rgba32 , png1Rgba32 ) ]
0 commit comments