timocratic-color 1.4.1.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.
- 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
data/test/test_color.rb
ADDED
@@ -0,0 +1,134 @@
|
|
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/css'
|
20
|
+
|
21
|
+
module TestColor
|
22
|
+
class TestColor < Test::Unit::TestCase
|
23
|
+
def setup
|
24
|
+
Kernel.module_eval do
|
25
|
+
alias old_warn warn
|
26
|
+
|
27
|
+
def warn(message)
|
28
|
+
$last_warn = message
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def teardown
|
34
|
+
Kernel.module_eval do
|
35
|
+
undef warn
|
36
|
+
alias warn old_warn
|
37
|
+
undef old_warn
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_const
|
42
|
+
$last_warn = nil
|
43
|
+
assert_equal(Color::RGB::AliceBlue, Color::AliceBlue)
|
44
|
+
assert_equal("Color::AliceBlue has been deprecated. Use Color::RGB::AliceBlue instead.", $last_warn)
|
45
|
+
|
46
|
+
$last_warn = nil # Do this twice to make sure it always happens...
|
47
|
+
assert(Color::AliceBlue)
|
48
|
+
assert_equal("Color::AliceBlue has been deprecated. Use Color::RGB::AliceBlue instead.", $last_warn)
|
49
|
+
|
50
|
+
$last_warn = nil
|
51
|
+
assert_equal(Color::COLOR_VERSION, Color::VERSION)
|
52
|
+
assert_equal("Color::VERSION has been deprecated. Use Color::COLOR_VERSION instead.", $last_warn)
|
53
|
+
|
54
|
+
$last_warn = nil
|
55
|
+
assert_equal(Color::COLOR_VERSION, Color::COLOR_TOOLS_VERSION)
|
56
|
+
assert_equal("Color::COLOR_TOOLS_VERSION has been deprecated. Use Color::COLOR_VERSION instead.", $last_warn)
|
57
|
+
|
58
|
+
$last_warn = nil
|
59
|
+
assert(Color::COLOR_VERSION)
|
60
|
+
assert_nil($last_warn)
|
61
|
+
assert(Color::COLOR_EPSILON)
|
62
|
+
assert_nil($last_warn)
|
63
|
+
|
64
|
+
assert_raises(NameError) { assert(Color::MISSING_VALUE) }
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_normalize
|
68
|
+
(1..10).each do |i|
|
69
|
+
assert_equal(0.0, Color.normalize(-7 * i))
|
70
|
+
assert_equal(0.0, Color.normalize(-7 / i))
|
71
|
+
assert_equal(0.0, Color.normalize(0 - i))
|
72
|
+
assert_equal(1.0, Color.normalize(255 + i))
|
73
|
+
assert_equal(1.0, Color.normalize(256 * i))
|
74
|
+
assert_equal(1.0, Color.normalize(65536 / i))
|
75
|
+
end
|
76
|
+
(0..255).each do |i|
|
77
|
+
assert_in_delta(i / 255.0, Color.normalize(i / 255.0),
|
78
|
+
1e-2)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_normalize_range
|
83
|
+
assert_equal(0, Color.normalize_8bit(-1))
|
84
|
+
assert_equal(0, Color.normalize_8bit(0))
|
85
|
+
assert_equal(127, Color.normalize_8bit(127))
|
86
|
+
assert_equal(172, Color.normalize_8bit(172))
|
87
|
+
assert_equal(255, Color.normalize_8bit(255))
|
88
|
+
assert_equal(255, Color.normalize_8bit(256))
|
89
|
+
|
90
|
+
assert_equal(-100, Color.normalize_to_range(-101, -100..100))
|
91
|
+
assert_equal(-100, Color.normalize_to_range(-100.5, -100..100))
|
92
|
+
assert_equal(-100, Color.normalize_to_range(-100, -100..100))
|
93
|
+
assert_equal(-100, Color.normalize_to_range(-100.0, -100..100))
|
94
|
+
assert_equal(-99.5, Color.normalize_to_range(-99.5, -100..100))
|
95
|
+
assert_equal(-50, Color.normalize_to_range(-50, -100..100))
|
96
|
+
assert_equal(-50.5, Color.normalize_to_range(-50.5, -100..100))
|
97
|
+
assert_equal(0, Color.normalize_to_range(0, -100..100))
|
98
|
+
assert_equal(50, Color.normalize_to_range(50, -100..100))
|
99
|
+
assert_equal(50.5, Color.normalize_to_range(50.5, -100..100))
|
100
|
+
assert_equal(99, Color.normalize_to_range(99, -100..100))
|
101
|
+
assert_equal(99.5, Color.normalize_to_range(99.5, -100..100))
|
102
|
+
assert_equal(100, Color.normalize_to_range(100, -100..100))
|
103
|
+
assert_equal(100, Color.normalize_to_range(100.0, -100..100))
|
104
|
+
assert_equal(100, Color.normalize_to_range(100.5, -100..100))
|
105
|
+
assert_equal(100, Color.normalize_to_range(101, -100..100))
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_new
|
109
|
+
$last_warn = nil
|
110
|
+
c = Color.new("#fff")
|
111
|
+
assert_kind_of(Color::HSL, c)
|
112
|
+
assert_equal(Color::RGB::White.to_hsl, c)
|
113
|
+
assert_equal("Color.new has been deprecated. Use Color::RGB.new instead.", $last_warn)
|
114
|
+
|
115
|
+
$last_warn = nil
|
116
|
+
c = Color.new([0, 0, 0])
|
117
|
+
assert_kind_of(Color::HSL, c)
|
118
|
+
assert_equal(Color::RGB::Black.to_hsl, c)
|
119
|
+
assert_equal("Color.new has been deprecated. Use Color::RGB.new instead.", $last_warn)
|
120
|
+
|
121
|
+
$last_warn = nil
|
122
|
+
c = Color.new([10, 20, 30], :hsl)
|
123
|
+
assert_kind_of(Color::HSL, c)
|
124
|
+
assert_equal(Color::HSL.new(10, 20, 30), c)
|
125
|
+
assert_equal("Color.new has been deprecated. Use Color::HSL.new instead.", $last_warn)
|
126
|
+
|
127
|
+
$last_warn = nil
|
128
|
+
c = Color.new([10, 20, 30, 40], :cmyk)
|
129
|
+
assert_kind_of(Color::HSL, c)
|
130
|
+
assert_equal(Color::CMYK.new(10, 20, 30, 40).to_hsl, c)
|
131
|
+
assert_equal("Color.new has been deprecated. Use Color::CMYK.new instead.", $last_warn)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
data/test/test_css.rb
ADDED
@@ -0,0 +1,31 @@
|
|
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/css'
|
20
|
+
|
21
|
+
module TestColor
|
22
|
+
class TestCSS < Test::Unit::TestCase
|
23
|
+
def test_index
|
24
|
+
assert_equal(Color::RGB::AliceBlue, Color::CSS[:aliceblue])
|
25
|
+
assert_equal(Color::RGB::AliceBlue, Color::CSS["AliceBlue"])
|
26
|
+
assert_equal(Color::RGB::AliceBlue, Color::CSS["aliceBlue"])
|
27
|
+
assert_equal(Color::RGB::AliceBlue, Color::CSS["aliceblue"])
|
28
|
+
assert_equal(Color::RGB::AliceBlue, Color::CSS[:AliceBlue])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/test/test_gimp.rb
ADDED
@@ -0,0 +1,103 @@
|
|
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/gimp'
|
20
|
+
|
21
|
+
module TestColor
|
22
|
+
module TestPalette
|
23
|
+
class TestGimp < Test::Unit::TestCase
|
24
|
+
include Color::Palette
|
25
|
+
|
26
|
+
GIMP_W3C = <<-EOS
|
27
|
+
GIMP Palette
|
28
|
+
Name: W3C Named Colors
|
29
|
+
Columns: 2
|
30
|
+
#
|
31
|
+
# ColorZilla W3C Named Colors
|
32
|
+
#
|
33
|
+
255 255 255 White
|
34
|
+
255 255 0 Yclow
|
35
|
+
255 0 255 Fuchsia
|
36
|
+
255 0 0 Red
|
37
|
+
192 192 192 Silver
|
38
|
+
128 128 128 Gray
|
39
|
+
128 128 0 Olive
|
40
|
+
128 0 128 Purple
|
41
|
+
128 0 0 Maroon
|
42
|
+
0 255 255 Aqua
|
43
|
+
0 255 0 Lime
|
44
|
+
0 128 128 Teal
|
45
|
+
0 128 0 Green
|
46
|
+
0 0 255 Blue
|
47
|
+
0 0 128 Navy
|
48
|
+
0 0 0 Black
|
49
|
+
EOS
|
50
|
+
|
51
|
+
def setup
|
52
|
+
@filename = "test#{Process.pid}.gimp"
|
53
|
+
end
|
54
|
+
|
55
|
+
def teardown
|
56
|
+
require 'fileutils'
|
57
|
+
FileUtils.rm_f @filename if File.exist? @filename
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_each
|
61
|
+
@gimp = Gimp.new(GIMP_W3C)
|
62
|
+
assert_equal(16, @gimp.instance_variable_get(:@colors).size)
|
63
|
+
@gimp.each { |c| assert_kind_of(Color::RGB, c) }
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_each_name
|
67
|
+
@gimp = Gimp.new(GIMP_W3C)
|
68
|
+
assert_equal(16, @gimp.instance_variable_get(:@names).size)
|
69
|
+
|
70
|
+
@gimp.each_name { |color_name, color_set|
|
71
|
+
assert_kind_of(Array, color_set)
|
72
|
+
color_set.each { |c|
|
73
|
+
assert_kind_of(Color::RGB, c)
|
74
|
+
}
|
75
|
+
}
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_index
|
79
|
+
assert_nothing_raised do
|
80
|
+
File.open(@filename, "wb") do |f|
|
81
|
+
f.write GIMP_W3C
|
82
|
+
end
|
83
|
+
end
|
84
|
+
assert_nothing_raised { @gimp = Gimp.from_file(@filename) }
|
85
|
+
assert_equal(Color::RGB::White, @gimp[0])
|
86
|
+
assert_equal(Color::RGB::White, @gimp["White"][0])
|
87
|
+
assert_equal([Color::RGB::White, Color::RGB::Black],
|
88
|
+
@gimp.values_at(0, -1))
|
89
|
+
assert_equal(16, @gimp.size)
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_valid_eh
|
93
|
+
@gimp = Gimp.new(GIMP_W3C)
|
94
|
+
assert(@gimp.valid?)
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_name
|
98
|
+
@gimp = Gimp.new(GIMP_W3C)
|
99
|
+
assert_equal("W3C Named Colors", @gimp.name)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,123 @@
|
|
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 TestGrayScale < Test::Unit::TestCase
|
22
|
+
def setup
|
23
|
+
@gs = Color::GrayScale.from_percent(33)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_brightness
|
27
|
+
assert_in_delta(0.33, @gs.brightness, Color::COLOR_TOLERANCE)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_darken_by
|
31
|
+
assert_in_delta(29.7, @gs.darken_by(10).gray, Color::COLOR_TOLERANCE)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_g
|
35
|
+
assert_in_delta(0.33, @gs.g, Color::COLOR_TOLERANCE)
|
36
|
+
assert_in_delta(33, @gs.grey, Color::COLOR_TOLERANCE)
|
37
|
+
assert_nothing_raised { @gs.gray = 40 }
|
38
|
+
assert_in_delta(0.4, @gs.g, Color::COLOR_TOLERANCE)
|
39
|
+
assert_nothing_raised { @gs.g = 2.0 }
|
40
|
+
assert_in_delta(100, @gs.gray, Color::COLOR_TOLERANCE)
|
41
|
+
assert_nothing_raised { @gs.grey = -2.0 }
|
42
|
+
assert_in_delta(0.0, @gs.g, Color::COLOR_TOLERANCE)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_html_css
|
46
|
+
assert_equal("#545454", @gs.html)
|
47
|
+
assert_equal("rgb(33.00%, 33.00%, 33.00%)", @gs.css_rgb)
|
48
|
+
assert_equal("rgba(33.00%, 33.00%, 33.00%, 1.00)", @gs.css_rgba)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_lighten_by
|
52
|
+
assert_in_delta(0.363, @gs.lighten_by(10).g, Color::COLOR_TOLERANCE)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_pdf_fill
|
56
|
+
assert_equal("0.330 g", @gs.pdf_fill)
|
57
|
+
assert_equal("0.330 G", @gs.pdf_stroke)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_to_cmyk
|
61
|
+
cmyk = nil
|
62
|
+
assert_nothing_raised { cmyk = @gs.to_cmyk }
|
63
|
+
assert_kind_of(Color::CMYK, cmyk)
|
64
|
+
assert_in_delta(0.0, cmyk.c, Color::COLOR_TOLERANCE)
|
65
|
+
assert_in_delta(0.0, cmyk.m, Color::COLOR_TOLERANCE)
|
66
|
+
assert_in_delta(0.0, cmyk.y, Color::COLOR_TOLERANCE)
|
67
|
+
assert_in_delta(0.67, cmyk.k, Color::COLOR_TOLERANCE)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_to_grayscale
|
71
|
+
assert_equal(@gs, @gs.to_grayscale)
|
72
|
+
assert_equal(@gs, @gs.to_greyscale)
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_to_hsl
|
76
|
+
hsl = nil
|
77
|
+
assert_nothing_raised { hsl = @gs.to_hsl }
|
78
|
+
assert_kind_of(Color::HSL, hsl)
|
79
|
+
assert_in_delta(0.0, hsl.h, Color::COLOR_TOLERANCE)
|
80
|
+
assert_in_delta(0.0, hsl.s, Color::COLOR_TOLERANCE)
|
81
|
+
assert_in_delta(0.33, hsl.l, Color::COLOR_TOLERANCE)
|
82
|
+
assert_equal("hsl(0.00, 0.00%, 33.00%)", @gs.css_hsl)
|
83
|
+
assert_equal("hsla(0.00, 0.00%, 33.00%, 1.00)", @gs.css_hsla)
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_to_rgb
|
87
|
+
rgb = nil
|
88
|
+
assert_nothing_raised { rgb = @gs.to_rgb }
|
89
|
+
assert_kind_of(Color::RGB, rgb)
|
90
|
+
assert_in_delta(0.33, rgb.r, Color::COLOR_TOLERANCE)
|
91
|
+
assert_in_delta(0.33, rgb.g, Color::COLOR_TOLERANCE)
|
92
|
+
assert_in_delta(0.33, rgb.b, Color::COLOR_TOLERANCE)
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_to_yiq
|
96
|
+
yiq = nil
|
97
|
+
assert_nothing_raised { yiq = @gs.to_yiq }
|
98
|
+
assert_kind_of(Color::YIQ, yiq)
|
99
|
+
assert_in_delta(0.33, yiq.y, Color::COLOR_TOLERANCE)
|
100
|
+
assert_in_delta(0.0, yiq.i, Color::COLOR_TOLERANCE)
|
101
|
+
assert_in_delta(0.0, yiq.q, Color::COLOR_TOLERANCE)
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_add
|
105
|
+
delta = @gs + Color::GrayScale.new(20)
|
106
|
+
max = @gs + Color::GrayScale.new(80)
|
107
|
+
|
108
|
+
assert_in_delta(1.0, max.g, Color::COLOR_TOLERANCE)
|
109
|
+
assert_in_delta(0.53, delta.g, Color::COLOR_TOLERANCE)
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_subtract
|
113
|
+
delta = @gs - Color::GrayScale.new(20)
|
114
|
+
max = @gs - Color::GrayScale.new(80)
|
115
|
+
assert_in_delta(0.0, max.g, Color::COLOR_TOLERANCE)
|
116
|
+
assert_in_delta(0.13, delta.g, Color::COLOR_TOLERANCE)
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_inspect
|
120
|
+
assert_equal("Gray [33.00%]", @gs.inspect)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
data/test/test_hsl.rb
ADDED
@@ -0,0 +1,155 @@
|
|
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
|
+
# HSL Tests provided by Adam Johnson
|
14
|
+
#
|
15
|
+
# $Id: test_all.rb 55 2007-02-03 23:29:34Z austin $
|
16
|
+
#++
|
17
|
+
|
18
|
+
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib") if __FILE__ == $0
|
19
|
+
require 'test/unit'
|
20
|
+
require 'color'
|
21
|
+
|
22
|
+
module TestColor
|
23
|
+
class TestHSL < Test::Unit::TestCase
|
24
|
+
def setup
|
25
|
+
# @hsl = Color::HSL.new(262, 67, 42)
|
26
|
+
@hsl = Color::HSL.new(145, 20, 30)
|
27
|
+
# @rgb = Color::RGB.new(88, 35, 179)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_rgb_roundtrip_conversion
|
31
|
+
hsl = Color::HSL.new(262, 67, 42)
|
32
|
+
c = hsl.to_rgb.to_hsl
|
33
|
+
assert_in_delta hsl.h, c.h, Color::COLOR_TOLERANCE, "Hue"
|
34
|
+
assert_in_delta hsl.s, c.s, Color::COLOR_TOLERANCE, "Saturation"
|
35
|
+
assert_in_delta hsl.l, c.l, Color::COLOR_TOLERANCE, "Luminance"
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_brightness
|
39
|
+
assert_in_delta 0.3, @hsl.brightness, Color::COLOR_TOLERANCE
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_hue
|
43
|
+
assert_in_delta 0.4027, @hsl.h, Color::COLOR_TOLERANCE
|
44
|
+
assert_in_delta 145, @hsl.hue, Color::COLOR_TOLERANCE
|
45
|
+
assert_nothing_raised { @hsl.hue = 33 }
|
46
|
+
assert_in_delta 0.09167, @hsl.h, Color::COLOR_TOLERANCE
|
47
|
+
assert_nothing_raised { @hsl.hue = -33 }
|
48
|
+
assert_in_delta 0.90833, @hsl.h, Color::COLOR_TOLERANCE
|
49
|
+
assert_nothing_raised { @hsl.h = 3.3 }
|
50
|
+
assert_in_delta 360, @hsl.hue, Color::COLOR_TOLERANCE
|
51
|
+
assert_nothing_raised { @hsl.h = -3.3 }
|
52
|
+
assert_in_delta 0.0, @hsl.h, Color::COLOR_TOLERANCE
|
53
|
+
assert_nothing_raised { @hsl.hue = 0 }
|
54
|
+
assert_nothing_raised { @hsl.hue -= 20 }
|
55
|
+
assert_in_delta 340, @hsl.hue, Color::COLOR_TOLERANCE
|
56
|
+
assert_nothing_raised { @hsl.hue += 45 }
|
57
|
+
assert_in_delta 25, @hsl.hue, Color::COLOR_TOLERANCE
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_saturation
|
61
|
+
assert_in_delta 0.2, @hsl.s, Color::COLOR_TOLERANCE
|
62
|
+
assert_in_delta 20, @hsl.saturation, Color::COLOR_TOLERANCE
|
63
|
+
assert_nothing_raised { @hsl.saturation = 33 }
|
64
|
+
assert_in_delta 0.33, @hsl.s, Color::COLOR_TOLERANCE
|
65
|
+
assert_nothing_raised { @hsl.s = 3.3 }
|
66
|
+
assert_in_delta 100, @hsl.saturation, Color::COLOR_TOLERANCE
|
67
|
+
assert_nothing_raised { @hsl.s = -3.3 }
|
68
|
+
assert_in_delta 0.0, @hsl.s, Color::COLOR_TOLERANCE
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_luminance
|
72
|
+
assert_in_delta 0.3, @hsl.l, Color::COLOR_TOLERANCE
|
73
|
+
assert_in_delta 30, @hsl.luminosity, Color::COLOR_TOLERANCE
|
74
|
+
assert_nothing_raised { @hsl.luminosity = 33 }
|
75
|
+
assert_in_delta 0.33, @hsl.l, Color::COLOR_TOLERANCE
|
76
|
+
assert_nothing_raised { @hsl.l = 3.3 }
|
77
|
+
assert_in_delta 100, @hsl.lightness, Color::COLOR_TOLERANCE
|
78
|
+
assert_nothing_raised { @hsl.l = -3.3 }
|
79
|
+
assert_in_delta 0.0, @hsl.l, Color::COLOR_TOLERANCE
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_html_css
|
83
|
+
assert_equal "hsl(145.00, 20.00%, 30.00%)", @hsl.css_hsl
|
84
|
+
assert_equal "hsla(145.00, 20.00%, 30.00%, 1.00)", @hsl.css_hsla
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_to_cmyk
|
88
|
+
cmyk = nil
|
89
|
+
assert_nothing_raised { cmyk = @hsl.to_cmyk }
|
90
|
+
assert_kind_of Color::CMYK, cmyk
|
91
|
+
assert_in_delta 0.3223, cmyk.c, Color::COLOR_TOLERANCE
|
92
|
+
assert_in_delta 0.2023, cmyk.m, Color::COLOR_TOLERANCE
|
93
|
+
assert_in_delta 0.2723, cmyk.y, Color::COLOR_TOLERANCE
|
94
|
+
assert_in_delta 0.4377, cmyk.k, Color::COLOR_TOLERANCE
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_to_grayscale
|
98
|
+
gs = nil
|
99
|
+
assert_nothing_raised { gs = @hsl.to_grayscale }
|
100
|
+
assert_kind_of Color::GreyScale, gs
|
101
|
+
assert_in_delta 30, gs.gray, Color::COLOR_TOLERANCE
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_to_rgb
|
105
|
+
rgb = nil
|
106
|
+
assert_nothing_raised { rgb = @hsl.to_rgb }
|
107
|
+
assert_kind_of Color::RGB, rgb
|
108
|
+
assert_in_delta 0.24, rgb.r, Color::COLOR_TOLERANCE
|
109
|
+
assert_in_delta 0.36, rgb.g, Color::COLOR_TOLERANCE
|
110
|
+
assert_in_delta 0.29, rgb.b, Color::COLOR_TOLERANCE
|
111
|
+
assert_equal "#3d5c4a", @hsl.html
|
112
|
+
assert_equal "rgb(24.00%, 36.00%, 29.00%)", @hsl.css_rgb
|
113
|
+
assert_equal "rgba(24.00%, 36.00%, 29.00%, 1.00)", @hsl.css_rgba
|
114
|
+
# The following tests address a bug reported by Jean Krohn on June 6,
|
115
|
+
# 2006 and excercise some previously unexercised code in to_rgb.
|
116
|
+
assert_equal Color::RGB::Black, Color::HSL.new(75, 75, 0)
|
117
|
+
assert_equal Color::RGB::White, Color::HSL.new(75, 75, 100)
|
118
|
+
assert_equal Color::RGB::Gray80, Color::HSL.new(75, 0, 80)
|
119
|
+
|
120
|
+
# The following tests a bug reported by Adam Johnson on 29 October
|
121
|
+
# 2007.
|
122
|
+
rgb = Color::RGB.from_fraction(0.34496, 0.1386, 0.701399)
|
123
|
+
c = Color::HSL.new(262, 67, 42).to_rgb
|
124
|
+
assert_in_delta rgb.r, c.r, Color::COLOR_TOLERANCE, "Red"
|
125
|
+
assert_in_delta rgb.g, c.g, Color::COLOR_TOLERANCE, "Green"
|
126
|
+
assert_in_delta rgb.b, c.b, Color::COLOR_TOLERANCE, "Blue"
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_to_yiq
|
130
|
+
yiq = nil
|
131
|
+
assert_nothing_raised { yiq = @hsl.to_yiq }
|
132
|
+
assert_kind_of Color::YIQ, yiq
|
133
|
+
assert_in_delta 0.3161, yiq.y, Color::COLOR_TOLERANCE
|
134
|
+
assert_in_delta 0.0, yiq.i, Color::COLOR_TOLERANCE
|
135
|
+
assert_in_delta 0.0, yiq.q, Color::COLOR_TOLERANCE
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_mix_with
|
139
|
+
red = Color::RGB::Red.to_hsl
|
140
|
+
yellow = Color::RGB::Yellow.to_hsl
|
141
|
+
assert_in_delta 0, red.hue, Color::COLOR_TOLERANCE
|
142
|
+
assert_in_delta 60, yellow.hue, Color::COLOR_TOLERANCE
|
143
|
+
ry25 = red.mix_with yellow, 0.25
|
144
|
+
assert_in_delta 15, ry25.hue, Color::COLOR_TOLERANCE
|
145
|
+
ry50 = red.mix_with yellow, 0.50
|
146
|
+
assert_in_delta 30, ry50.hue, Color::COLOR_TOLERANCE
|
147
|
+
ry75 = red.mix_with yellow, 0.75
|
148
|
+
assert_in_delta 45, ry75.hue, Color::COLOR_TOLERANCE
|
149
|
+
end
|
150
|
+
|
151
|
+
def test_inspect
|
152
|
+
assert_equal "HSL [145.00 deg, 20.00%, 30.00%]", @hsl.inspect
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|