color 1.8 → 2.0.0.pre.1
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.
- checksums.yaml +5 -5
- data/CHANGELOG.md +301 -0
- data/CODE_OF_CONDUCT.md +128 -0
- data/CONTRIBUTING.md +70 -0
- data/CONTRIBUTORS.md +10 -0
- data/LICENCE.md +27 -0
- data/Manifest.txt +11 -23
- data/README.md +54 -0
- data/Rakefile +74 -61
- data/SECURITY.md +34 -0
- data/lib/color/cielab.rb +348 -0
- data/lib/color/cmyk.rb +279 -213
- data/lib/color/grayscale.rb +128 -160
- data/lib/color/hsl.rb +205 -173
- data/lib/color/rgb/colors.rb +177 -163
- data/lib/color/rgb.rb +536 -541
- data/lib/color/version.rb +5 -0
- data/lib/color/xyz.rb +214 -0
- data/lib/color/yiq.rb +91 -46
- data/lib/color.rb +208 -142
- data/test/fixtures/cielab.json +444 -0
- data/test/minitest_helper.rb +20 -4
- data/test/test_cmyk.rb +49 -72
- data/test/test_color.rb +58 -112
- data/test/test_grayscale.rb +35 -57
- data/test/test_hsl.rb +71 -77
- data/test/test_rgb.rb +195 -267
- data/test/test_yiq.rb +12 -30
- metadata +90 -107
- data/.autotest +0 -5
- data/.coveralls.yml +0 -2
- data/.gemtest +0 -0
- data/.hoerc +0 -2
- data/.minitest.rb +0 -2
- data/.travis.yml +0 -41
- data/Code-of-Conduct.rdoc +0 -41
- data/Contributing.rdoc +0 -62
- data/Gemfile +0 -9
- data/History.rdoc +0 -194
- data/Licence.rdoc +0 -27
- data/README.rdoc +0 -52
- data/lib/color/css.rb +0 -7
- data/lib/color/palette/adobecolor.rb +0 -260
- data/lib/color/palette/gimp.rb +0 -104
- data/lib/color/palette/monocontrast.rb +0 -164
- data/lib/color/palette.rb +0 -4
- data/lib/color/rgb/contrast.rb +0 -57
- data/lib/color/rgb/metallic.rb +0 -28
- data/test/test_adobecolor.rb +0 -405
- data/test/test_css.rb +0 -19
- data/test/test_gimp.rb +0 -87
- data/test/test_monocontrast.rb +0 -130
data/test/test_color.rb
CHANGED
@@ -1,134 +1,80 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "color"
|
4
|
+
require "minitest_helper"
|
5
5
|
|
6
6
|
module TestColor
|
7
7
|
class TestColor < Minitest::Test
|
8
8
|
def setup
|
9
|
-
|
10
|
-
alias old_warn warn
|
11
|
-
|
12
|
-
def warn(message)
|
13
|
-
$last_warn = message
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def teardown
|
19
|
-
Kernel.module_eval do
|
20
|
-
undef warn
|
21
|
-
alias warn old_warn
|
22
|
-
undef old_warn
|
23
|
-
end
|
9
|
+
@subject = Object.new.extend(Color)
|
24
10
|
end
|
25
11
|
|
26
|
-
def
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
$last_warn = nil # Do this twice to make sure it always happens...
|
32
|
-
assert(Color::AliceBlue)
|
33
|
-
assert_equal("Color::AliceBlue has been deprecated. Use Color::RGB::AliceBlue instead.", $last_warn)
|
34
|
-
|
35
|
-
$last_warn = nil
|
36
|
-
assert_equal(Color::COLOR_VERSION, Color::VERSION)
|
37
|
-
assert_equal("Color::VERSION has been deprecated. Use Color::COLOR_VERSION instead.", $last_warn)
|
38
|
-
|
39
|
-
$last_warn = nil
|
40
|
-
assert_equal(Color::COLOR_VERSION, Color::COLOR_TOOLS_VERSION)
|
41
|
-
assert_equal("Color::COLOR_TOOLS_VERSION has been deprecated. Use Color::COLOR_VERSION instead.", $last_warn)
|
42
|
-
|
43
|
-
$last_warn = nil
|
44
|
-
assert(Color::COLOR_VERSION)
|
45
|
-
assert_nil($last_warn)
|
46
|
-
assert(Color::COLOR_EPSILON)
|
47
|
-
assert_nil($last_warn)
|
48
|
-
|
49
|
-
assert_raises(NameError) { assert(Color::MISSING_VALUE) }
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_equivalent
|
53
|
-
assert Color.equivalent?(Color::RGB::Red, Color::HSL.new(0, 100, 50))
|
54
|
-
refute Color.equivalent?(Color::RGB::Red, nil)
|
55
|
-
refute Color.equivalent?(nil, Color::RGB::Red)
|
56
|
-
end
|
12
|
+
# def test_equivalent
|
13
|
+
# assert Color.equivalent?(Color::RGB::Red, Color::HSL.from_values(0, 100, 50))
|
14
|
+
# refute Color.equivalent?(Color::RGB::Red, nil)
|
15
|
+
# refute Color.equivalent?(nil, Color::RGB::Red)
|
16
|
+
# end
|
57
17
|
|
58
18
|
def test_normalize
|
19
|
+
normalize = @subject.method(:normalize)
|
20
|
+
|
59
21
|
(1..10).each do |i|
|
60
|
-
assert_equal(0.0,
|
61
|
-
assert_equal(0.0,
|
62
|
-
assert_equal(0.0,
|
63
|
-
assert_equal(1.0,
|
64
|
-
assert_equal(1.0,
|
65
|
-
assert_equal(1.0,
|
22
|
+
assert_equal(0.0, normalize.call(-7 * i))
|
23
|
+
assert_equal(0.0, normalize.call(-7 / i))
|
24
|
+
assert_equal(0.0, normalize.call(0 - i))
|
25
|
+
assert_equal(1.0, normalize.call(255 + i))
|
26
|
+
assert_equal(1.0, normalize.call(256 * i))
|
27
|
+
assert_equal(1.0, normalize.call(65536 / i))
|
66
28
|
end
|
29
|
+
|
67
30
|
(0..255).each do |i|
|
68
|
-
assert_in_delta(i / 255.0,
|
69
|
-
1e-2)
|
31
|
+
assert_in_delta(i / 255.0, normalize.call(i / 255.0), 1e-2)
|
70
32
|
end
|
71
33
|
end
|
72
34
|
|
73
|
-
def
|
74
|
-
|
75
|
-
assert_equal(0, Color.normalize_8bit(0))
|
76
|
-
assert_equal(127, Color.normalize_8bit(127))
|
77
|
-
assert_equal(172, Color.normalize_8bit(172))
|
78
|
-
assert_equal(255, Color.normalize_8bit(255))
|
79
|
-
assert_equal(255, Color.normalize_8bit(256))
|
80
|
-
|
81
|
-
assert_equal(0, Color.normalize_16bit(-1))
|
82
|
-
assert_equal(0, Color.normalize_16bit(0))
|
83
|
-
assert_equal(127, Color.normalize_16bit(127))
|
84
|
-
assert_equal(172, Color.normalize_16bit(172))
|
85
|
-
assert_equal(255, Color.normalize_16bit(255))
|
86
|
-
assert_equal(256, Color.normalize_16bit(256))
|
87
|
-
assert_equal(65535, Color.normalize_16bit(65535))
|
88
|
-
assert_equal(65535, Color.normalize_16bit(66536))
|
35
|
+
def test_normalize_byte
|
36
|
+
normalize_byte = @subject.method(:normalize_byte)
|
89
37
|
|
90
|
-
assert_equal(
|
91
|
-
assert_equal(
|
92
|
-
assert_equal(
|
93
|
-
assert_equal(
|
94
|
-
assert_equal(
|
95
|
-
assert_equal(
|
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))
|
38
|
+
assert_equal(0, normalize_byte.call(-1))
|
39
|
+
assert_equal(0, normalize_byte.call(0))
|
40
|
+
assert_equal(127, normalize_byte.call(127))
|
41
|
+
assert_equal(172, normalize_byte.call(172))
|
42
|
+
assert_equal(255, normalize_byte.call(255))
|
43
|
+
assert_equal(255, normalize_byte.call(256))
|
106
44
|
end
|
107
45
|
|
108
|
-
def
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
assert_equal(
|
113
|
-
assert_equal(
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
assert_equal(
|
119
|
-
|
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)
|
46
|
+
def test_normalize_word
|
47
|
+
normalize_word = @subject.method(:normalize_word)
|
48
|
+
|
49
|
+
assert_equal(0, normalize_word.call(-1))
|
50
|
+
assert_equal(0, normalize_word.call(0))
|
51
|
+
assert_equal(127, normalize_word.call(127))
|
52
|
+
assert_equal(172, normalize_word.call(172))
|
53
|
+
assert_equal(255, normalize_word.call(255))
|
54
|
+
assert_equal(256, normalize_word.call(256))
|
55
|
+
assert_equal(65535, normalize_word.call(65535))
|
56
|
+
assert_equal(65535, normalize_word.call(66536))
|
57
|
+
end
|
126
58
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
assert_equal(
|
131
|
-
assert_equal(
|
59
|
+
def test_normalize_range
|
60
|
+
normalize_to_range = @subject.method(:normalize_to_range)
|
61
|
+
|
62
|
+
assert_equal(-100, normalize_to_range.call(-101, -100..100))
|
63
|
+
assert_equal(-100, normalize_to_range.call(-100.5, -100..100))
|
64
|
+
assert_equal(-100, normalize_to_range.call(-100, -100..100))
|
65
|
+
assert_equal(-100, normalize_to_range.call(-100.0, -100..100))
|
66
|
+
assert_equal(-99.5, normalize_to_range.call(-99.5, -100..100))
|
67
|
+
assert_equal(-50, normalize_to_range.call(-50, -100..100))
|
68
|
+
assert_equal(-50.5, normalize_to_range.call(-50.5, -100..100))
|
69
|
+
assert_equal(0, normalize_to_range.call(0, -100..100))
|
70
|
+
assert_equal(50, normalize_to_range.call(50, -100..100))
|
71
|
+
assert_equal(50.5, normalize_to_range.call(50.5, -100..100))
|
72
|
+
assert_equal(99, normalize_to_range.call(99, -100..100))
|
73
|
+
assert_equal(99.5, normalize_to_range.call(99.5, -100..100))
|
74
|
+
assert_equal(100, normalize_to_range.call(100, -100..100))
|
75
|
+
assert_equal(100, normalize_to_range.call(100.0, -100..100))
|
76
|
+
assert_equal(100, normalize_to_range.call(100.5, -100..100))
|
77
|
+
assert_equal(100, normalize_to_range.call(101, -100..100))
|
132
78
|
end
|
133
79
|
end
|
134
80
|
end
|
data/test/test_grayscale.rb
CHANGED
@@ -1,106 +1,84 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "color"
|
4
|
+
require "minitest_helper"
|
5
5
|
|
6
6
|
module TestColor
|
7
|
-
class
|
7
|
+
class TestGrayscale < Minitest::Test
|
8
8
|
def setup
|
9
|
-
@gs = Color::
|
9
|
+
@gs = Color::Grayscale.from_percentage(33)
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_brightness
|
13
|
-
|
13
|
+
assert_in_tolerance(0.33, @gs.brightness)
|
14
14
|
end
|
15
15
|
|
16
16
|
def test_darken_by
|
17
|
-
|
17
|
+
assert_in_tolerance(29.7, @gs.darken_by(10).gray)
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_g
|
21
|
-
|
22
|
-
|
23
|
-
@gs.gray = 40
|
24
|
-
|
25
|
-
@gs.g = 2.0
|
26
|
-
|
27
|
-
@gs.
|
28
|
-
|
21
|
+
assert_in_tolerance(0.33, @gs.g)
|
22
|
+
assert_in_tolerance(33, @gs.gray)
|
23
|
+
# @gs.gray = 40
|
24
|
+
# assert_in_tolerance(0.4, @gs.g)
|
25
|
+
# @gs.g = 2.0
|
26
|
+
# assert_in_tolerance(100, @gs.gray)
|
27
|
+
# @gs.gray = -2.0
|
28
|
+
# assert_in_tolerance(0.0, @gs.g)
|
29
29
|
end
|
30
30
|
|
31
|
-
def
|
31
|
+
def test_css
|
32
32
|
assert_equal("#545454", @gs.html)
|
33
|
-
assert_equal("rgb(33.00
|
34
|
-
assert_equal("
|
35
|
-
assert_equal("
|
33
|
+
assert_equal("rgb(33.00% 33.00% 33.00%)", @gs.css)
|
34
|
+
assert_equal("rgb(33.00% 33.00% 33.00% / 1.00)", @gs.css(alpha: 1))
|
35
|
+
assert_equal("rgb(33.00% 33.00% 33.00% / 0.20)", @gs.css(alpha: 0.2))
|
36
36
|
end
|
37
37
|
|
38
38
|
def test_lighten_by
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_pdf_fill
|
43
|
-
assert_equal("0.330 g", @gs.pdf_fill)
|
44
|
-
assert_equal("0.330 G", @gs.pdf_stroke)
|
39
|
+
assert_in_tolerance(0.363, @gs.lighten_by(10).g)
|
45
40
|
end
|
46
41
|
|
47
42
|
def test_to_cmyk
|
48
43
|
cmyk = @gs.to_cmyk
|
49
44
|
assert_kind_of(Color::CMYK, cmyk)
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
45
|
+
assert_in_tolerance(0.0, cmyk.c)
|
46
|
+
assert_in_tolerance(0.0, cmyk.m)
|
47
|
+
assert_in_tolerance(0.0, cmyk.y)
|
48
|
+
assert_in_tolerance(0.67, cmyk.k)
|
54
49
|
end
|
55
50
|
|
56
51
|
def test_to_grayscale
|
57
52
|
assert_equal(@gs, @gs.to_grayscale)
|
58
|
-
assert_equal(@gs, @gs.
|
53
|
+
assert_equal(@gs, @gs.to_grayscale)
|
59
54
|
end
|
60
55
|
|
61
56
|
def test_to_hsl
|
62
57
|
hsl = @gs.to_hsl
|
63
58
|
assert_kind_of(Color::HSL, hsl)
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
assert_equal("hsl(0.00, 0.00%, 33.00%)", @gs.css_hsl)
|
68
|
-
assert_equal("hsla(0.00, 0.00%, 33.00%, 1.00)", @gs.css_hsla)
|
59
|
+
assert_in_tolerance(0.0, hsl.h)
|
60
|
+
assert_in_tolerance(0.0, hsl.s)
|
61
|
+
assert_in_tolerance(0.33, hsl.l)
|
69
62
|
end
|
70
63
|
|
71
64
|
def test_to_rgb
|
72
65
|
rgb = @gs.to_rgb
|
73
66
|
assert_kind_of(Color::RGB, rgb)
|
74
|
-
|
75
|
-
|
76
|
-
|
67
|
+
assert_in_tolerance(0.33, rgb.r)
|
68
|
+
assert_in_tolerance(0.33, rgb.g)
|
69
|
+
assert_in_tolerance(0.33, rgb.b)
|
77
70
|
end
|
78
71
|
|
79
72
|
def test_to_yiq
|
80
73
|
yiq = @gs.to_yiq
|
81
74
|
assert_kind_of(Color::YIQ, yiq)
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_add
|
88
|
-
delta = @gs + Color::GrayScale.new(20)
|
89
|
-
max = @gs + Color::GrayScale.new(80)
|
90
|
-
|
91
|
-
assert_in_delta(1.0, max.g, Color::COLOR_TOLERANCE)
|
92
|
-
assert_in_delta(0.53, delta.g, Color::COLOR_TOLERANCE)
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_subtract
|
96
|
-
delta = @gs - Color::GrayScale.new(20)
|
97
|
-
max = @gs - Color::GrayScale.new(80)
|
98
|
-
assert_in_delta(0.0, max.g, Color::COLOR_TOLERANCE)
|
99
|
-
assert_in_delta(0.13, delta.g, Color::COLOR_TOLERANCE)
|
75
|
+
assert_in_tolerance(0.33, yiq.y)
|
76
|
+
assert_in_tolerance(0.0, yiq.i)
|
77
|
+
assert_in_tolerance(0.0, yiq.q)
|
100
78
|
end
|
101
79
|
|
102
80
|
def test_inspect
|
103
|
-
assert_equal("
|
81
|
+
assert_equal("Grayscale [33.00%]", @gs.inspect)
|
104
82
|
end
|
105
83
|
end
|
106
84
|
end
|
data/test/test_hsl.rb
CHANGED
@@ -1,137 +1,131 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "color"
|
4
|
+
require "minitest_helper"
|
5
5
|
|
6
6
|
module TestColor
|
7
7
|
class TestHSL < Minitest::Test
|
8
8
|
def setup
|
9
|
-
|
10
|
-
@hsl = Color::HSL.new(145, 20, 30)
|
11
|
-
# @rgb = Color::RGB.new(88, 35, 179)
|
9
|
+
@hsl = Color::HSL.from_values(145, 20, 30)
|
12
10
|
end
|
13
11
|
|
14
12
|
def test_rgb_roundtrip_conversion
|
15
|
-
hsl = Color::HSL.
|
13
|
+
hsl = Color::HSL.from_values(262, 67, 42)
|
16
14
|
c = hsl.to_rgb.to_hsl
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
assert_in_tolerance hsl.h, c.h, "Hue"
|
16
|
+
assert_in_tolerance hsl.s, c.s, "Saturation"
|
17
|
+
assert_in_tolerance hsl.l, c.l, "Luminance"
|
20
18
|
end
|
21
19
|
|
22
20
|
def test_brightness
|
23
|
-
|
21
|
+
assert_in_tolerance 0.3, @hsl.brightness
|
24
22
|
end
|
25
23
|
|
26
24
|
def test_hue
|
27
|
-
|
28
|
-
|
29
|
-
@hsl.hue = 33
|
30
|
-
|
31
|
-
@hsl.hue = -33
|
32
|
-
|
33
|
-
@hsl.h = 3.3
|
34
|
-
|
35
|
-
@hsl.h = -3.3
|
36
|
-
|
37
|
-
@hsl.hue = 0
|
38
|
-
@hsl.hue -= 20
|
39
|
-
|
40
|
-
@hsl.hue += 45
|
41
|
-
|
25
|
+
assert_in_tolerance 0.4027, @hsl.h
|
26
|
+
assert_in_tolerance 145, @hsl.hue
|
27
|
+
# @hsl.hue = 33
|
28
|
+
# assert_in_tolerance 0.09167, @hsl.h
|
29
|
+
# @hsl.hue = -33
|
30
|
+
# assert_in_tolerance 0.90833, @hsl.h
|
31
|
+
# @hsl.h = 3.3
|
32
|
+
# assert_in_tolerance 360, @hsl.hue
|
33
|
+
# @hsl.h = -3.3
|
34
|
+
# assert_in_tolerance 0.0, @hsl.h
|
35
|
+
# @hsl.hue = 0
|
36
|
+
# @hsl.hue -= 20
|
37
|
+
# assert_in_tolerance 340, @hsl.hue
|
38
|
+
# @hsl.hue += 45
|
39
|
+
# assert_in_tolerance 25, @hsl.hue
|
42
40
|
end
|
43
41
|
|
44
42
|
def test_saturation
|
45
|
-
|
46
|
-
|
47
|
-
@hsl.saturation = 33
|
48
|
-
|
49
|
-
@hsl.s = 3.3
|
50
|
-
|
51
|
-
@hsl.s = -3.3
|
52
|
-
|
43
|
+
assert_in_tolerance 0.2, @hsl.s
|
44
|
+
assert_in_tolerance 20, @hsl.saturation
|
45
|
+
# @hsl.saturation = 33
|
46
|
+
# assert_in_tolerance 0.33, @hsl.s
|
47
|
+
# @hsl.s = 3.3
|
48
|
+
# assert_in_tolerance 100, @hsl.saturation
|
49
|
+
# @hsl.s = -3.3
|
50
|
+
# assert_in_tolerance 0.0, @hsl.s
|
53
51
|
end
|
54
52
|
|
55
53
|
def test_luminance
|
56
|
-
|
57
|
-
|
58
|
-
@hsl.luminosity = 33
|
59
|
-
|
60
|
-
@hsl.l = 3.3
|
61
|
-
|
62
|
-
@hsl.l = -3.3
|
63
|
-
|
54
|
+
assert_in_tolerance 0.3, @hsl.l
|
55
|
+
assert_in_tolerance 30, @hsl.luminosity
|
56
|
+
# @hsl.luminosity = 33
|
57
|
+
# assert_in_tolerance 0.33, @hsl.l
|
58
|
+
# @hsl.l = 3.3
|
59
|
+
# assert_in_tolerance 100, @hsl.lightness
|
60
|
+
# @hsl.l = -3.3
|
61
|
+
# assert_in_tolerance 0.0, @hsl.l
|
64
62
|
end
|
65
63
|
|
66
|
-
def
|
67
|
-
assert_equal "hsl(145.
|
68
|
-
assert_equal "
|
64
|
+
def test_css
|
65
|
+
assert_equal "hsl(145.00deg 20.00% 30.00%)", @hsl.css
|
66
|
+
assert_equal "hsl(145.00deg 20.00% 30.00% / 1.00)", @hsl.css(alpha: 1)
|
69
67
|
end
|
70
68
|
|
71
69
|
def test_to_cmyk
|
72
70
|
cmyk = @hsl.to_cmyk
|
73
71
|
assert_kind_of Color::CMYK, cmyk
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
72
|
+
assert_in_tolerance 0.3223, cmyk.c
|
73
|
+
assert_in_tolerance 0.2023, cmyk.m
|
74
|
+
assert_in_tolerance 0.2723, cmyk.y
|
75
|
+
assert_in_tolerance 0.4377, cmyk.k
|
78
76
|
end
|
79
77
|
|
80
78
|
def test_to_grayscale
|
81
79
|
gs = @hsl.to_grayscale
|
82
|
-
assert_kind_of Color::
|
83
|
-
|
80
|
+
assert_kind_of Color::Grayscale, gs
|
81
|
+
assert_in_tolerance 30, gs.gray
|
84
82
|
end
|
85
83
|
|
86
84
|
def test_to_rgb
|
87
85
|
rgb = @hsl.to_rgb
|
88
86
|
assert_kind_of Color::RGB, rgb
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
assert_equal "#3d5c4a", @hsl.html
|
93
|
-
assert_equal "rgb(24.00%, 36.00%, 29.00%)", @hsl.css_rgb
|
94
|
-
assert_equal "rgba(24.00%, 36.00%, 29.00%, 1.00)", @hsl.css_rgba
|
95
|
-
assert_equal "rgba(24.00%, 36.00%, 29.00%, 0.20)", @hsl.css_rgba(0.2)
|
87
|
+
assert_in_tolerance 0.24, rgb.r
|
88
|
+
assert_in_tolerance 0.36, rgb.g
|
89
|
+
assert_in_tolerance 0.29, rgb.b
|
96
90
|
|
97
91
|
# The following tests address a bug reported by Jean Krohn on June 6,
|
98
|
-
# 2006 and
|
99
|
-
assert_equal Color::RGB::Black, Color::HSL.
|
100
|
-
assert_equal Color::RGB::White, Color::HSL.
|
101
|
-
assert_equal Color::RGB::Gray80, Color::HSL.
|
92
|
+
# 2006 and exercise some previously unexercised code in to_rgb.
|
93
|
+
assert_equal Color::RGB::Black, Color::HSL.from_values(75, 75, 0)
|
94
|
+
assert_equal Color::RGB::White, Color::HSL.from_values(75, 75, 100)
|
95
|
+
assert_equal Color::RGB::Gray80, Color::HSL.from_values(75, 0, 80)
|
102
96
|
|
103
97
|
# The following tests a bug reported by Adam Johnson on 29 October
|
104
98
|
# 2010.
|
105
99
|
rgb = Color::RGB.from_fraction(0.34496, 0.1386, 0.701399)
|
106
|
-
c = Color::HSL.
|
107
|
-
|
108
|
-
|
109
|
-
|
100
|
+
c = Color::HSL.from_values(262, 67, 42).to_rgb
|
101
|
+
assert_in_tolerance rgb.r, c.r, "Red"
|
102
|
+
assert_in_tolerance rgb.g, c.g, "Green"
|
103
|
+
assert_in_tolerance rgb.b, c.b, "Blue"
|
110
104
|
end
|
111
105
|
|
112
106
|
def test_to_yiq
|
113
107
|
yiq = @hsl.to_yiq
|
114
108
|
assert_kind_of Color::YIQ, yiq
|
115
|
-
|
116
|
-
|
117
|
-
|
109
|
+
assert_in_tolerance 0.3161, yiq.y
|
110
|
+
assert_in_tolerance 0.0, yiq.i
|
111
|
+
assert_in_tolerance 0.0, yiq.q
|
118
112
|
end
|
119
113
|
|
120
114
|
def test_mix_with
|
121
|
-
red
|
122
|
-
yellow
|
123
|
-
|
124
|
-
|
115
|
+
red = Color::RGB::Red.to_hsl
|
116
|
+
yellow = Color::RGB::Yellow.to_hsl
|
117
|
+
assert_in_tolerance 0, red.hue
|
118
|
+
assert_in_tolerance 60, yellow.hue
|
125
119
|
ry25 = red.mix_with yellow, 0.25
|
126
|
-
|
120
|
+
assert_in_tolerance 15, ry25.hue
|
127
121
|
ry50 = red.mix_with yellow, 0.50
|
128
|
-
|
122
|
+
assert_in_tolerance 30, ry50.hue
|
129
123
|
ry75 = red.mix_with yellow, 0.75
|
130
|
-
|
124
|
+
assert_in_tolerance 45, ry75.hue
|
131
125
|
end
|
132
126
|
|
133
127
|
def test_inspect
|
134
|
-
assert_equal "HSL [145.
|
128
|
+
assert_equal "HSL [145.00deg 20.00% 30.00%]", @hsl.inspect
|
135
129
|
end
|
136
130
|
end
|
137
131
|
end
|