@@ -14,7 +14,7 @@ export var test_Hex_Color = function () {
1414 TKUnit . assertEqual ( color . g , 0 , "Color.g not properly parsed" ) ;
1515 TKUnit . assertEqual ( color . b , 0 , "Color.b not properly parsed" ) ;
1616 TKUnit . assertEqual ( color . hex , "#FF0000" , "Color.hex not properly parsed" ) ;
17- TKUnit . assertEqual ( color . argb , _parseArgb ( 255 , 255 , 0 , 0 ) , "Color.argb not properly parsed" ) ;
17+ TKUnit . assertEqual ( color . argb , 0xFFFF0000 , "Color.argb not properly parsed" ) ;
1818}
1919
2020export var test_ShortHex_Color = function ( ) {
@@ -27,7 +27,7 @@ export var test_ShortHex_Color = function () {
2727 TKUnit . assertEqual ( color . g , 136 , "Color.g not properly parsed" ) ; // 0x88 == 136
2828 TKUnit . assertEqual ( color . b , 0 , "Color.b not properly parsed" ) ;
2929 TKUnit . assertEqual ( color . hex , "#FF8800" , "Color.hex not properly parsed" ) ;
30- TKUnit . assertEqual ( color . argb , _parseArgb ( 255 , 255 , 136 , 0 ) , "Color.argb not properly parsed" ) ;
30+ TKUnit . assertEqual ( color . argb , 0xFFFF8800 , "Color.argb not properly parsed" ) ;
3131}
3232
3333export var test_Argb_Color = function ( ) {
@@ -39,22 +39,21 @@ export var test_Argb_Color = function () {
3939 TKUnit . assertEqual ( color . r , 255 , "Color.r not properly parsed" ) ;
4040 TKUnit . assertEqual ( color . g , 100 , "Color.g not properly parsed" ) ;
4141 TKUnit . assertEqual ( color . b , 100 , "Color.b not properly parsed" ) ;
42- TKUnit . assertEqual ( color . hex , _buildHex ( 100 , 255 , 100 , 100 ) , "Color.hex not properly parsed" ) ;
43- TKUnit . assertEqual ( color . argb , _parseArgb ( 100 , 255 , 100 , 100 ) , "Color.argb not properly parsed" ) ;
42+ TKUnit . assertEqual ( color . hex , "#64FF6464" , "Color.hex not properly parsed" ) ;
43+ TKUnit . assertEqual ( color . argb , 0x64FF6464 , "Color.argb not properly parsed" ) ;
4444}
4545
4646export var test_ArgbInt_Color = function ( ) {
4747 // >> color-rgb-single
4848 // Creates the color with 100 alpha, 100 red, 100 green, 100 blue
49- var argb = ( 100 << 24 ) | ( 100 << 16 ) | ( 100 << 8 ) | 100 ;
50- var color = new Color ( argb ) ;
49+ var color = new Color ( 0x64646464 ) ;
5150 // << color-rgb-single
5251 TKUnit . assertEqual ( color . a , 100 , "Color.a not properly parsed" ) ;
5352 TKUnit . assertEqual ( color . r , 100 , "Color.r not properly parsed" ) ;
5453 TKUnit . assertEqual ( color . g , 100 , "Color.g not properly parsed" ) ;
5554 TKUnit . assertEqual ( color . b , 100 , "Color.b not properly parsed" ) ;
56- TKUnit . assertEqual ( color . hex , _buildHex ( 100 , 100 , 100 , 100 ) , "Color.hex not properly parsed" ) ;
57- TKUnit . assertEqual ( color . argb , _parseArgb ( 100 , 100 , 100 , 100 ) , "Color.argb not properly parsed" ) ;
55+ TKUnit . assertEqual ( color . hex , "#64646464" , "Color.hex not properly parsed" ) ;
56+ TKUnit . assertEqual ( color . argb , 0x64646464 , "Color.argb not properly parsed" ) ;
5857}
5958
6059export var test_rgb_Color_CSS = function ( ) {
@@ -69,13 +68,13 @@ export var test_rgb_Color_CSS = function () {
6968 TKUnit . assertEqual ( color . r , 255 , "Color.r not properly parsed" ) ;
7069 TKUnit . assertEqual ( color . g , 100 , "Color.g not properly parsed" ) ;
7170 TKUnit . assertEqual ( color . b , 100 , "Color.b not properly parsed" ) ;
72- TKUnit . assertEqual ( color . hex , _buildHex ( 255 , 255 , 100 , 100 ) , "Color.hex not properly parsed" ) ;
73- TKUnit . assertEqual ( color . argb , _parseArgb ( 255 , 255 , 100 , 100 ) , "Color.argb not properly parsed" ) ;
71+ TKUnit . assertEqual ( color . hex , "#FF6464" , "Color.hex not properly parsed" ) ;
72+ TKUnit . assertEqual ( color . argb , 0xFFFF6464 , "Color.argb not properly parsed" ) ;
7473}
7574
7675export var test_rgba_Color_CSS = function ( ) {
7776 var alpha = 0.5 ;
78- var expected = Math . round ( alpha * 255 ) ;
77+ var expected = 0x80 ;
7978 // <snippet module="color" title="color">
8079 // ### Creating a Color from four RGB values
8180 // ``` JavaScript
@@ -87,24 +86,6 @@ export var test_rgba_Color_CSS = function () {
8786 TKUnit . assertEqual ( color . r , 255 , "Color.r not properly parsed" ) ;
8887 TKUnit . assertEqual ( color . g , 100 , "Color.g not properly parsed" ) ;
8988 TKUnit . assertEqual ( color . b , 100 , "Color.b not properly parsed" ) ;
90- TKUnit . assertEqual ( color . hex , _buildHex ( expected , 255 , 100 , 100 ) , "Color.hex not properly parsed" ) ;
91- TKUnit . assertEqual ( color . argb , _parseArgb ( expected , 255 , 100 , 100 ) , "Color.argb not properly parsed" ) ;
92- }
93-
94- var _buildHex = function ( a : number , r : number , g : number , b : number ) : string {
95- return "#" + _componentToHex ( a ) + _componentToHex ( r ) + _componentToHex ( g ) + _componentToHex ( b ) ;
96- }
97-
98- var _componentToHex = function ( component : number ) : string {
99- var hex = component . toString ( 16 ) ;
100- if ( hex . length === 1 ) {
101- hex = "0" + hex ;
102- }
103-
104- return hex ;
105- }
106-
107- var _parseArgb = function ( a : number , r : number , g : number , b : number ) : number {
108- // Format is ARGB, so alpha takes the first 8 bits, red the next, green the next and the last 8 bits are for the blue component
109- return ( a << 24 ) | ( r << 16 ) | ( g << 8 ) | b ;
89+ TKUnit . assertEqual ( color . hex , "#80FF6464" , "Color.hex not properly parsed" ) ;
90+ TKUnit . assertEqual ( color . argb , 0x80FF6464 , "Color.argb not properly parsed" ) ;
11091}
0 commit comments