Last active
July 24, 2019 13:20
-
-
Save ollieatkinson/01c49ab54d64d75a04852d7ac1a44346 to your computer and use it in GitHub Desktop.
Assert that two colors are similar using XCTest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func XCTAssertColor(_ l: UIColor?, _ r: UIColor, accuracy: CGFloat, file: StaticString = #file, line: UInt = #line) { | |
guard let l = l else { | |
XCTFail("Color is 'nil'", file: file, line: line) | |
return | |
} | |
var (lh, rh) = (CGFloat(0), CGFloat(0)) | |
var (lb, rb) = (CGFloat(0), CGFloat(0)) | |
var (ls, rs) = (CGFloat(0), CGFloat(0)) | |
var (la, ra) = (CGFloat(0), CGFloat(0)) | |
l.getHue(&lh, saturation: &ls, brightness: &lb, alpha: &la) | |
r.getHue(&rh, saturation: &rs, brightness: &rb, alpha: &ra) | |
XCTAssertEqual(lh, rh, accuracy: accuracy, "Hue", file: file, line: line) | |
XCTAssertEqual(ls, rs, accuracy: accuracy, "Saturation", file: file, line: line) | |
XCTAssertEqual(lb, rb, accuracy: accuracy, "Brightness", file: file, line: line) | |
XCTAssertEqual(la, ra, accuracy: accuracy, "Alpha", file: file, line: line) | |
} |
Author
ollieatkinson
commented
Jul 24, 2019
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment