@@ -287,9 +287,26 @@ class DynamicColorTests: XCTestCase {
287
287
}
288
288
289
289
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 " )
293
310
}
294
311
295
312
func testInvertColor( ) {
0 commit comments