-
Notifications
You must be signed in to change notification settings - Fork 380
/
UIColorTests.swift
70 lines (56 loc) · 1.53 KB
/
UIColorTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//
// UIColorTests.swift
// EZSwiftExtensions
//
// Created by Goktug Yilmaz on 8/25/16.
// Copyright © 2016 Goktug Yilmaz. All rights reserved.
//
import XCTest
import EZSwiftExtensions
class UIColorTests: XCTestCase {
var color: UIColor!
override func setUp() {
super.setUp()
color = UIColor.blue
}
func testInitRGBValues() {
color = UIColor(r: 255, g: 255, b: 255)
let red = color.cgColor.components?[0]
XCTAssertEqual(red, 1)
}
func testInitHexString() {
color = UIColor(hexString: "ff0000")
let red = color.cgColor.components?[0]
let green = color.cgColor.components?[1]
let blue = color.cgColor.components?[2]
XCTAssertEqual(red, 1)
XCTAssertEqual(blue, 0)
XCTAssertEqual(green, 0)
}
func testInitGray() {
color = UIColor(gray: 100)
var red: CGFloat = 0
var green: CGFloat = 0
var blue: CGFloat = 0
XCTAssertTrue(color.getRed(&red, green: &green, blue: &blue, alpha: nil))
let gray = Double(0.299 * red + 0.587 * green + 0.114 * blue).rounded(toPlaces: 7)
let testGray = (100.0 / 255).rounded(toPlaces: 7)
XCTAssertEqual(gray, testGray)
}
func testRedComponent() {
color = UIColor.red
XCTAssertEqual(color.redComponent, 255)
}
func testGreenComponent() {
color = UIColor.green
XCTAssertEqual(color.greenComponent, 255)
}
func testBlueComponent() {
color = UIColor.blue
XCTAssertEqual(color.blueComponent, 255)
}
func testAlpha() {
color = UIColor(red: 255, green: 255, blue: 255, alpha: 0.5)
XCTAssertEqual(color.alpha, 0.5)
}
}