Skip to content

Commit 5c7d732

Browse files
committed
Add missing unit tests for func grayscaled(mode:)
1 parent 80f2613 commit 5c7d732

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

Tests/DynamicColorTests.swift

+20-3
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,26 @@ class DynamicColorTests: XCTestCase {
287287
}
288288

289289
func testGrayscaleColor() {
290-
let grayscale = DynamicColor(hex: 0xc0392b).grayscaled()
291-
let desaturated = DynamicColor(hex: 0xc0392b).desaturated(amount: 1)
292-
XCTAssert(grayscale.isEqual(desaturated), "Colors should be the same")
290+
let baseColor = DynamicColor(hex: 0xc0392b)
291+
292+
let grayscaleByLuminance = baseColor.grayscaled(mode: .luminance)
293+
let expectedGrayscaleByLuminance = DynamicColor(white: 0.376, alpha: 1.0)
294+
XCTAssertEqual(grayscaleByLuminance, expectedGrayscaleByLuminance, accuracy: 0.001, "Colors should be the same")
295+
296+
let grayscaleByLightness = baseColor.grayscaled(mode: .lightness)
297+
let expectedGrayscaleByLightness = DynamicColor(white: 0.461, alpha: 1.0)
298+
XCTAssertEqual(grayscaleByLightness, expectedGrayscaleByLightness, accuracy: 0.001, "Colors should be the same")
299+
300+
let grayscaleByAverage = baseColor.grayscaled(mode: .average)
301+
let expectedGrayscaleByAverage = DynamicColor(white: 0.382, alpha: 1.0)
302+
XCTAssertEqual(grayscaleByAverage, expectedGrayscaleByAverage, accuracy: 0.001, "Colors should be the same")
303+
304+
let grayscaleByValue = baseColor.grayscaled(mode: .value)
305+
let expectedGrayscaleByValue = DynamicColor(white: 0.753, alpha: 1.0)
306+
XCTAssertEqual(grayscaleByValue, expectedGrayscaleByValue, accuracy: 0.001, "Colors should be the same")
307+
308+
let grayscaleByDefault = baseColor.grayscaled()
309+
XCTAssert(grayscaleByDefault.isEqual(grayscaleByLightness), "Colors should be the same")
293310
}
294311

295312
func testInvertColor() {

0 commit comments

Comments
 (0)