@@ -52,6 +52,106 @@ public Task CompareDifferent()
5252 return Verify ( compare ) ;
5353 }
5454
55+ // https://github.com/VerifyTests/Verify.ImageMagick/issues/754
56+ // Regression test: Ensure image comparisons correctly detect differences
57+ // regardless of the threshold value (as long as diff > threshold)
58+ [ Test ]
59+ public async Task Issue754_DifferentImagesShouldNotBeEqual ( )
60+ {
61+ // Simulate UI screenshot comparison - white background with different text positions
62+ using var image1 = new MagickImage ( MagickColors . White , 200 , 100 ) ;
63+ using var text1 = new MagickImage ( MagickColors . Black , 80 , 20 ) ;
64+ image1 . Composite ( text1 , 10 , 40 , CompositeOperator . Over ) ; // Text on left
65+
66+ using var image2 = new MagickImage ( MagickColors . White , 200 , 100 ) ;
67+ using var text2 = new MagickImage ( MagickColors . Black , 80 , 20 ) ;
68+ image2 . Composite ( text2 , 110 , 40 , CompositeOperator . Over ) ; // Text on right
69+
70+ var stream1 = new MemoryStream ( ) ;
71+ var stream2 = new MemoryStream ( ) ;
72+ image1 . Write ( stream1 , MagickFormat . Png ) ;
73+ image2 . Write ( stream2 , MagickFormat . Png ) ;
74+ stream1 . Position = 0 ;
75+ stream2 . Position = 0 ;
76+
77+ // Get raw diff to understand the magnitude
78+ using var img1 = new MagickImage ( stream1 ) ;
79+ using var img2 = new MagickImage ( stream2 ) ;
80+ var rawDiff = img1 . Compare ( img2 , ErrorMetric . Fuzz ) ;
81+
82+ stream1 . Position = 0 ;
83+ stream2 . Position = 0 ;
84+
85+ // With an extremely small threshold, different images MUST be detected
86+ var threshold = 0.00000000000001 ;
87+ var compare = await VerifyImageMagick . Compare ( threshold , ErrorMetric . Fuzz , stream1 , stream2 ) ;
88+
89+ Assert . That ( compare . IsEqual , Is . False ,
90+ $ "Different images (diff={ rawDiff } ) should be detected with threshold={ threshold } ") ;
91+ }
92+
93+ // https://github.com/VerifyTests/Verify.ImageMagick/issues/754
94+ // Test that threshold=0 and tiny threshold behave consistently
95+ [ Test ]
96+ public async Task Issue754_ZeroVsNonZeroThreshold ( )
97+ {
98+ using var image1 = new MagickImage ( MagickColors . White , 100 , 100 ) ;
99+ using var image2 = new MagickImage ( MagickColors . White , 100 , 100 ) ;
100+
101+ // Add a visible difference - 10x10 black square
102+ using var diff = new MagickImage ( MagickColors . Black , 10 , 10 ) ;
103+ image2 . Composite ( diff , 45 , 45 , CompositeOperator . Over ) ;
104+
105+ var stream1 = new MemoryStream ( ) ;
106+ var stream2 = new MemoryStream ( ) ;
107+ image1 . Write ( stream1 , MagickFormat . Png ) ;
108+ image2 . Write ( stream2 , MagickFormat . Png ) ;
109+
110+ // Compare with threshold = 0
111+ stream1 . Position = 0 ;
112+ stream2 . Position = 0 ;
113+ var compareZero = await VerifyImageMagick . Compare ( 0 , ErrorMetric . Fuzz , stream1 , stream2 ) ;
114+
115+ // Compare with tiny non-zero threshold
116+ stream1 . Position = 0 ;
117+ stream2 . Position = 0 ;
118+ var compareTiny = await VerifyImageMagick . Compare ( 0.00000000000001 , ErrorMetric . Fuzz , stream1 , stream2 ) ;
119+
120+ // Both should detect the difference
121+ Assert . Multiple ( ( ) =>
122+ {
123+ Assert . That ( compareZero . IsEqual , Is . False , "Threshold=0 should detect difference" ) ;
124+ Assert . That ( compareTiny . IsEqual , Is . False , "Tiny threshold should detect difference" ) ;
125+ } ) ;
126+ }
127+
128+ // https://github.com/VerifyTests/Verify.ImageMagick/issues/754
129+ // Verify RootMeanSquared works as a reliable alternative
130+ [ Test ]
131+ public async Task Issue754_RootMeanSquaredAsAlternative ( )
132+ {
133+ using var image1 = new MagickImage ( MagickColors . White , 100 , 100 ) ;
134+ using var block1 = new MagickImage ( MagickColors . Gray , 20 , 20 ) ;
135+ image1 . Composite ( block1 , 10 , 10 , CompositeOperator . Over ) ;
136+
137+ using var image2 = new MagickImage ( MagickColors . White , 100 , 100 ) ;
138+ using var block2 = new MagickImage ( MagickColors . Gray , 20 , 20 ) ;
139+ image2 . Composite ( block2 , 70 , 70 , CompositeOperator . Over ) ;
140+
141+ var stream1 = new MemoryStream ( ) ;
142+ var stream2 = new MemoryStream ( ) ;
143+ image1 . Write ( stream1 , MagickFormat . Png ) ;
144+ image2 . Write ( stream2 , MagickFormat . Png ) ;
145+ stream1 . Position = 0 ;
146+ stream2 . Position = 0 ;
147+
148+ var threshold = 0.00000000000001 ;
149+ var compare = await VerifyImageMagick . Compare ( threshold , ErrorMetric . RootMeanSquared , stream1 , stream2 ) ;
150+
151+ Assert . That ( compare . IsEqual , Is . False ,
152+ "RootMeanSquared should detect positional differences" ) ;
153+ }
154+
55155 [ Test ]
56156 public Task VerifyPdf ( ) =>
57157 VerifyFile ( "sample.pdf" ) ;
0 commit comments