Skip to content

Commit 8a0abd4

Browse files
committed
Only checking if we've exceeded threshold if the current value fails
1 parent df33080 commit 8a0abd4

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

Sources/SnapshotTesting/Snapshotting/NSImage.swift

+4-2
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,11 @@ private func compare(_ old: NSImage, _ new: NSImage, precision: Float) -> Bool {
8484
var offset = 0
8585
while offset < pixelCount * 4 {
8686
if p1[offset] != p2[offset] {
87-
differentPixelCount += 1
87+
differentPixelCount += 1
88+
if differentPixelCount > threshold {
89+
return false
90+
}
8891
}
89-
if differentPixelCount > threshold { return false }
9092
offset += 1
9193
}
9294
return true

Sources/SnapshotTesting/Snapshotting/UIImage.swift

+6-2
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,12 @@ private func compare(_ old: UIImage, _ new: UIImage, precision: Float) -> Bool {
105105

106106
var byte = 0
107107
while byte < byteCount {
108-
if oldBytes[byte] != newerBytes[byte] { differentPixelCount += 1 }
109-
if differentPixelCount >= threshold { return false }
108+
if oldBytes[byte] != newerBytes[byte] {
109+
differentPixelCount += 1
110+
if differentPixelCount >= threshold {
111+
return false
112+
}
113+
}
110114
byte += 1
111115
}
112116
return true

0 commit comments

Comments
 (0)