spectrum 0.0.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/HISTORY.md +56 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.md +255 -0
  5. data/lib/spectrum/describe.rb +55 -0
  6. data/lib/spectrum/feature/advice.rb +31 -0
  7. data/lib/spectrum/feature/feature.rb +192 -0
  8. data/lib/spectrum/feature/featurette.rb +68 -0
  9. data/lib/spectrum/feature/scenario.rb +203 -0
  10. data/lib/spectrum/feature/step.rb +50 -0
  11. data/lib/spectrum/feature.rb +45 -0
  12. data/lib/spectrum/spec/context.rb +409 -0
  13. data/lib/spectrum/spec/example.rb +231 -0
  14. data/lib/spectrum/spec/hooks.rb +83 -0
  15. data/lib/spectrum/testcase/test_case.rb +328 -0
  16. data/lib/spectrum/testcase/test_proc.rb +143 -0
  17. data/lib/spectrum/testcase.rb +28 -0
  18. data/lib/spectrum/version.rb +3 -0
  19. data/lib/spectrum/world.rb +15 -0
  20. data/lib/spectrum.rb +14 -138
  21. metadata +71 -72
  22. data/History.txt +0 -93
  23. data/Install.txt +0 -18
  24. data/Licence.txt +0 -27
  25. data/README.txt +0 -35
  26. data/lib/spectrum/cmyk.rb +0 -281
  27. data/lib/spectrum/css.rb +0 -28
  28. data/lib/spectrum/grayscale.rb +0 -212
  29. data/lib/spectrum/hsl.rb +0 -221
  30. data/lib/spectrum/palette/adobecolor.rb +0 -272
  31. data/lib/spectrum/palette/gimp.rb +0 -116
  32. data/lib/spectrum/palette/monocontrast.rb +0 -180
  33. data/lib/spectrum/palette.rb +0 -16
  34. data/lib/spectrum/rgb/metallic.rb +0 -43
  35. data/lib/spectrum/rgb-colors.rb +0 -355
  36. data/lib/spectrum/rgb.rb +0 -453
  37. data/lib/spectrum/yiq.rb +0 -84
  38. data/test/test_adobecolor.rb +0 -419
  39. data/test/test_all.rb +0 -23
  40. data/test/test_cmyk.rb +0 -128
  41. data/test/test_color.rb +0 -141
  42. data/test/test_css.rb +0 -29
  43. data/test/test_gimp.rb +0 -101
  44. data/test/test_grayscale.rb +0 -121
  45. data/test/test_hsl.rb +0 -153
  46. data/test/test_monocontrast.rb +0 -142
  47. data/test/test_rgb.rb +0 -344
  48. data/test/test_yiq.rb +0 -73
data/test/test_rgb.rb DELETED
@@ -1,344 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #--
3
- # Color
4
- # Colour management with Ruby
5
- # http://rubyforge.org/projects/color
6
- # Version 1.5.0
7
- #
8
- # Licensed under a MIT-style licence. See Licence.txt in the main
9
- # distribution for full licensing information.
10
- #
11
- # Copyright (c) 2005 - 2010 Austin Ziegler and Matt Lyon
12
- #++
13
-
14
- $LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib") if __FILE__ == $0
15
- require 'test/unit'
16
- require 'spectrum'
17
-
18
- module TestColor
19
- class TestRGB < Test::Unit::TestCase
20
- def test_adjust_brightness
21
- assert_equal("#1a1aff", Spectrum::RGB::Blue.adjust_brightness(10).html)
22
- assert_equal("#0000e6", Spectrum::RGB::Blue.adjust_brightness(-10).html)
23
- end
24
-
25
- def test_adjust_hue
26
- assert_equal("#6600ff", Spectrum::RGB::Blue.adjust_hue(10).html)
27
- assert_equal("#0066ff", Spectrum::RGB::Blue.adjust_hue(-10).html)
28
- end
29
-
30
- def test_adjust_saturation
31
- assert_equal("#ef9374",
32
- Spectrum::RGB::DarkSalmon.adjust_saturation(10).html)
33
- assert_equal("#e39980",
34
- Spectrum::RGB::DarkSalmon.adjust_saturation(-10).html)
35
- end
36
-
37
- def test_red
38
- red = Spectrum::RGB::Red.dup
39
- assert_in_delta(1.0, red.r, Spectrum::COLOR_TOLERANCE)
40
- assert_in_delta(100, red.red_p, Spectrum::COLOR_TOLERANCE)
41
- assert_in_delta(255, red.red, Spectrum::COLOR_TOLERANCE)
42
- assert_in_delta(1.0, red.r, Spectrum::COLOR_TOLERANCE)
43
- assert_nothing_raised { red.red_p = 33 }
44
- assert_in_delta(0.33, red.r, Spectrum::COLOR_TOLERANCE)
45
- assert_nothing_raised { red.red = 330 }
46
- assert_in_delta(1.0, red.r, Spectrum::COLOR_TOLERANCE)
47
- assert_nothing_raised { red.r = -3.3 }
48
- assert_in_delta(0.0, red.r, Spectrum::COLOR_TOLERANCE)
49
- end
50
-
51
- def test_green
52
- lime = Spectrum::RGB::Lime.dup
53
- assert_in_delta(1.0, lime.g, Spectrum::COLOR_TOLERANCE)
54
- assert_in_delta(100, lime.green_p, Spectrum::COLOR_TOLERANCE)
55
- assert_in_delta(255, lime.green, Spectrum::COLOR_TOLERANCE)
56
- assert_nothing_raised { lime.green_p = 33 }
57
- assert_in_delta(0.33, lime.g, Spectrum::COLOR_TOLERANCE)
58
- assert_nothing_raised { lime.green = 330 }
59
- assert_in_delta(1.0, lime.g, Spectrum::COLOR_TOLERANCE)
60
- assert_nothing_raised { lime.g = -3.3 }
61
- assert_in_delta(0.0, lime.g, Spectrum::COLOR_TOLERANCE)
62
- end
63
-
64
- def test_blue
65
- blue = Spectrum::RGB::Blue.dup
66
- assert_in_delta(1.0, blue.b, Spectrum::COLOR_TOLERANCE)
67
- assert_in_delta(255, blue.blue, Spectrum::COLOR_TOLERANCE)
68
- assert_in_delta(100, blue.blue_p, Spectrum::COLOR_TOLERANCE)
69
- assert_nothing_raised { blue.blue_p = 33 }
70
- assert_in_delta(0.33, blue.b, Spectrum::COLOR_TOLERANCE)
71
- assert_nothing_raised { blue.blue = 330 }
72
- assert_in_delta(1.0, blue.b, Spectrum::COLOR_TOLERANCE)
73
- assert_nothing_raised { blue.b = -3.3 }
74
- assert_in_delta(0.0, blue.b, Spectrum::COLOR_TOLERANCE)
75
- end
76
-
77
- def test_brightness
78
- assert_in_delta(0.0, Spectrum::RGB::Black.brightness, Spectrum::COLOR_TOLERANCE)
79
- assert_in_delta(0.5, Spectrum::RGB::Grey50.brightness, Spectrum::COLOR_TOLERANCE)
80
- assert_in_delta(1.0, Spectrum::RGB::White.brightness, Spectrum::COLOR_TOLERANCE)
81
- end
82
-
83
- def test_darken_by
84
- assert_in_delta(0.5, Spectrum::RGB::Blue.darken_by(50).b,
85
- Spectrum::COLOR_TOLERANCE)
86
- end
87
-
88
- def test_html
89
- assert_equal("#000000", Spectrum::RGB::Black.html)
90
- assert_equal(Spectrum::RGB::Black, Spectrum::RGB.from_html("#000000"))
91
- assert_equal("#0000ff", Spectrum::RGB::Blue.html)
92
- assert_equal("#00ff00", Spectrum::RGB::Lime.html)
93
- assert_equal("#ff0000", Spectrum::RGB::Red.html)
94
- assert_equal("#ffffff", Spectrum::RGB::White.html)
95
-
96
- assert_equal("rgb(0.00%, 0.00%, 0.00%)", Spectrum::RGB::Black.css_rgb)
97
- assert_equal("rgb(0.00%, 0.00%, 100.00%)", Spectrum::RGB::Blue.css_rgb)
98
- assert_equal("rgb(0.00%, 100.00%, 0.00%)", Spectrum::RGB::Lime.css_rgb)
99
- assert_equal("rgb(100.00%, 0.00%, 0.00%)", Spectrum::RGB::Red.css_rgb)
100
- assert_equal("rgb(100.00%, 100.00%, 100.00%)", Spectrum::RGB::White.css_rgb)
101
-
102
- assert_equal("rgba(0.00%, 0.00%, 0.00%, 1.00)", Spectrum::RGB::Black.css_rgba)
103
- assert_equal("rgba(0.00%, 0.00%, 100.00%, 1.00)", Spectrum::RGB::Blue.css_rgba)
104
- assert_equal("rgba(0.00%, 100.00%, 0.00%, 1.00)", Spectrum::RGB::Lime.css_rgba)
105
- assert_equal("rgba(100.00%, 0.00%, 0.00%, 1.00)", Spectrum::RGB::Red.css_rgba)
106
- assert_equal("rgba(100.00%, 100.00%, 100.00%, 1.00)",
107
- Spectrum::RGB::White.css_rgba)
108
- end
109
-
110
- def test_lighten_by
111
- assert_in_delta(1.0, Spectrum::RGB::Blue.lighten_by(50).b,
112
- Spectrum::COLOR_TOLERANCE)
113
- assert_in_delta(0.5, Spectrum::RGB::Blue.lighten_by(50).r,
114
- Spectrum::COLOR_TOLERANCE)
115
- assert_in_delta(0.5, Spectrum::RGB::Blue.lighten_by(50).g,
116
- Spectrum::COLOR_TOLERANCE)
117
- end
118
-
119
- def test_mix_with
120
- assert_in_delta(0.5, Spectrum::RGB::Red.mix_with(Spectrum::RGB::Blue, 50).r,
121
- Spectrum::COLOR_TOLERANCE)
122
- assert_in_delta(0.0, Spectrum::RGB::Red.mix_with(Spectrum::RGB::Blue, 50).g,
123
- Spectrum::COLOR_TOLERANCE)
124
- assert_in_delta(0.5, Spectrum::RGB::Red.mix_with(Spectrum::RGB::Blue, 50).b,
125
- Spectrum::COLOR_TOLERANCE)
126
- assert_in_delta(0.5, Spectrum::RGB::Blue.mix_with(Spectrum::RGB::Red, 50).r,
127
- Spectrum::COLOR_TOLERANCE)
128
- assert_in_delta(0.0, Spectrum::RGB::Blue.mix_with(Spectrum::RGB::Red, 50).g,
129
- Spectrum::COLOR_TOLERANCE)
130
- assert_in_delta(0.5, Spectrum::RGB::Blue.mix_with(Spectrum::RGB::Red, 50).b,
131
- Spectrum::COLOR_TOLERANCE)
132
- end
133
-
134
- def test_pdf_fill
135
- assert_equal("0.000 0.000 0.000 rg", Spectrum::RGB::Black.pdf_fill)
136
- assert_equal("0.000 0.000 1.000 rg", Spectrum::RGB::Blue.pdf_fill)
137
- assert_equal("0.000 1.000 0.000 rg", Spectrum::RGB::Lime.pdf_fill)
138
- assert_equal("1.000 0.000 0.000 rg", Spectrum::RGB::Red.pdf_fill)
139
- assert_equal("1.000 1.000 1.000 rg", Spectrum::RGB::White.pdf_fill)
140
- assert_equal("0.000 0.000 0.000 RG", Spectrum::RGB::Black.pdf_stroke)
141
- assert_equal("0.000 0.000 1.000 RG", Spectrum::RGB::Blue.pdf_stroke)
142
- assert_equal("0.000 1.000 0.000 RG", Spectrum::RGB::Lime.pdf_stroke)
143
- assert_equal("1.000 0.000 0.000 RG", Spectrum::RGB::Red.pdf_stroke)
144
- assert_equal("1.000 1.000 1.000 RG", Spectrum::RGB::White.pdf_stroke)
145
- end
146
-
147
- def test_to_cmyk
148
- assert_kind_of(Spectrum::CMYK, Spectrum::RGB::Black.to_cmyk)
149
- assert_equal(Spectrum::CMYK.new(0, 0, 0, 100), Spectrum::RGB::Black.to_cmyk)
150
- assert_equal(Spectrum::CMYK.new(0, 0, 100, 0),
151
- Spectrum::RGB::Yellow.to_cmyk)
152
- assert_equal(Spectrum::CMYK.new(100, 0, 0, 0), Spectrum::RGB::Cyan.to_cmyk)
153
- assert_equal(Spectrum::CMYK.new(0, 100, 0, 0),
154
- Spectrum::RGB::Magenta.to_cmyk)
155
- assert_equal(Spectrum::CMYK.new(0, 100, 100, 0), Spectrum::RGB::Red.to_cmyk)
156
- assert_equal(Spectrum::CMYK.new(100, 0, 100, 0),
157
- Spectrum::RGB::Lime.to_cmyk)
158
- assert_equal(Spectrum::CMYK.new(100, 100, 0, 0),
159
- Spectrum::RGB::Blue.to_cmyk)
160
- assert_equal(Spectrum::CMYK.new(10.32, 60.52, 10.32, 39.47),
161
- Spectrum::RGB::Purple.to_cmyk)
162
- assert_equal(Spectrum::CMYK.new(10.90, 59.13, 59.13, 24.39),
163
- Spectrum::RGB::Brown.to_cmyk)
164
- assert_equal(Spectrum::CMYK.new(0, 63.14, 18.43, 0),
165
- Spectrum::RGB::Carnation.to_cmyk)
166
- assert_equal(Spectrum::CMYK.new(7.39, 62.69, 62.69, 37.32),
167
- Spectrum::RGB::Cayenne.to_cmyk)
168
- end
169
-
170
- def test_to_grayscale
171
- assert_kind_of(Spectrum::GrayScale, Spectrum::RGB::Black.to_grayscale)
172
- assert_equal(Spectrum::GrayScale.from_fraction(0),
173
- Spectrum::RGB::Black.to_grayscale)
174
- assert_equal(Spectrum::GrayScale.from_fraction(0.5),
175
- Spectrum::RGB::Yellow.to_grayscale)
176
- assert_equal(Spectrum::GrayScale.from_fraction(0.5),
177
- Spectrum::RGB::Cyan.to_grayscale)
178
- assert_equal(Spectrum::GrayScale.from_fraction(0.5),
179
- Spectrum::RGB::Magenta.to_grayscale)
180
- assert_equal(Spectrum::GrayScale.from_fraction(0.5),
181
- Spectrum::RGB::Red.to_grayscale)
182
- assert_equal(Spectrum::GrayScale.from_fraction(0.5),
183
- Spectrum::RGB::Lime.to_grayscale)
184
- assert_equal(Spectrum::GrayScale.from_fraction(0.5),
185
- Spectrum::RGB::Blue.to_grayscale)
186
- assert_equal(Spectrum::GrayScale.from_fraction(0.2510),
187
- Spectrum::RGB::Purple.to_grayscale)
188
- assert_equal(Spectrum::GrayScale.new(40.58),
189
- Spectrum::RGB::Brown.to_grayscale)
190
- assert_equal(Spectrum::GrayScale.new(68.43),
191
- Spectrum::RGB::Carnation.to_grayscale)
192
- assert_equal(Spectrum::GrayScale.new(27.65),
193
- Spectrum::RGB::Cayenne.to_grayscale)
194
- end
195
-
196
- def test_to_hsl
197
- assert_kind_of(Spectrum::HSL, Spectrum::RGB::Black.to_hsl)
198
- assert_equal(Spectrum::HSL.new, Spectrum::RGB::Black.to_hsl)
199
- assert_equal(Spectrum::HSL.new(60, 100, 50), Spectrum::RGB::Yellow.to_hsl)
200
- assert_equal(Spectrum::HSL.new(180, 100, 50), Spectrum::RGB::Cyan.to_hsl)
201
- assert_equal(Spectrum::HSL.new(300, 100, 50), Spectrum::RGB::Magenta.to_hsl)
202
- assert_equal(Spectrum::HSL.new(0, 100, 50), Spectrum::RGB::Red.to_hsl)
203
- assert_equal(Spectrum::HSL.new(120, 100, 50), Spectrum::RGB::Lime.to_hsl)
204
- assert_equal(Spectrum::HSL.new(240, 100, 50), Spectrum::RGB::Blue.to_hsl)
205
- assert_equal(Spectrum::HSL.new(300, 100, 25.10),
206
- Spectrum::RGB::Purple.to_hsl)
207
- assert_equal(Spectrum::HSL.new(0, 59.42, 40.59),
208
- Spectrum::RGB::Brown.to_hsl)
209
- assert_equal(Spectrum::HSL.new(317.5, 100, 68.43),
210
- Spectrum::RGB::Carnation.to_hsl)
211
- assert_equal(Spectrum::HSL.new(0, 100, 27.64),
212
- Spectrum::RGB::Cayenne.to_hsl)
213
-
214
- assert_equal("hsl(0.00, 0.00%, 0.00%)", Spectrum::RGB::Black.css_hsl)
215
- assert_equal("hsl(60.00, 100.00%, 50.00%)",
216
- Spectrum::RGB::Yellow.css_hsl)
217
- assert_equal("hsl(180.00, 100.00%, 50.00%)", Spectrum::RGB::Cyan.css_hsl)
218
- assert_equal("hsl(300.00, 100.00%, 50.00%)",
219
- Spectrum::RGB::Magenta.css_hsl)
220
- assert_equal("hsl(0.00, 100.00%, 50.00%)", Spectrum::RGB::Red.css_hsl)
221
- assert_equal("hsl(120.00, 100.00%, 50.00%)", Spectrum::RGB::Lime.css_hsl)
222
- assert_equal("hsl(240.00, 100.00%, 50.00%)", Spectrum::RGB::Blue.css_hsl)
223
- assert_equal("hsl(300.00, 100.00%, 25.10%)",
224
- Spectrum::RGB::Purple.css_hsl)
225
- assert_equal("hsl(0.00, 59.42%, 40.59%)", Spectrum::RGB::Brown.css_hsl)
226
- assert_equal("hsl(317.52, 100.00%, 68.43%)",
227
- Spectrum::RGB::Carnation.css_hsl)
228
- assert_equal("hsl(0.00, 100.00%, 27.65%)", Spectrum::RGB::Cayenne.css_hsl)
229
-
230
- assert_equal("hsla(0.00, 0.00%, 0.00%, 1.00)",
231
- Spectrum::RGB::Black.css_hsla)
232
- assert_equal("hsla(60.00, 100.00%, 50.00%, 1.00)",
233
- Spectrum::RGB::Yellow.css_hsla)
234
- assert_equal("hsla(180.00, 100.00%, 50.00%, 1.00)",
235
- Spectrum::RGB::Cyan.css_hsla)
236
- assert_equal("hsla(300.00, 100.00%, 50.00%, 1.00)",
237
- Spectrum::RGB::Magenta.css_hsla)
238
- assert_equal("hsla(0.00, 100.00%, 50.00%, 1.00)",
239
- Spectrum::RGB::Red.css_hsla)
240
- assert_equal("hsla(120.00, 100.00%, 50.00%, 1.00)",
241
- Spectrum::RGB::Lime.css_hsla)
242
- assert_equal("hsla(240.00, 100.00%, 50.00%, 1.00)",
243
- Spectrum::RGB::Blue.css_hsla)
244
- assert_equal("hsla(300.00, 100.00%, 25.10%, 1.00)",
245
- Spectrum::RGB::Purple.css_hsla)
246
- assert_equal("hsla(0.00, 59.42%, 40.59%, 1.00)",
247
- Spectrum::RGB::Brown.css_hsla)
248
- assert_equal("hsla(317.52, 100.00%, 68.43%, 1.00)",
249
- Spectrum::RGB::Carnation.css_hsla)
250
- assert_equal("hsla(0.00, 100.00%, 27.65%, 1.00)",
251
- Spectrum::RGB::Cayenne.css_hsla)
252
-
253
- # The following tests a bug reported by Jean Krohn on 10 June 2006
254
- # where HSL conversion was not quite correct, resulting in a bad
255
- # round-trip.
256
- assert_equal("#008800", Spectrum::RGB.from_html("#008800").to_hsl.html)
257
- assert_not_equal("#002288", Spectrum::RGB.from_html("#008800").to_hsl.html)
258
-
259
- # The following tests a bug reported by Adam Johnson on 29 October
260
- # 2010.
261
- hsl = Spectrum::HSL.new(262, 67, 42)
262
- c = Spectrum::RGB.from_fraction(0.34496, 0.1386, 0.701399).to_hsl
263
- assert_in_delta hsl.h, c.h, Spectrum::COLOR_TOLERANCE, "Hue"
264
- assert_in_delta hsl.s, c.s, Spectrum::COLOR_TOLERANCE, "Saturation"
265
- assert_in_delta hsl.l, c.l, Spectrum::COLOR_TOLERANCE, "Luminance"
266
- end
267
-
268
- def test_to_rgb
269
- assert_equal(Spectrum::RGB::Black, Spectrum::RGB::Black.to_rgb)
270
- end
271
-
272
- def test_to_yiq
273
- assert_kind_of(Spectrum::YIQ, Spectrum::RGB::Black.to_yiq)
274
- assert_equal(Spectrum::YIQ.new, Spectrum::RGB::Black.to_yiq)
275
- assert_equal(Spectrum::YIQ.new(88.6, 32.1, 0), Spectrum::RGB::Yellow.to_yiq)
276
- assert_equal(Spectrum::YIQ.new(70.1, 0, 0), Spectrum::RGB::Cyan.to_yiq)
277
- assert_equal(Spectrum::YIQ.new(41.3, 27.5, 52.3),
278
- Spectrum::RGB::Magenta.to_yiq)
279
- assert_equal(Spectrum::YIQ.new(29.9, 59.6, 21.2), Spectrum::RGB::Red.to_yiq)
280
- assert_equal(Spectrum::YIQ.new(58.7, 0, 0), Spectrum::RGB::Lime.to_yiq)
281
- assert_equal(Spectrum::YIQ.new(11.4, 0, 31.1), Spectrum::RGB::Blue.to_yiq)
282
- assert_equal(Spectrum::YIQ.new(20.73, 13.80, 26.25),
283
- Spectrum::RGB::Purple.to_yiq)
284
- assert_equal(Spectrum::YIQ.new(30.89, 28.75, 10.23),
285
- Spectrum::RGB::Brown.to_yiq)
286
- assert_equal(Spectrum::YIQ.new(60.84, 23.28, 27.29),
287
- Spectrum::RGB::Carnation.to_yiq)
288
- assert_equal(Spectrum::YIQ.new(16.53, 32.96, 11.72),
289
- Spectrum::RGB::Cayenne.to_yiq)
290
- end
291
-
292
- def test_add
293
- assert_nothing_raised { Spectrum::RGB::Cyan + Spectrum::RGB::Yellow }
294
- white = Spectrum::RGB::Cyan + Spectrum::RGB::Yellow
295
- assert_not_nil(white)
296
- assert_equal(Spectrum::RGB::White, white)
297
-
298
- c1 = Spectrum::RGB.new(0x80, 0x80, 0x00)
299
- c2 = Spectrum::RGB.new(0x45, 0x20, 0xf0)
300
- cr = Spectrum::RGB.new(0xc5, 0xa0, 0xf0)
301
-
302
- assert_equal(cr, c1 + c2)
303
- end
304
-
305
- def test_subtract
306
- black = Spectrum::RGB::LightCoral - Spectrum::RGB::Honeydew
307
- assert_equal(Spectrum::RGB::Black, black)
308
-
309
- c1 = Spectrum::RGB.new(0x85, 0x80, 0x00)
310
- c2 = Spectrum::RGB.new(0x40, 0x20, 0xf0)
311
- cr = Spectrum::RGB.new(0x45, 0x60, 0x00)
312
-
313
- assert_equal(cr, c1 - c2)
314
- end
315
-
316
- def test_mean_grayscale
317
- c1 = Spectrum::RGB.new(0x85, 0x80, 0x00)
318
- c1_max = assert_nothing_raised { c1.max_rgb_as_greyscale }
319
- c1_max = c1.max_rgb_as_greyscale
320
- c1_result = Spectrum::GrayScale.from_fraction(0x85 / 255.0)
321
-
322
- assert_equal(c1_result, c1_max)
323
- end
324
-
325
- def test_from_html
326
- assert_equal("RGB [#333333]", Spectrum::RGB.from_html("#333").inspect)
327
- assert_equal("RGB [#333333]", Spectrum::RGB.from_html("333").inspect)
328
- assert_equal("RGB [#555555]", Spectrum::RGB.from_html("#555555").inspect)
329
- assert_equal("RGB [#555555]", Spectrum::RGB.from_html("555555").inspect)
330
- assert_raises(ArgumentError) { Spectrum::RGB.from_html("#5555555") }
331
- assert_raises(ArgumentError) { Spectrum::RGB.from_html("5555555") }
332
- assert_raises(ArgumentError) { Spectrum::RGB.from_html("#55555") }
333
- assert_raises(ArgumentError) { Spectrum::RGB.from_html("55555") }
334
- end
335
-
336
- def test_inspect
337
- assert_equal("RGB [#000000]", Spectrum::RGB::Black.inspect)
338
- assert_equal("RGB [#0000ff]", Spectrum::RGB::Blue.inspect)
339
- assert_equal("RGB [#00ff00]", Spectrum::RGB::Lime.inspect)
340
- assert_equal("RGB [#ff0000]", Spectrum::RGB::Red.inspect)
341
- assert_equal("RGB [#ffffff]", Spectrum::RGB::White.inspect)
342
- end
343
- end
344
- end
data/test/test_yiq.rb DELETED
@@ -1,73 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #--
3
- # Color
4
- # Colour management with Ruby
5
- # http://rubyforge.org/projects/color
6
- # Version 1.5.0
7
- #
8
- # Licensed under a MIT-style licence. See Licence.txt in the main
9
- # distribution for full licensing information.
10
- #
11
- # Copyright (c) 2005 - 2010 Austin Ziegler and Matt Lyon
12
- #++
13
-
14
- $LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib") if __FILE__ == $0
15
- require 'test/unit'
16
- require 'spectrum'
17
-
18
- module TestColor
19
- class TestYIQ < Test::Unit::TestCase
20
- def setup
21
- @yiq = Spectrum::YIQ.from_fraction(0.1, 0.2, 0.3)
22
- end
23
-
24
- def test_brightness
25
- assert_in_delta(0.1, @yiq.brightness, Spectrum::COLOR_TOLERANCE)
26
- end
27
-
28
- def test_i
29
- assert_in_delta(0.2, @yiq.i, Spectrum::COLOR_TOLERANCE)
30
- assert_in_delta(0.2, @yiq.i, Spectrum::COLOR_TOLERANCE)
31
- assert_nothing_raised { @yiq.i = 0.5 }
32
- assert_in_delta(0.5, @yiq.i, Spectrum::COLOR_TOLERANCE)
33
- assert_nothing_raised { @yiq.i = 5 }
34
- assert_in_delta(1.0, @yiq.i, Spectrum::COLOR_TOLERANCE)
35
- assert_nothing_raised { @yiq.i = -5 }
36
- assert_in_delta(0.0, @yiq.i, Spectrum::COLOR_TOLERANCE)
37
- end
38
-
39
- def test_q
40
- assert_in_delta(0.3, @yiq.q, Spectrum::COLOR_TOLERANCE)
41
- assert_in_delta(0.3, @yiq.q, Spectrum::COLOR_TOLERANCE)
42
- assert_nothing_raised { @yiq.q = 0.5 }
43
- assert_in_delta(0.5, @yiq.q, Spectrum::COLOR_TOLERANCE)
44
- assert_nothing_raised { @yiq.q = 5 }
45
- assert_in_delta(1.0, @yiq.q, Spectrum::COLOR_TOLERANCE)
46
- assert_nothing_raised { @yiq.q = -5 }
47
- assert_in_delta(0.0, @yiq.q, Spectrum::COLOR_TOLERANCE)
48
- end
49
-
50
- def test_to_grayscale
51
- assert_equal(Spectrum::GrayScale.new(0.1), @yiq.to_grayscale)
52
- end
53
-
54
- def test_to_yiq
55
- assert_equal(@yiq, @yiq.to_yiq)
56
- end
57
-
58
- def test_y
59
- assert_in_delta(0.1, @yiq.y, Spectrum::COLOR_TOLERANCE)
60
- assert_in_delta(0.1, @yiq.y, Spectrum::COLOR_TOLERANCE)
61
- assert_nothing_raised { @yiq.y = 0.5 }
62
- assert_in_delta(0.5, @yiq.y, Spectrum::COLOR_TOLERANCE)
63
- assert_nothing_raised { @yiq.y = 5 }
64
- assert_in_delta(1.0, @yiq.y, Spectrum::COLOR_TOLERANCE)
65
- assert_nothing_raised { @yiq.y = -5 }
66
- assert_in_delta(0.0, @yiq.y, Spectrum::COLOR_TOLERANCE)
67
- end
68
-
69
- def test_inspect
70
- assert_equal("YIQ [10.00%, 20.00%, 30.00%]", @yiq.inspect)
71
- end
72
- end
73
- end