diff --git a/Tests/AppKit/CPColorTest.j b/Tests/AppKit/CPColorTest.j index a0ee065f1..53048543a 100644 --- a/Tests/AppKit/CPColorTest.j +++ b/Tests/AppKit/CPColorTest.j @@ -8,7 +8,7 @@ { var colors = ['000000', '0099CC', '7E8EAB', 'FFFFFF']; for (var i = 0; i < colors.length; ++i) - [self assert: colors[i] equals: [[CPColor colorWithHexString: colors[i]] hexString]]; + [self assert:colors[i] equals:[[CPColor colorWithHexString:colors[i]] hexString]]; } - (void)testColorWithCSSString @@ -21,6 +21,30 @@ [self assert:128 equals:ROUND([rgbaColour alphaComponent] * 255) message:"alpha component"]; } +- (void)testColorWithHue_saturation_brightness_ +{ + var tests = [ + [[0, 0, 0], [0, 0, 0]], + [[0, 0, 1], [1, 1, 1]], + [[0, 1, 1], [1, 0, 0]], + [[0.75, 1, 1], [0.5, 0, 1]], + [[0.5, 0.5, 0.5], [0.25, 0.5, 0.5]], + [[0.9, 0.8, 0.7], [0.7, 0.14, 0.476]] + ]; + + for (var i = 0; i < tests.length; i++) + { + var test = tests[i], + input = test[0], + expected = test[1], + c = [CPColor colorWithCalibratedHue:input[0] saturation:input[1] brightness:input[2] alpha:0.5]; + [self assert:expected equals:[Math.round([c redComponent] * 1000) / 1000, Math.round([c greenComponent] * 1000) / 1000, Math.round([c blueComponent] * 1000) / 1000] message:@"hue: " + input[0] + " saturation: " + input[1] + " brightness: " + input[2]]; + } + + var hsb = [[CPColor colorWithHue:0.9 saturation:0.8 brightness:0.7] hsbComponents]; + [self assert:[0.9, 0.8, 0.7] equals:[Math.round(hsb[0] * 10) / 10, Math.round(hsb[1] * 10) / 10, Math.round(hsb[2] * 10) / 10]]; +} + - (void)testIsEqual_ { // Based on https://gist.github.com/e06f749362cb1166439f by spakanati.