@@ -15,161 +15,134 @@ module('Color');
1515test ( 'Set named color' , function ( ) {
1616 var path = new Path ( ) ;
1717 path . fillColor = 'red' ;
18- compareRgbColors ( path . fillColor , new Color ( 1 , 0 , 0 ) ) ;
18+ compareColors ( path . fillColor , new Color ( 1 , 0 , 0 ) ) ;
1919 equals ( path . fillColor . toCss ( ) , 'rgb(255, 0, 0)' ) ;
2020} ) ;
2121
2222test ( 'Set color to hex' , function ( ) {
2323 var path = new Path ( ) ;
2424 path . fillColor = '#ff0000' ;
25- compareRgbColors ( path . fillColor , new Color ( 1 , 0 , 0 ) ) ;
25+ compareColors ( path . fillColor , new Color ( 1 , 0 , 0 ) ) ;
2626 equals ( path . fillColor . toCss ( ) , 'rgb(255, 0, 0)' ) ;
2727
2828 var path = new Path ( ) ;
2929 path . fillColor = '#f00' ;
30- compareRgbColors ( path . fillColor , new Color ( 1 , 0 , 0 ) ) ;
30+ compareColors ( path . fillColor , new Color ( 1 , 0 , 0 ) ) ;
3131 equals ( path . fillColor . toCss ( ) , 'rgb(255, 0, 0)' ) ;
3232} ) ;
3333
3434test ( 'Set color to object' , function ( ) {
3535 var path = new Path ( ) ;
3636 path . fillColor = { red : 1 , green : 0 , blue : 1 } ;
37- compareRgbColors ( path . fillColor , new Color ( 1 , 0 , 1 ) ) ;
37+ compareColors ( path . fillColor , new Color ( 1 , 0 , 1 ) ) ;
3838 equals ( path . fillColor . toCss ( ) , 'rgb(255, 0, 255)' ) ;
3939
4040 var path = new Path ( ) ;
4141 path . fillColor = { gray : 0.2 } ;
42- compareRgbColors ( path . fillColor , new Color ( 0.8 , 0.8 , 0.8 ) ) ;
42+ compareColors ( path . fillColor , new Color ( 0.2 ) ) ;
4343 equals ( path . fillColor . toCss ( ) , 'rgb(204, 204, 204)' ) ;
4444} ) ;
4545
4646test ( 'Set color to array' , function ( ) {
4747 var path = new Path ( ) ;
4848 path . fillColor = [ 1 , 0 , 0 ] ;
49- compareRgbColors ( path . fillColor , new Color ( 1 , 0 , 0 ) ) ;
49+ compareColors ( path . fillColor , new Color ( 1 , 0 , 0 ) ) ;
5050 equals ( path . fillColor . toCss ( ) , 'rgb(255, 0, 0)' ) ;
5151} ) ;
5252
5353test ( 'Creating colors' , function ( ) {
5454
55- compareRgbColors ( new Color ( '#ff0000' ) , new Color ( 1 , 0 , 0 ) ,
56- 'RgbColor from hex code' ) ;
55+ compareColors ( new Color ( '#ff0000' ) , new Color ( 1 , 0 , 0 ) ,
56+ 'Color from hex code' ) ;
5757
58- compareRgbColors ( new Color ( { red : 1 , green : 0 , blue : 1 } ) ,
59- new Color ( 1 , 0 , 1 ) , 'RgbColor from rgb object literal' ) ;
58+ compareColors ( new Color ( { red : 1 , green : 0 , blue : 1 } ) ,
59+ new Color ( 1 , 0 , 1 ) , 'Color from rgb object literal' ) ;
6060
61- compareRgbColors ( new Color ( { gray : 0.2 } ) ,
62- new Color ( 0.8 , 0.8 , 0.8 ) , 'RgbColor from gray object literal' ) ;
61+ compareColors ( new Color ( { gray : 0.2 } ) ,
62+ new Color ( 0.8 , 0.8 , 0.8 ) . convert ( 'gray' ) , 'Color from gray object literal' ) ;
6363
64- compareRgbColors ( new Color ( { hue : 0 , saturation : 1 , brightness : 1 } ) ,
65- new Color ( 1 , 0 , 0 ) , 'RgbColor from hsb object literal' ) ;
64+ compareColors ( new Color ( { hue : 0 , saturation : 1 , brightness : 1 } ) ,
65+ new Color ( 1 , 0 , 0 ) . convert ( 'hsb' ) , 'Color from hsb object literal' ) ;
6666
67- compareRgbColors ( new Color ( [ 1 , 0 , 0 ] ) , new Color ( 1 , 0 , 0 ) ,
68- 'RgbColor from array' ) ;
67+ compareColors ( new Color ( [ 1 , 0 , 0 ] ) , new Color ( 1 , 0 , 0 ) ,
68+ 'Rgb Color from array' ) ;
6969
70- compareHsbColors ( new HsbColor ( '#000000' ) , new HsbColor ( 0 , 0 , 0 ) ,
71- 'HsbColor from hex code' ) ;
72-
73- compareHsbColors ( new HsbColor ( { red : 1 , green : 0 , blue : 0 } ) ,
74- new HsbColor ( 0 , 1 , 1 ) , 'HsbColor from rgb object literal' ) ;
75-
76- compareHsbColors ( new HsbColor ( { gray : 0.8 } ) ,
77- new HsbColor ( 0 , 0 , 0.2 ) , 'RgbColor from gray object literal' ) ;
78-
79- compareHsbColors ( new HsbColor ( [ 1 , 0 , 0 ] ) , new HsbColor ( 1 , 0 , 0 ) ,
80- 'HsbColor from array' ) ;
81-
82- compareGrayColors ( new GrayColor ( '#000000' ) , new GrayColor ( 1 ) ,
83- 'GrayColor from hex code' ) ;
84-
85- compareGrayColors ( new GrayColor ( '#ffffff' ) , new GrayColor ( 0 ) ,
86- 'GrayColor from hex code' ) ;
87-
88- compareGrayColors ( new GrayColor ( { red : 1 , green : 1 , blue : 1 } ) ,
89- new GrayColor ( 0 ) , 'GrayColor from rgb object literal' ) ;
90-
91- compareGrayColors ( new GrayColor ( { gray : 0.2 } ) ,
92- new GrayColor ( 0.2 ) , 'GrayColor from gray object literal' ) ;
93-
94- compareGrayColors ( new GrayColor ( { hue : 0 , saturation : 0 , brightness : 0.8 } ) ,
95- new GrayColor ( 0.2 ) , 'GrayColor from hsb object literal' ) ;
96-
97- compareGrayColors ( new GrayColor ( [ 1 ] ) , new GrayColor ( 1 ) ,
98- 'GrayColor from array' ) ;
70+ compareColors ( new Color ( [ 1 ] ) , new Color ( 1 ) ,
71+ 'Gray Color from array' ) ;
9972} ) ;
10073
101- test ( 'Get gray from RgbColor ' , function ( ) {
74+ test ( 'Get gray from RGB Color ' , function ( ) {
10275 var color = new Color ( 1 , 0.5 , 0.2 ) ;
10376 compareNumbers ( color . gray , 0.38458251953125 ) ;
10477
10578 var color = new Color ( 0.5 , 0.2 , 0.1 ) ;
10679 compareNumbers ( color . gray , 0.72137451171875 ) ;
10780} ) ;
10881
109- test ( 'Get gray from HsbColor ' , function ( ) {
82+ test ( 'Get gray from HSB Color ' , function ( ) {
11083 var color = new HsbColor ( 0 , 0 , 0.2 ) ;
11184 compareNumbers ( color . gray , 0.8 ) ;
11285} ) ;
11386
114- test ( 'Get red from HsbColor ' , function ( ) {
87+ test ( 'Get red from HSB Color ' , function ( ) {
11588 var color = new HsbColor ( 0 , 1 , 1 ) ;
11689 compareNumbers ( color . red , 1 ) ;
11790} ) ;
11891
119- test ( 'Get hue from RgbColor ' , function ( ) {
92+ test ( 'Get hue from RGB Color ' , function ( ) {
12093 var color = new Color ( 1 , 0 , 0 ) ;
12194 compareNumbers ( color . hue , 0 ) ;
12295 compareNumbers ( color . saturation , 1 ) ;
12396} ) ;
12497
12598test ( 'Gray Color' , function ( ) {
126- var color = new GrayColor ( 1 ) ;
99+ var color = new Color ( 1 ) ;
127100 compareNumbers ( color . gray , 1 ) ;
128101 compareNumbers ( color . red , 0 ) ;
102+ compareNumbers ( color . blue , 0 ) ;
129103
130104 color . red = 0.5 ;
131- compareNumbers ( color . gray , '0.84999' ) ;
105+ compareNumbers ( color . gray , 0.85055 ) ;
132106
133107 color . green = 0.2 ;
134- compareNumbers ( color . gray , '0.82051' ) ;
108+
109+ compareNumbers ( color . red , 0.5 ) ;
110+ compareNumbers ( color . green , 0.2 ) ;
111+ compareNumbers ( color . blue , 0 ) ;
112+
113+ compareNumbers ( color . gray , 0.73315 ) ;
135114} ) ;
136115
137116test ( 'Converting Colors' , function ( ) {
138117 var rgbColor = new Color ( 1 , 0.5 , 0.2 ) ;
139- compareNumbers ( new GrayColor ( rgbColor ) . gray , 0.38299560546875 ) ;
140-
141- var grayColor = new GrayColor ( 0.2 ) ;
142- var rgbColor = new Color ( grayColor ) ;
143- compareRgbColors ( rgbColor , [ 0.8 , 0.8 , 0.8 , 1 ] ) ;
144-
145- var hsbColor = new HsbColor ( grayColor ) ;
146- compareHsbColors ( hsbColor , [ 0 , 0 , 0.8 , 1 ] ) ;
147-
148- var rgbColor = new Color ( 1 , 0 , 0 ) ;
149- compareHsbColors ( new HsbColor ( rgbColor ) , [ 0 , 1 , 1 , 1 ] ) ;
118+ compareNumbers ( rgbColor . gray , 0.38299560546875 ) ;
119+ var grayColor = new Color ( 0.2 ) ;
120+ compareColors ( grayColor . convert ( 'rgb' ) , new Color ( 0.8 , 0.8 , 0.8 ) ) ;
121+ compareColors ( grayColor . convert ( 'hsb' ) , { hue : 0 , saturation : 0 , brightness : 0.8 } ) ;
122+ compareColors ( new Color ( 1 , 0 , 0 ) . convert ( 'hsb' ) , { hue : 0 , saturation : 1 , brightness : 1 } ) ;
150123} ) ;
151124
152- test ( 'Setting RgbColor #gray' , function ( ) {
125+ test ( 'Setting Color #gray' , function ( ) {
153126 var color = new Color ( 1 , 0.5 , 0.2 ) ;
154127 color . gray = 0.1 ;
155- compareRgbColors ( color , [ 0.9 , 0.9 , 0.9 , 1 ] ) ;
128+ compareColors ( color , new Color ( 0.1 ) ) ;
156129} ) ;
157130
158- test ( 'Setting HsbColor #red' , function ( ) {
159- var color = new HsbColor ( 180 , 0 , 0 ) ;
131+ test ( 'Setting Color #red' , function ( ) {
132+ var color = new Color ( { hue : 180 , saturation : 0 , brightness : 0 } ) ;
160133 color . red = 1 ;
161- compareHsbColors ( color , [ 0 , 1 , 1 , 1 ] ) ;
134+ compareColors ( color , new Color ( 0 , 1 , 1 ) ) ;
162135} ) ;
163136
164- test ( 'Setting HsbColor #gray' , function ( ) {
165- var color = new HsbColor ( 180 , 0 , 0 ) ;
137+ test ( 'Setting Color #gray' , function ( ) {
138+ var color = new Color ( { hue : 180 , saturation : 0 , brightness : 0 } ) ;
166139 color . gray = 0.5 ;
167- compareHsbColors ( color , [ 0 , 0 , 0.5 , 1 ] ) ;
140+ compareColors ( color , new Color ( 0.5 ) ) ;
168141} ) ;
169142
170143test ( 'Color.read(channels)' , function ( ) {
171144 var color = Color . read ( [ 0 , 0 , 1 ] ) ;
172- compareRgbColors ( color , [ 0 , 0 , 1 , 1 ] ) ;
145+ compareColors ( color , new Color ( 0 , 0 , 1 ) ) ;
173146} ) ;
174147
175148test ( 'Cloning colors' , function ( ) {
@@ -196,6 +169,6 @@ test('Color#convert', function() {
196169
197170test ( 'Saturation from black rgb' , function ( ) {
198171 equals ( function ( ) {
199- return new Color ( 0 , 0 , 0 ) . saturation == 0 ;
172+ return new Color ( 0 , 0 , 0 ) . saturation === 0 ;
200173 } , true ) ;
201174} ) ;
0 commit comments