timocratic-color 1.4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +91 -0
- data/Install.txt +20 -0
- data/Licence.txt +29 -0
- data/Manifest.txt +31 -0
- data/Rakefile +116 -0
- data/Readme.txt +33 -0
- data/lib/color.rb +147 -0
- data/lib/color/cmyk.rb +281 -0
- data/lib/color/css.rb +30 -0
- data/lib/color/grayscale.rb +214 -0
- data/lib/color/hsl.rb +223 -0
- data/lib/color/palette.rb +18 -0
- data/lib/color/palette/adobecolor.rb +274 -0
- data/lib/color/palette/gimp.rb +118 -0
- data/lib/color/palette/monocontrast.rb +182 -0
- data/lib/color/rgb-colors.rb +357 -0
- data/lib/color/rgb.rb +455 -0
- data/lib/color/rgb/metallic.rb +45 -0
- data/lib/color/yiq.rb +86 -0
- data/setup.rb +1585 -0
- data/test/test_adobecolor.rb +421 -0
- data/test/test_all.rb +25 -0
- data/test/test_cmyk.rb +130 -0
- data/test/test_color.rb +134 -0
- data/test/test_css.rb +31 -0
- data/test/test_gimp.rb +103 -0
- data/test/test_grayscale.rb +123 -0
- data/test/test_hsl.rb +155 -0
- data/test/test_monocontrast.rb +144 -0
- data/test/test_rgb.rb +346 -0
- data/test/test_yiq.rb +75 -0
- metadata +109 -0
@@ -0,0 +1,144 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#--
|
3
|
+
# Color
|
4
|
+
# Colour management with Ruby
|
5
|
+
# http://rubyforge.org/projects/color
|
6
|
+
# Version 1.4.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 - 2007 Austin Ziegler and Matt Lyon
|
12
|
+
#
|
13
|
+
# $Id: test_all.rb 55 2007-02-03 23:29:34Z austin $
|
14
|
+
#++
|
15
|
+
|
16
|
+
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib") if __FILE__ == $0
|
17
|
+
require 'test/unit'
|
18
|
+
require 'color'
|
19
|
+
require 'color/palette/monocontrast'
|
20
|
+
|
21
|
+
module TestColor
|
22
|
+
module TestPalette
|
23
|
+
class TestMonoContrast < Test::Unit::TestCase
|
24
|
+
include Color::Palette
|
25
|
+
def setup
|
26
|
+
@high = Color::RGB.from_html("#c9e3a6")
|
27
|
+
@low = Color::RGB.from_html("#746b8e")
|
28
|
+
@mcp1 = MonoContrast.new(@high)
|
29
|
+
@mcp2 = MonoContrast.new(@low)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_background
|
33
|
+
assert_equal("#141711", @mcp1.background[-5].html)
|
34
|
+
assert_equal("#32392a", @mcp1.background[-4].html)
|
35
|
+
assert_equal("#657253", @mcp1.background[-3].html)
|
36
|
+
assert_equal("#97aa7d", @mcp1.background[-2].html)
|
37
|
+
assert_equal("#abc18d", @mcp1.background[-1].html)
|
38
|
+
assert_equal("#c9e3a6", @mcp1.background[ 0].html)
|
39
|
+
assert_equal("#d1e7b3", @mcp1.background[+1].html)
|
40
|
+
assert_equal("#d7eabc", @mcp1.background[+2].html) # d7eabd
|
41
|
+
assert_equal("#e4f1d3", @mcp1.background[+3].html) # e5f2d3
|
42
|
+
assert_equal("#f2f8e9", @mcp1.background[+4].html) # f1f8e9
|
43
|
+
assert_equal("#fafcf6", @mcp1.background[+5].html) # fafdf7
|
44
|
+
|
45
|
+
assert_equal("#0c0b0e", @mcp2.background[-5].html)
|
46
|
+
assert_equal("#1d1b24", @mcp2.background[-4].html)
|
47
|
+
assert_equal("#3a3647", @mcp2.background[-3].html)
|
48
|
+
assert_equal("#57506b", @mcp2.background[-2].html)
|
49
|
+
assert_equal("#635b79", @mcp2.background[-1].html)
|
50
|
+
assert_equal("#746b8e", @mcp2.background[ 0].html)
|
51
|
+
assert_equal("#89819f", @mcp2.background[+1].html)
|
52
|
+
assert_equal("#9790aa", @mcp2.background[+2].html) # 9790ab
|
53
|
+
assert_equal("#bab5c7", @mcp2.background[+3].html) # bab6c7
|
54
|
+
assert_equal("#dcdae3", @mcp2.background[+4].html)
|
55
|
+
assert_equal("#f1f0f4", @mcp2.background[+5].html) # f2f1f4
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_brightness_diff
|
59
|
+
bd1 = @mcp1.brightness_diff(@high, @low)
|
60
|
+
bd2 = @mcp1.brightness_diff(@low, @high)
|
61
|
+
assert_in_delta(bd1, bd2, Color::COLOR_TOLERANCE)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_calculate_foreground
|
65
|
+
assert_equal("#ffffff", @mcp1.calculate_foreground(@low, @high).html)
|
66
|
+
assert_equal("#1d1b24", @mcp1.calculate_foreground(@high, @low).html)
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_color_diff
|
70
|
+
assert_in_delta(@mcp1.color_diff(@low, @high),
|
71
|
+
@mcp1.color_diff(@high, @low),
|
72
|
+
Color::COLOR_TOLERANCE)
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_foreground
|
76
|
+
assert_equal("#c9e3a6", @mcp1.foreground[-5].html)
|
77
|
+
assert_equal("#e4f1d3", @mcp1.foreground[-4].html) # e5f2d3
|
78
|
+
assert_equal("#ffffff", @mcp1.foreground[-3].html)
|
79
|
+
assert_equal("#000000", @mcp1.foreground[-2].html)
|
80
|
+
assert_equal("#000000", @mcp1.foreground[-1].html)
|
81
|
+
assert_equal("#000000", @mcp1.foreground[ 0].html)
|
82
|
+
assert_equal("#000000", @mcp1.foreground[+1].html)
|
83
|
+
assert_equal("#000000", @mcp1.foreground[+2].html)
|
84
|
+
assert_equal("#32392a", @mcp1.foreground[+3].html)
|
85
|
+
assert_equal("#32392a", @mcp1.foreground[+4].html)
|
86
|
+
assert_equal("#32392a", @mcp1.foreground[+5].html)
|
87
|
+
|
88
|
+
assert_equal("#bab5c7", @mcp2.foreground[-5].html) # bab6c7
|
89
|
+
assert_equal("#dcdae3", @mcp2.foreground[-4].html)
|
90
|
+
assert_equal("#ffffff", @mcp2.foreground[-3].html)
|
91
|
+
assert_equal("#ffffff", @mcp2.foreground[-2].html)
|
92
|
+
assert_equal("#ffffff", @mcp2.foreground[-1].html)
|
93
|
+
assert_equal("#ffffff", @mcp2.foreground[ 0].html)
|
94
|
+
assert_equal("#000000", @mcp2.foreground[+1].html)
|
95
|
+
assert_equal("#000000", @mcp2.foreground[+2].html)
|
96
|
+
assert_equal("#000000", @mcp2.foreground[+3].html)
|
97
|
+
assert_equal("#1d1b24", @mcp2.foreground[+4].html)
|
98
|
+
assert_equal("#3a3647", @mcp2.foreground[+5].html)
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_minimum_brightness_diff
|
102
|
+
assert_in_delta(MonoContrast::DEFAULT_MINIMUM_BRIGHTNESS_DIFF,
|
103
|
+
@mcp1.minimum_brightness_diff, Color::COLOR_TOLERANCE)
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_minimum_brightness_diff_equals
|
107
|
+
assert_in_delta(MonoContrast::DEFAULT_MINIMUM_BRIGHTNESS_DIFF,
|
108
|
+
@mcp1.minimum_brightness_diff, Color::COLOR_TOLERANCE)
|
109
|
+
mcps = @mcp1.dup
|
110
|
+
assert_nothing_raised { @mcp1.minimum_brightness_diff = 0.75 }
|
111
|
+
assert_in_delta(0.75, @mcp1.minimum_brightness_diff, Color::COLOR_TOLERANCE)
|
112
|
+
assert_not_equal(@mcp1.foreground[-5], mcps.foreground[-5])
|
113
|
+
assert_nothing_raised { @mcp1.minimum_brightness_diff = 4.0 }
|
114
|
+
assert_in_delta(1, @mcp1.minimum_brightness_diff, Color::COLOR_TOLERANCE)
|
115
|
+
assert_nothing_raised { @mcp1.minimum_brightness_diff = -4.0 }
|
116
|
+
assert_in_delta(0, @mcp1.minimum_brightness_diff, Color::COLOR_TOLERANCE)
|
117
|
+
assert_nothing_raised { @mcp1.minimum_brightness_diff = nil }
|
118
|
+
assert_in_delta(MonoContrast::DEFAULT_MINIMUM_BRIGHTNESS_DIFF,
|
119
|
+
@mcp1.minimum_brightness_diff, Color::COLOR_TOLERANCE)
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_minimum_color_diff
|
123
|
+
assert_in_delta(MonoContrast::DEFAULT_MINIMUM_COLOR_DIFF,
|
124
|
+
@mcp1.minimum_color_diff, Color::COLOR_TOLERANCE)
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_minimum_color_diff_equals
|
128
|
+
assert_in_delta(MonoContrast::DEFAULT_MINIMUM_COLOR_DIFF,
|
129
|
+
@mcp1.minimum_color_diff, Color::COLOR_TOLERANCE)
|
130
|
+
mcps = @mcp1.dup
|
131
|
+
assert_nothing_raised { @mcp1.minimum_color_diff = 0.75 }
|
132
|
+
assert_in_delta(0.75, @mcp1.minimum_color_diff, Color::COLOR_TOLERANCE)
|
133
|
+
assert_not_equal(@mcp1.foreground[-5], mcps.foreground[-5])
|
134
|
+
assert_nothing_raised { @mcp1.minimum_color_diff = 4.0 }
|
135
|
+
assert_in_delta(3, @mcp1.minimum_color_diff, Color::COLOR_TOLERANCE)
|
136
|
+
assert_nothing_raised { @mcp1.minimum_color_diff = -4.0 }
|
137
|
+
assert_in_delta(0, @mcp1.minimum_color_diff, Color::COLOR_TOLERANCE)
|
138
|
+
assert_nothing_raised { @mcp1.minimum_color_diff = nil }
|
139
|
+
assert_in_delta(MonoContrast::DEFAULT_MINIMUM_COLOR_DIFF,
|
140
|
+
@mcp1.minimum_color_diff, Color::COLOR_TOLERANCE)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
data/test/test_rgb.rb
ADDED
@@ -0,0 +1,346 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#--
|
3
|
+
# Color
|
4
|
+
# Colour management with Ruby
|
5
|
+
# http://rubyforge.org/projects/color
|
6
|
+
# Version 1.4.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 - 2007 Austin Ziegler and Matt Lyon
|
12
|
+
#
|
13
|
+
# $Id: test_all.rb 55 2007-02-03 23:29:34Z austin $
|
14
|
+
#++
|
15
|
+
|
16
|
+
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib") if __FILE__ == $0
|
17
|
+
require 'test/unit'
|
18
|
+
require 'color'
|
19
|
+
|
20
|
+
module TestColor
|
21
|
+
class TestRGB < Test::Unit::TestCase
|
22
|
+
def test_adjust_brightness
|
23
|
+
assert_equal("#1a1aff", Color::RGB::Blue.adjust_brightness(10).html)
|
24
|
+
assert_equal("#0000e6", Color::RGB::Blue.adjust_brightness(-10).html)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_adjust_hue
|
28
|
+
assert_equal("#6600ff", Color::RGB::Blue.adjust_hue(10).html)
|
29
|
+
assert_equal("#0066ff", Color::RGB::Blue.adjust_hue(-10).html)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_adjust_saturation
|
33
|
+
assert_equal("#ef9374",
|
34
|
+
Color::RGB::DarkSalmon.adjust_saturation(10).html)
|
35
|
+
assert_equal("#e39980",
|
36
|
+
Color::RGB::DarkSalmon.adjust_saturation(-10).html)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_red
|
40
|
+
red = Color::RGB::Red.dup
|
41
|
+
assert_in_delta(1.0, red.r, Color::COLOR_TOLERANCE)
|
42
|
+
assert_in_delta(100, red.red_p, Color::COLOR_TOLERANCE)
|
43
|
+
assert_in_delta(255, red.red, Color::COLOR_TOLERANCE)
|
44
|
+
assert_in_delta(1.0, red.r, Color::COLOR_TOLERANCE)
|
45
|
+
assert_nothing_raised { red.red_p = 33 }
|
46
|
+
assert_in_delta(0.33, red.r, Color::COLOR_TOLERANCE)
|
47
|
+
assert_nothing_raised { red.red = 330 }
|
48
|
+
assert_in_delta(1.0, red.r, Color::COLOR_TOLERANCE)
|
49
|
+
assert_nothing_raised { red.r = -3.3 }
|
50
|
+
assert_in_delta(0.0, red.r, Color::COLOR_TOLERANCE)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_green
|
54
|
+
lime = Color::RGB::Lime.dup
|
55
|
+
assert_in_delta(1.0, lime.g, Color::COLOR_TOLERANCE)
|
56
|
+
assert_in_delta(100, lime.green_p, Color::COLOR_TOLERANCE)
|
57
|
+
assert_in_delta(255, lime.green, Color::COLOR_TOLERANCE)
|
58
|
+
assert_nothing_raised { lime.green_p = 33 }
|
59
|
+
assert_in_delta(0.33, lime.g, Color::COLOR_TOLERANCE)
|
60
|
+
assert_nothing_raised { lime.green = 330 }
|
61
|
+
assert_in_delta(1.0, lime.g, Color::COLOR_TOLERANCE)
|
62
|
+
assert_nothing_raised { lime.g = -3.3 }
|
63
|
+
assert_in_delta(0.0, lime.g, Color::COLOR_TOLERANCE)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_blue
|
67
|
+
blue = Color::RGB::Blue.dup
|
68
|
+
assert_in_delta(1.0, blue.b, Color::COLOR_TOLERANCE)
|
69
|
+
assert_in_delta(255, blue.blue, Color::COLOR_TOLERANCE)
|
70
|
+
assert_in_delta(100, blue.blue_p, Color::COLOR_TOLERANCE)
|
71
|
+
assert_nothing_raised { blue.blue_p = 33 }
|
72
|
+
assert_in_delta(0.33, blue.b, Color::COLOR_TOLERANCE)
|
73
|
+
assert_nothing_raised { blue.blue = 330 }
|
74
|
+
assert_in_delta(1.0, blue.b, Color::COLOR_TOLERANCE)
|
75
|
+
assert_nothing_raised { blue.b = -3.3 }
|
76
|
+
assert_in_delta(0.0, blue.b, Color::COLOR_TOLERANCE)
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_brightness
|
80
|
+
assert_in_delta(0.0, Color::RGB::Black.brightness, Color::COLOR_TOLERANCE)
|
81
|
+
assert_in_delta(0.5, Color::RGB::Grey50.brightness, Color::COLOR_TOLERANCE)
|
82
|
+
assert_in_delta(1.0, Color::RGB::White.brightness, Color::COLOR_TOLERANCE)
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_darken_by
|
86
|
+
assert_in_delta(0.5, Color::RGB::Blue.darken_by(50).b,
|
87
|
+
Color::COLOR_TOLERANCE)
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_html
|
91
|
+
assert_equal("#000000", Color::RGB::Black.html)
|
92
|
+
assert_equal(Color::RGB::Black, Color::RGB.from_html("#000000"))
|
93
|
+
assert_equal("#0000ff", Color::RGB::Blue.html)
|
94
|
+
assert_equal("#00ff00", Color::RGB::Lime.html)
|
95
|
+
assert_equal("#ff0000", Color::RGB::Red.html)
|
96
|
+
assert_equal("#ffffff", Color::RGB::White.html)
|
97
|
+
|
98
|
+
assert_equal("rgb(0.00%, 0.00%, 0.00%)", Color::RGB::Black.css_rgb)
|
99
|
+
assert_equal("rgb(0.00%, 0.00%, 100.00%)", Color::RGB::Blue.css_rgb)
|
100
|
+
assert_equal("rgb(0.00%, 100.00%, 0.00%)", Color::RGB::Lime.css_rgb)
|
101
|
+
assert_equal("rgb(100.00%, 0.00%, 0.00%)", Color::RGB::Red.css_rgb)
|
102
|
+
assert_equal("rgb(100.00%, 100.00%, 100.00%)", Color::RGB::White.css_rgb)
|
103
|
+
|
104
|
+
assert_equal("rgba(0.00%, 0.00%, 0.00%, 1.00)", Color::RGB::Black.css_rgba)
|
105
|
+
assert_equal("rgba(0.00%, 0.00%, 100.00%, 1.00)", Color::RGB::Blue.css_rgba)
|
106
|
+
assert_equal("rgba(0.00%, 100.00%, 0.00%, 1.00)", Color::RGB::Lime.css_rgba)
|
107
|
+
assert_equal("rgba(100.00%, 0.00%, 0.00%, 1.00)", Color::RGB::Red.css_rgba)
|
108
|
+
assert_equal("rgba(100.00%, 100.00%, 100.00%, 1.00)",
|
109
|
+
Color::RGB::White.css_rgba)
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_lighten_by
|
113
|
+
assert_in_delta(1.0, Color::RGB::Blue.lighten_by(50).b,
|
114
|
+
Color::COLOR_TOLERANCE)
|
115
|
+
assert_in_delta(0.5, Color::RGB::Blue.lighten_by(50).r,
|
116
|
+
Color::COLOR_TOLERANCE)
|
117
|
+
assert_in_delta(0.5, Color::RGB::Blue.lighten_by(50).g,
|
118
|
+
Color::COLOR_TOLERANCE)
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_mix_with
|
122
|
+
assert_in_delta(0.5, Color::RGB::Red.mix_with(Color::RGB::Blue, 50).r,
|
123
|
+
Color::COLOR_TOLERANCE)
|
124
|
+
assert_in_delta(0.0, Color::RGB::Red.mix_with(Color::RGB::Blue, 50).g,
|
125
|
+
Color::COLOR_TOLERANCE)
|
126
|
+
assert_in_delta(0.5, Color::RGB::Red.mix_with(Color::RGB::Blue, 50).b,
|
127
|
+
Color::COLOR_TOLERANCE)
|
128
|
+
assert_in_delta(0.5, Color::RGB::Blue.mix_with(Color::RGB::Red, 50).r,
|
129
|
+
Color::COLOR_TOLERANCE)
|
130
|
+
assert_in_delta(0.0, Color::RGB::Blue.mix_with(Color::RGB::Red, 50).g,
|
131
|
+
Color::COLOR_TOLERANCE)
|
132
|
+
assert_in_delta(0.5, Color::RGB::Blue.mix_with(Color::RGB::Red, 50).b,
|
133
|
+
Color::COLOR_TOLERANCE)
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_pdf_fill
|
137
|
+
assert_equal("0.000 0.000 0.000 rg", Color::RGB::Black.pdf_fill)
|
138
|
+
assert_equal("0.000 0.000 1.000 rg", Color::RGB::Blue.pdf_fill)
|
139
|
+
assert_equal("0.000 1.000 0.000 rg", Color::RGB::Lime.pdf_fill)
|
140
|
+
assert_equal("1.000 0.000 0.000 rg", Color::RGB::Red.pdf_fill)
|
141
|
+
assert_equal("1.000 1.000 1.000 rg", Color::RGB::White.pdf_fill)
|
142
|
+
assert_equal("0.000 0.000 0.000 RG", Color::RGB::Black.pdf_stroke)
|
143
|
+
assert_equal("0.000 0.000 1.000 RG", Color::RGB::Blue.pdf_stroke)
|
144
|
+
assert_equal("0.000 1.000 0.000 RG", Color::RGB::Lime.pdf_stroke)
|
145
|
+
assert_equal("1.000 0.000 0.000 RG", Color::RGB::Red.pdf_stroke)
|
146
|
+
assert_equal("1.000 1.000 1.000 RG", Color::RGB::White.pdf_stroke)
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_to_cmyk
|
150
|
+
assert_kind_of(Color::CMYK, Color::RGB::Black.to_cmyk)
|
151
|
+
assert_equal(Color::CMYK.new(0, 0, 0, 100), Color::RGB::Black.to_cmyk)
|
152
|
+
assert_equal(Color::CMYK.new(0, 0, 100, 0),
|
153
|
+
Color::RGB::Yellow.to_cmyk)
|
154
|
+
assert_equal(Color::CMYK.new(100, 0, 0, 0), Color::RGB::Cyan.to_cmyk)
|
155
|
+
assert_equal(Color::CMYK.new(0, 100, 0, 0),
|
156
|
+
Color::RGB::Magenta.to_cmyk)
|
157
|
+
assert_equal(Color::CMYK.new(0, 100, 100, 0), Color::RGB::Red.to_cmyk)
|
158
|
+
assert_equal(Color::CMYK.new(100, 0, 100, 0),
|
159
|
+
Color::RGB::Lime.to_cmyk)
|
160
|
+
assert_equal(Color::CMYK.new(100, 100, 0, 0),
|
161
|
+
Color::RGB::Blue.to_cmyk)
|
162
|
+
assert_equal(Color::CMYK.new(10.32, 60.52, 10.32, 39.47),
|
163
|
+
Color::RGB::Purple.to_cmyk)
|
164
|
+
assert_equal(Color::CMYK.new(10.90, 59.13, 59.13, 24.39),
|
165
|
+
Color::RGB::Brown.to_cmyk)
|
166
|
+
assert_equal(Color::CMYK.new(0, 63.14, 18.43, 0),
|
167
|
+
Color::RGB::Carnation.to_cmyk)
|
168
|
+
assert_equal(Color::CMYK.new(7.39, 62.69, 62.69, 37.32),
|
169
|
+
Color::RGB::Cayenne.to_cmyk)
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_to_grayscale
|
173
|
+
assert_kind_of(Color::GrayScale, Color::RGB::Black.to_grayscale)
|
174
|
+
assert_equal(Color::GrayScale.from_fraction(0),
|
175
|
+
Color::RGB::Black.to_grayscale)
|
176
|
+
assert_equal(Color::GrayScale.from_fraction(0.5),
|
177
|
+
Color::RGB::Yellow.to_grayscale)
|
178
|
+
assert_equal(Color::GrayScale.from_fraction(0.5),
|
179
|
+
Color::RGB::Cyan.to_grayscale)
|
180
|
+
assert_equal(Color::GrayScale.from_fraction(0.5),
|
181
|
+
Color::RGB::Magenta.to_grayscale)
|
182
|
+
assert_equal(Color::GrayScale.from_fraction(0.5),
|
183
|
+
Color::RGB::Red.to_grayscale)
|
184
|
+
assert_equal(Color::GrayScale.from_fraction(0.5),
|
185
|
+
Color::RGB::Lime.to_grayscale)
|
186
|
+
assert_equal(Color::GrayScale.from_fraction(0.5),
|
187
|
+
Color::RGB::Blue.to_grayscale)
|
188
|
+
assert_equal(Color::GrayScale.from_fraction(0.2510),
|
189
|
+
Color::RGB::Purple.to_grayscale)
|
190
|
+
assert_equal(Color::GrayScale.new(40.58),
|
191
|
+
Color::RGB::Brown.to_grayscale)
|
192
|
+
assert_equal(Color::GrayScale.new(68.43),
|
193
|
+
Color::RGB::Carnation.to_grayscale)
|
194
|
+
assert_equal(Color::GrayScale.new(27.65),
|
195
|
+
Color::RGB::Cayenne.to_grayscale)
|
196
|
+
end
|
197
|
+
|
198
|
+
def test_to_hsl
|
199
|
+
assert_kind_of(Color::HSL, Color::RGB::Black.to_hsl)
|
200
|
+
assert_equal(Color::HSL.new, Color::RGB::Black.to_hsl)
|
201
|
+
assert_equal(Color::HSL.new(60, 100, 50), Color::RGB::Yellow.to_hsl)
|
202
|
+
assert_equal(Color::HSL.new(180, 100, 50), Color::RGB::Cyan.to_hsl)
|
203
|
+
assert_equal(Color::HSL.new(300, 100, 50), Color::RGB::Magenta.to_hsl)
|
204
|
+
assert_equal(Color::HSL.new(0, 100, 50), Color::RGB::Red.to_hsl)
|
205
|
+
assert_equal(Color::HSL.new(120, 100, 50), Color::RGB::Lime.to_hsl)
|
206
|
+
assert_equal(Color::HSL.new(240, 100, 50), Color::RGB::Blue.to_hsl)
|
207
|
+
assert_equal(Color::HSL.new(300, 100, 25.10),
|
208
|
+
Color::RGB::Purple.to_hsl)
|
209
|
+
assert_equal(Color::HSL.new(0, 59.42, 40.59),
|
210
|
+
Color::RGB::Brown.to_hsl)
|
211
|
+
assert_equal(Color::HSL.new(317.5, 100, 68.43),
|
212
|
+
Color::RGB::Carnation.to_hsl)
|
213
|
+
assert_equal(Color::HSL.new(0, 100, 27.64),
|
214
|
+
Color::RGB::Cayenne.to_hsl)
|
215
|
+
|
216
|
+
assert_equal("hsl(0.00, 0.00%, 0.00%)", Color::RGB::Black.css_hsl)
|
217
|
+
assert_equal("hsl(60.00, 100.00%, 50.00%)",
|
218
|
+
Color::RGB::Yellow.css_hsl)
|
219
|
+
assert_equal("hsl(180.00, 100.00%, 50.00%)", Color::RGB::Cyan.css_hsl)
|
220
|
+
assert_equal("hsl(300.00, 100.00%, 50.00%)",
|
221
|
+
Color::RGB::Magenta.css_hsl)
|
222
|
+
assert_equal("hsl(0.00, 100.00%, 50.00%)", Color::RGB::Red.css_hsl)
|
223
|
+
assert_equal("hsl(120.00, 100.00%, 50.00%)", Color::RGB::Lime.css_hsl)
|
224
|
+
assert_equal("hsl(240.00, 100.00%, 50.00%)", Color::RGB::Blue.css_hsl)
|
225
|
+
assert_equal("hsl(300.00, 100.00%, 25.10%)",
|
226
|
+
Color::RGB::Purple.css_hsl)
|
227
|
+
assert_equal("hsl(0.00, 59.42%, 40.59%)", Color::RGB::Brown.css_hsl)
|
228
|
+
assert_equal("hsl(317.52, 100.00%, 68.43%)",
|
229
|
+
Color::RGB::Carnation.css_hsl)
|
230
|
+
assert_equal("hsl(0.00, 100.00%, 27.65%)", Color::RGB::Cayenne.css_hsl)
|
231
|
+
|
232
|
+
assert_equal("hsla(0.00, 0.00%, 0.00%, 1.00)",
|
233
|
+
Color::RGB::Black.css_hsla)
|
234
|
+
assert_equal("hsla(60.00, 100.00%, 50.00%, 1.00)",
|
235
|
+
Color::RGB::Yellow.css_hsla)
|
236
|
+
assert_equal("hsla(180.00, 100.00%, 50.00%, 1.00)",
|
237
|
+
Color::RGB::Cyan.css_hsla)
|
238
|
+
assert_equal("hsla(300.00, 100.00%, 50.00%, 1.00)",
|
239
|
+
Color::RGB::Magenta.css_hsla)
|
240
|
+
assert_equal("hsla(0.00, 100.00%, 50.00%, 1.00)",
|
241
|
+
Color::RGB::Red.css_hsla)
|
242
|
+
assert_equal("hsla(120.00, 100.00%, 50.00%, 1.00)",
|
243
|
+
Color::RGB::Lime.css_hsla)
|
244
|
+
assert_equal("hsla(240.00, 100.00%, 50.00%, 1.00)",
|
245
|
+
Color::RGB::Blue.css_hsla)
|
246
|
+
assert_equal("hsla(300.00, 100.00%, 25.10%, 1.00)",
|
247
|
+
Color::RGB::Purple.css_hsla)
|
248
|
+
assert_equal("hsla(0.00, 59.42%, 40.59%, 1.00)",
|
249
|
+
Color::RGB::Brown.css_hsla)
|
250
|
+
assert_equal("hsla(317.52, 100.00%, 68.43%, 1.00)",
|
251
|
+
Color::RGB::Carnation.css_hsla)
|
252
|
+
assert_equal("hsla(0.00, 100.00%, 27.65%, 1.00)",
|
253
|
+
Color::RGB::Cayenne.css_hsla)
|
254
|
+
|
255
|
+
# The following tests a bug reported by Jean Krohn on 10 June 2006
|
256
|
+
# where HSL conversion was not quite correct, resulting in a bad
|
257
|
+
# round-trip.
|
258
|
+
assert_equal("#008800", Color::RGB.from_html("#008800").to_hsl.html)
|
259
|
+
assert_not_equal("#002288", Color::RGB.from_html("#008800").to_hsl.html)
|
260
|
+
|
261
|
+
# The following tests a bug reported by Adam Johnson on 29 October
|
262
|
+
# 2007.
|
263
|
+
hsl = Color::HSL.new(262, 67, 42)
|
264
|
+
c = Color::RGB.from_fraction(0.34496, 0.1386, 0.701399).to_hsl
|
265
|
+
assert_in_delta hsl.h, c.h, Color::COLOR_TOLERANCE, "Hue"
|
266
|
+
assert_in_delta hsl.s, c.s, Color::COLOR_TOLERANCE, "Saturation"
|
267
|
+
assert_in_delta hsl.l, c.l, Color::COLOR_TOLERANCE, "Luminance"
|
268
|
+
end
|
269
|
+
|
270
|
+
def test_to_rgb
|
271
|
+
assert_equal(Color::RGB::Black, Color::RGB::Black.to_rgb)
|
272
|
+
end
|
273
|
+
|
274
|
+
def test_to_yiq
|
275
|
+
assert_kind_of(Color::YIQ, Color::RGB::Black.to_yiq)
|
276
|
+
assert_equal(Color::YIQ.new, Color::RGB::Black.to_yiq)
|
277
|
+
assert_equal(Color::YIQ.new(88.6, 32.1, 0), Color::RGB::Yellow.to_yiq)
|
278
|
+
assert_equal(Color::YIQ.new(70.1, 0, 0), Color::RGB::Cyan.to_yiq)
|
279
|
+
assert_equal(Color::YIQ.new(41.3, 27.5, 52.3),
|
280
|
+
Color::RGB::Magenta.to_yiq)
|
281
|
+
assert_equal(Color::YIQ.new(29.9, 59.6, 21.2), Color::RGB::Red.to_yiq)
|
282
|
+
assert_equal(Color::YIQ.new(58.7, 0, 0), Color::RGB::Lime.to_yiq)
|
283
|
+
assert_equal(Color::YIQ.new(11.4, 0, 31.1), Color::RGB::Blue.to_yiq)
|
284
|
+
assert_equal(Color::YIQ.new(20.73, 13.80, 26.25),
|
285
|
+
Color::RGB::Purple.to_yiq)
|
286
|
+
assert_equal(Color::YIQ.new(30.89, 28.75, 10.23),
|
287
|
+
Color::RGB::Brown.to_yiq)
|
288
|
+
assert_equal(Color::YIQ.new(60.84, 23.28, 27.29),
|
289
|
+
Color::RGB::Carnation.to_yiq)
|
290
|
+
assert_equal(Color::YIQ.new(16.53, 32.96, 11.72),
|
291
|
+
Color::RGB::Cayenne.to_yiq)
|
292
|
+
end
|
293
|
+
|
294
|
+
def test_add
|
295
|
+
assert_nothing_raised { Color::RGB::Cyan + Color::RGB::Yellow }
|
296
|
+
white = Color::RGB::Cyan + Color::RGB::Yellow
|
297
|
+
assert_not_nil(white)
|
298
|
+
assert_equal(Color::RGB::White, white)
|
299
|
+
|
300
|
+
c1 = Color::RGB.new(0x80, 0x80, 0x00)
|
301
|
+
c2 = Color::RGB.new(0x45, 0x20, 0xf0)
|
302
|
+
cr = Color::RGB.new(0xc5, 0xa0, 0xf0)
|
303
|
+
|
304
|
+
assert_equal(cr, c1 + c2)
|
305
|
+
end
|
306
|
+
|
307
|
+
def test_subtract
|
308
|
+
black = Color::RGB::LightCoral - Color::RGB::Honeydew
|
309
|
+
assert_equal(Color::RGB::Black, black)
|
310
|
+
|
311
|
+
c1 = Color::RGB.new(0x85, 0x80, 0x00)
|
312
|
+
c2 = Color::RGB.new(0x40, 0x20, 0xf0)
|
313
|
+
cr = Color::RGB.new(0x45, 0x60, 0x00)
|
314
|
+
|
315
|
+
assert_equal(cr, c1 - c2)
|
316
|
+
end
|
317
|
+
|
318
|
+
def test_mean_grayscale
|
319
|
+
c1 = Color::RGB.new(0x85, 0x80, 0x00)
|
320
|
+
c1_max = assert_nothing_raised { c1.max_rgb_as_greyscale }
|
321
|
+
c1_max = c1.max_rgb_as_greyscale
|
322
|
+
c1_result = Color::GrayScale.from_fraction(0x85 / 255.0)
|
323
|
+
|
324
|
+
assert_equal(c1_result, c1_max)
|
325
|
+
end
|
326
|
+
|
327
|
+
def test_from_html
|
328
|
+
assert_equal("RGB [#333333]", Color::RGB.from_html("#333").inspect)
|
329
|
+
assert_equal("RGB [#333333]", Color::RGB.from_html("333").inspect)
|
330
|
+
assert_equal("RGB [#555555]", Color::RGB.from_html("#555555").inspect)
|
331
|
+
assert_equal("RGB [#555555]", Color::RGB.from_html("555555").inspect)
|
332
|
+
assert_raises(ArgumentError) { Color::RGB.from_html("#5555555") }
|
333
|
+
assert_raises(ArgumentError) { Color::RGB.from_html("5555555") }
|
334
|
+
assert_raises(ArgumentError) { Color::RGB.from_html("#55555") }
|
335
|
+
assert_raises(ArgumentError) { Color::RGB.from_html("55555") }
|
336
|
+
end
|
337
|
+
|
338
|
+
def test_inspect
|
339
|
+
assert_equal("RGB [#000000]", Color::RGB::Black.inspect)
|
340
|
+
assert_equal("RGB [#0000ff]", Color::RGB::Blue.inspect)
|
341
|
+
assert_equal("RGB [#00ff00]", Color::RGB::Lime.inspect)
|
342
|
+
assert_equal("RGB [#ff0000]", Color::RGB::Red.inspect)
|
343
|
+
assert_equal("RGB [#ffffff]", Color::RGB::White.inspect)
|
344
|
+
end
|
345
|
+
end
|
346
|
+
end
|