-
Notifications
You must be signed in to change notification settings - Fork 653
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Write unit tests for Color+Extension.swift (#101)
- Wrote tests - Possible minor bug where there's an alpha missing on 32-bit colors?
- Loading branch information
1 parent
99b952f
commit 4963ec5
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// | ||
// ColorExtensionTests.swift | ||
// SwiftUIChartsTests | ||
// | ||
// Created by Adrian Bolinger on 5/24/20. | ||
// | ||
|
||
@testable import SwiftUICharts | ||
import SwiftUI | ||
import XCTest | ||
|
||
class ColorExtensionTests: XCTestCase { | ||
func testTwentyFourBitRGBColors() { | ||
let actualWhite = Color(hexString: "FFFFFF") | ||
let expectedWhite = Color(red: 1, green: 1, blue: 1) | ||
XCTAssertEqual(actualWhite, expectedWhite) | ||
|
||
let actualBlack = Color(hexString: "000000") | ||
let expectedBlack = Color(red: 0, green: 0, blue: 0) | ||
XCTAssertEqual(actualBlack, expectedBlack) | ||
|
||
let actualRed = Color(hexString: "FF0000") | ||
let expectedRed = Color(red: 255/255, green: 0, blue: 0) | ||
XCTAssertEqual(actualRed, expectedRed) | ||
|
||
let actualGreen = Color(hexString: "00FF00") | ||
let expectedGreen = Color(red: 0, green: 1, blue: 0) | ||
XCTAssertEqual(actualGreen, expectedGreen) | ||
|
||
let actualBlue = Color(hexString: "0000FF") | ||
let expectedBlue = Color(red: 0, green: 0, blue: 1) | ||
XCTAssertEqual(actualBlue, expectedBlue) | ||
} | ||
|
||
func testTwelveBitRGBColors() { | ||
let actualWhite = Color(hexString: "FFF") | ||
let expectedWhite = Color(red: 1, green: 1, blue: 1) | ||
XCTAssertEqual(actualWhite, expectedWhite) | ||
|
||
let actualBlack = Color(hexString: "000") | ||
let expectedBlack = Color(red: 0, green: 0, blue: 0) | ||
XCTAssertEqual(actualBlack, expectedBlack) | ||
|
||
let actualRed = Color(hexString: "F00") | ||
let expectedRed = Color(red: 255/255, green: 0, blue: 0) | ||
XCTAssertEqual(actualRed, expectedRed) | ||
|
||
let actualGreen = Color(hexString: "0F0") | ||
let expectedGreen = Color(red: 0, green: 1, blue: 0) | ||
XCTAssertEqual(actualGreen, expectedGreen) | ||
|
||
let actualBlue = Color(hexString: "00F") | ||
let expectedBlue = Color(red: 0, green: 0, blue: 1) | ||
XCTAssertEqual(actualBlue, expectedBlue) | ||
} | ||
} |