color 1.4.1 → 1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.autotest +5 -0
- data/.coveralls.yml +2 -0
- data/.gemtest +0 -0
- data/.hoerc +2 -0
- data/.minitest.rb +2 -0
- data/.travis.yml +41 -0
- data/Code-of-Conduct.rdoc +41 -0
- data/Contributing.rdoc +62 -0
- data/Gemfile +9 -0
- data/History.rdoc +194 -0
- data/{Licence.txt → Licence.rdoc} +4 -4
- data/Manifest.txt +15 -7
- data/README.rdoc +52 -0
- data/Rakefile +62 -103
- data/lib/color.rb +108 -68
- data/lib/color/cmyk.rb +41 -57
- data/lib/color/css.rb +1 -22
- data/lib/color/grayscale.rb +37 -52
- data/lib/color/hsl.rb +97 -78
- data/lib/color/palette.rb +0 -12
- data/lib/color/palette/adobecolor.rb +0 -12
- data/lib/color/palette/gimp.rb +0 -12
- data/lib/color/palette/monocontrast.rb +26 -42
- data/lib/color/rgb.rb +376 -113
- data/lib/color/rgb/colors.rb +167 -0
- data/lib/color/rgb/contrast.rb +57 -0
- data/lib/color/rgb/metallic.rb +25 -40
- data/lib/color/yiq.rb +13 -35
- data/test/minitest_helper.rb +6 -0
- data/test/test_adobecolor.rb +9 -23
- data/test/test_cmyk.rb +21 -36
- data/test/test_color.rb +10 -17
- data/test/test_css.rb +12 -22
- data/test/test_gimp.rb +8 -22
- data/test/test_grayscale.rb +12 -27
- data/test/test_hsl.rb +23 -39
- data/test/test_monocontrast.rb +13 -25
- data/test/test_rgb.rb +98 -35
- data/test/test_yiq.rb +12 -24
- metadata +279 -124
- data.tar.gz.sig +0 -3
- data/History.txt +0 -93
- data/Install.txt +0 -18
- data/README.txt +0 -32
- data/lib/color/rgb-colors.rb +0 -355
- data/setup.rb +0 -1585
- data/test/test_all.rb +0 -23
- metadata.gz.sig +0 -3
data/test/test_color.rb
CHANGED
@@ -1,23 +1,10 @@
|
|
1
|
-
|
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'
|
1
|
+
# -*- ruby encoding: utf-8 -*-
|
2
|
+
|
16
3
|
require 'color'
|
17
|
-
require '
|
4
|
+
require 'minitest_helper'
|
18
5
|
|
19
6
|
module TestColor
|
20
|
-
class TestColor < Test
|
7
|
+
class TestColor < Minitest::Test
|
21
8
|
def setup
|
22
9
|
Kernel.module_eval do
|
23
10
|
alias old_warn warn
|
@@ -62,6 +49,12 @@ module TestColor
|
|
62
49
|
assert_raises(NameError) { assert(Color::MISSING_VALUE) }
|
63
50
|
end
|
64
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
|
57
|
+
|
65
58
|
def test_normalize
|
66
59
|
(1..10).each do |i|
|
67
60
|
assert_equal(0.0, Color.normalize(-7 * i))
|
data/test/test_css.rb
CHANGED
@@ -1,29 +1,19 @@
|
|
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
1
|
require 'color'
|
17
2
|
require 'color/css'
|
3
|
+
require 'minitest_helper'
|
18
4
|
|
19
5
|
module TestColor
|
20
|
-
class TestCSS < Test
|
21
|
-
def
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
6
|
+
class TestCSS < Minitest::Test
|
7
|
+
def test_index_with_known_name
|
8
|
+
assert_same(Color::RGB::AliceBlue, Color::CSS[:aliceblue])
|
9
|
+
assert_same(Color::RGB::AliceBlue, Color::CSS["AliceBlue"])
|
10
|
+
assert_same(Color::RGB::AliceBlue, Color::CSS["aliceBlue"])
|
11
|
+
assert_same(Color::RGB::AliceBlue, Color::CSS["aliceblue"])
|
12
|
+
assert_same(Color::RGB::AliceBlue, Color::CSS[:AliceBlue])
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_index_with_unknown_name
|
16
|
+
assert_equal(nil, Color::CSS['redx'])
|
27
17
|
end
|
28
18
|
end
|
29
19
|
end
|
data/test/test_gimp.rb
CHANGED
@@ -1,24 +1,12 @@
|
|
1
|
-
|
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
|
-
#++
|
1
|
+
# -*- ruby encoding: utf-8 -*-
|
13
2
|
|
14
|
-
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib") if __FILE__ == $0
|
15
|
-
require 'test/unit'
|
16
3
|
require 'color'
|
17
4
|
require 'color/palette/gimp'
|
5
|
+
require 'minitest_helper'
|
18
6
|
|
19
7
|
module TestColor
|
20
8
|
module TestPalette
|
21
|
-
class TestGimp < Test
|
9
|
+
class TestGimp < Minitest::Test
|
22
10
|
include Color::Palette
|
23
11
|
|
24
12
|
GIMP_W3C = <<-EOS
|
@@ -43,7 +31,7 @@ Columns: 2
|
|
43
31
|
0 128 0 Green
|
44
32
|
0 0 255 Blue
|
45
33
|
0 0 128 Navy
|
46
|
-
0 0 0 Black
|
34
|
+
0 0 0 Black
|
47
35
|
EOS
|
48
36
|
|
49
37
|
def setup
|
@@ -64,7 +52,7 @@ Columns: 2
|
|
64
52
|
def test_each_name
|
65
53
|
@gimp = Gimp.new(GIMP_W3C)
|
66
54
|
assert_equal(16, @gimp.instance_variable_get(:@names).size)
|
67
|
-
|
55
|
+
|
68
56
|
@gimp.each_name { |color_name, color_set|
|
69
57
|
assert_kind_of(Array, color_set)
|
70
58
|
color_set.each { |c|
|
@@ -74,12 +62,10 @@ Columns: 2
|
|
74
62
|
end
|
75
63
|
|
76
64
|
def test_index
|
77
|
-
|
78
|
-
|
79
|
-
f.write GIMP_W3C
|
80
|
-
end
|
65
|
+
File.open(@filename, "wb") do |f|
|
66
|
+
f.write GIMP_W3C
|
81
67
|
end
|
82
|
-
|
68
|
+
@gimp = Gimp.from_file(@filename)
|
83
69
|
assert_equal(Color::RGB::White, @gimp[0])
|
84
70
|
assert_equal(Color::RGB::White, @gimp["White"][0])
|
85
71
|
assert_equal([Color::RGB::White, Color::RGB::Black],
|
data/test/test_grayscale.rb
CHANGED
@@ -1,22 +1,10 @@
|
|
1
|
-
|
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'
|
1
|
+
# -*- ruby encoding: utf-8 -*-
|
2
|
+
|
16
3
|
require 'color'
|
4
|
+
require 'minitest_helper'
|
17
5
|
|
18
6
|
module TestColor
|
19
|
-
class TestGrayScale < Test
|
7
|
+
class TestGrayScale < Minitest::Test
|
20
8
|
def setup
|
21
9
|
@gs = Color::GrayScale.from_percent(33)
|
22
10
|
end
|
@@ -32,11 +20,11 @@ module TestColor
|
|
32
20
|
def test_g
|
33
21
|
assert_in_delta(0.33, @gs.g, Color::COLOR_TOLERANCE)
|
34
22
|
assert_in_delta(33, @gs.grey, Color::COLOR_TOLERANCE)
|
35
|
-
|
23
|
+
@gs.gray = 40
|
36
24
|
assert_in_delta(0.4, @gs.g, Color::COLOR_TOLERANCE)
|
37
|
-
|
25
|
+
@gs.g = 2.0
|
38
26
|
assert_in_delta(100, @gs.gray, Color::COLOR_TOLERANCE)
|
39
|
-
|
27
|
+
@gs.grey = -2.0
|
40
28
|
assert_in_delta(0.0, @gs.g, Color::COLOR_TOLERANCE)
|
41
29
|
end
|
42
30
|
|
@@ -44,6 +32,7 @@ module TestColor
|
|
44
32
|
assert_equal("#545454", @gs.html)
|
45
33
|
assert_equal("rgb(33.00%, 33.00%, 33.00%)", @gs.css_rgb)
|
46
34
|
assert_equal("rgba(33.00%, 33.00%, 33.00%, 1.00)", @gs.css_rgba)
|
35
|
+
assert_equal("rgba(33.00%, 33.00%, 33.00%, 0.20)", @gs.css_rgba(0.2))
|
47
36
|
end
|
48
37
|
|
49
38
|
def test_lighten_by
|
@@ -56,8 +45,7 @@ module TestColor
|
|
56
45
|
end
|
57
46
|
|
58
47
|
def test_to_cmyk
|
59
|
-
cmyk =
|
60
|
-
assert_nothing_raised { cmyk = @gs.to_cmyk }
|
48
|
+
cmyk = @gs.to_cmyk
|
61
49
|
assert_kind_of(Color::CMYK, cmyk)
|
62
50
|
assert_in_delta(0.0, cmyk.c, Color::COLOR_TOLERANCE)
|
63
51
|
assert_in_delta(0.0, cmyk.m, Color::COLOR_TOLERANCE)
|
@@ -71,8 +59,7 @@ module TestColor
|
|
71
59
|
end
|
72
60
|
|
73
61
|
def test_to_hsl
|
74
|
-
hsl =
|
75
|
-
assert_nothing_raised { hsl = @gs.to_hsl }
|
62
|
+
hsl = @gs.to_hsl
|
76
63
|
assert_kind_of(Color::HSL, hsl)
|
77
64
|
assert_in_delta(0.0, hsl.h, Color::COLOR_TOLERANCE)
|
78
65
|
assert_in_delta(0.0, hsl.s, Color::COLOR_TOLERANCE)
|
@@ -82,8 +69,7 @@ module TestColor
|
|
82
69
|
end
|
83
70
|
|
84
71
|
def test_to_rgb
|
85
|
-
rgb =
|
86
|
-
assert_nothing_raised { rgb = @gs.to_rgb }
|
72
|
+
rgb = @gs.to_rgb
|
87
73
|
assert_kind_of(Color::RGB, rgb)
|
88
74
|
assert_in_delta(0.33, rgb.r, Color::COLOR_TOLERANCE)
|
89
75
|
assert_in_delta(0.33, rgb.g, Color::COLOR_TOLERANCE)
|
@@ -91,8 +77,7 @@ module TestColor
|
|
91
77
|
end
|
92
78
|
|
93
79
|
def test_to_yiq
|
94
|
-
yiq =
|
95
|
-
assert_nothing_raised { yiq = @gs.to_yiq }
|
80
|
+
yiq = @gs.to_yiq
|
96
81
|
assert_kind_of(Color::YIQ, yiq)
|
97
82
|
assert_in_delta(0.33, yiq.y, Color::COLOR_TOLERANCE)
|
98
83
|
assert_in_delta(0.0, yiq.i, Color::COLOR_TOLERANCE)
|
data/test/test_hsl.rb
CHANGED
@@ -1,24 +1,10 @@
|
|
1
|
-
|
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
|
-
# HSL Tests provided by Adam Johnson
|
14
|
-
#++
|
15
|
-
|
16
|
-
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib") if __FILE__ == $0
|
17
|
-
require 'test/unit'
|
1
|
+
# -*- ruby encoding: utf-8 -*-
|
2
|
+
|
18
3
|
require 'color'
|
4
|
+
require 'minitest_helper'
|
19
5
|
|
20
6
|
module TestColor
|
21
|
-
class TestHSL < Test
|
7
|
+
class TestHSL < Minitest::Test
|
22
8
|
def setup
|
23
9
|
# @hsl = Color::HSL.new(262, 67, 42)
|
24
10
|
@hsl = Color::HSL.new(145, 20, 30)
|
@@ -40,40 +26,40 @@ module TestColor
|
|
40
26
|
def test_hue
|
41
27
|
assert_in_delta 0.4027, @hsl.h, Color::COLOR_TOLERANCE
|
42
28
|
assert_in_delta 145, @hsl.hue, Color::COLOR_TOLERANCE
|
43
|
-
|
29
|
+
@hsl.hue = 33
|
44
30
|
assert_in_delta 0.09167, @hsl.h, Color::COLOR_TOLERANCE
|
45
|
-
|
31
|
+
@hsl.hue = -33
|
46
32
|
assert_in_delta 0.90833, @hsl.h, Color::COLOR_TOLERANCE
|
47
|
-
|
33
|
+
@hsl.h = 3.3
|
48
34
|
assert_in_delta 360, @hsl.hue, Color::COLOR_TOLERANCE
|
49
|
-
|
35
|
+
@hsl.h = -3.3
|
50
36
|
assert_in_delta 0.0, @hsl.h, Color::COLOR_TOLERANCE
|
51
|
-
|
52
|
-
|
37
|
+
@hsl.hue = 0
|
38
|
+
@hsl.hue -= 20
|
53
39
|
assert_in_delta 340, @hsl.hue, Color::COLOR_TOLERANCE
|
54
|
-
|
40
|
+
@hsl.hue += 45
|
55
41
|
assert_in_delta 25, @hsl.hue, Color::COLOR_TOLERANCE
|
56
42
|
end
|
57
43
|
|
58
44
|
def test_saturation
|
59
45
|
assert_in_delta 0.2, @hsl.s, Color::COLOR_TOLERANCE
|
60
46
|
assert_in_delta 20, @hsl.saturation, Color::COLOR_TOLERANCE
|
61
|
-
|
47
|
+
@hsl.saturation = 33
|
62
48
|
assert_in_delta 0.33, @hsl.s, Color::COLOR_TOLERANCE
|
63
|
-
|
49
|
+
@hsl.s = 3.3
|
64
50
|
assert_in_delta 100, @hsl.saturation, Color::COLOR_TOLERANCE
|
65
|
-
|
51
|
+
@hsl.s = -3.3
|
66
52
|
assert_in_delta 0.0, @hsl.s, Color::COLOR_TOLERANCE
|
67
53
|
end
|
68
54
|
|
69
55
|
def test_luminance
|
70
56
|
assert_in_delta 0.3, @hsl.l, Color::COLOR_TOLERANCE
|
71
57
|
assert_in_delta 30, @hsl.luminosity, Color::COLOR_TOLERANCE
|
72
|
-
|
58
|
+
@hsl.luminosity = 33
|
73
59
|
assert_in_delta 0.33, @hsl.l, Color::COLOR_TOLERANCE
|
74
|
-
|
60
|
+
@hsl.l = 3.3
|
75
61
|
assert_in_delta 100, @hsl.lightness, Color::COLOR_TOLERANCE
|
76
|
-
|
62
|
+
@hsl.l = -3.3
|
77
63
|
assert_in_delta 0.0, @hsl.l, Color::COLOR_TOLERANCE
|
78
64
|
end
|
79
65
|
|
@@ -83,8 +69,7 @@ module TestColor
|
|
83
69
|
end
|
84
70
|
|
85
71
|
def test_to_cmyk
|
86
|
-
cmyk =
|
87
|
-
assert_nothing_raised { cmyk = @hsl.to_cmyk }
|
72
|
+
cmyk = @hsl.to_cmyk
|
88
73
|
assert_kind_of Color::CMYK, cmyk
|
89
74
|
assert_in_delta 0.3223, cmyk.c, Color::COLOR_TOLERANCE
|
90
75
|
assert_in_delta 0.2023, cmyk.m, Color::COLOR_TOLERANCE
|
@@ -93,15 +78,13 @@ module TestColor
|
|
93
78
|
end
|
94
79
|
|
95
80
|
def test_to_grayscale
|
96
|
-
gs =
|
97
|
-
assert_nothing_raised { gs = @hsl.to_grayscale }
|
81
|
+
gs = @hsl.to_grayscale
|
98
82
|
assert_kind_of Color::GreyScale, gs
|
99
83
|
assert_in_delta 30, gs.gray, Color::COLOR_TOLERANCE
|
100
84
|
end
|
101
85
|
|
102
86
|
def test_to_rgb
|
103
|
-
rgb =
|
104
|
-
assert_nothing_raised { rgb = @hsl.to_rgb }
|
87
|
+
rgb = @hsl.to_rgb
|
105
88
|
assert_kind_of Color::RGB, rgb
|
106
89
|
assert_in_delta 0.24, rgb.r, Color::COLOR_TOLERANCE
|
107
90
|
assert_in_delta 0.36, rgb.g, Color::COLOR_TOLERANCE
|
@@ -109,6 +92,8 @@ module TestColor
|
|
109
92
|
assert_equal "#3d5c4a", @hsl.html
|
110
93
|
assert_equal "rgb(24.00%, 36.00%, 29.00%)", @hsl.css_rgb
|
111
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)
|
96
|
+
|
112
97
|
# The following tests address a bug reported by Jean Krohn on June 6,
|
113
98
|
# 2006 and excercise some previously unexercised code in to_rgb.
|
114
99
|
assert_equal Color::RGB::Black, Color::HSL.new(75, 75, 0)
|
@@ -125,8 +110,7 @@ module TestColor
|
|
125
110
|
end
|
126
111
|
|
127
112
|
def test_to_yiq
|
128
|
-
yiq =
|
129
|
-
assert_nothing_raised { yiq = @hsl.to_yiq }
|
113
|
+
yiq = @hsl.to_yiq
|
130
114
|
assert_kind_of Color::YIQ, yiq
|
131
115
|
assert_in_delta 0.3161, yiq.y, Color::COLOR_TOLERANCE
|
132
116
|
assert_in_delta 0.0, yiq.i, Color::COLOR_TOLERANCE
|
data/test/test_monocontrast.rb
CHANGED
@@ -1,24 +1,12 @@
|
|
1
|
-
|
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
|
-
#++
|
1
|
+
# -*- ruby encoding: utf-8 -*-
|
13
2
|
|
14
|
-
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib") if __FILE__ == $0
|
15
|
-
require 'test/unit'
|
16
3
|
require 'color'
|
17
4
|
require 'color/palette/monocontrast'
|
5
|
+
require 'minitest_helper'
|
18
6
|
|
19
7
|
module TestColor
|
20
8
|
module TestPalette
|
21
|
-
class TestMonoContrast < Test
|
9
|
+
class TestMonoContrast < Minitest::Test
|
22
10
|
include Color::Palette
|
23
11
|
def setup
|
24
12
|
@high = Color::RGB.from_html("#c9e3a6")
|
@@ -105,14 +93,14 @@ module TestColor
|
|
105
93
|
assert_in_delta(MonoContrast::DEFAULT_MINIMUM_BRIGHTNESS_DIFF,
|
106
94
|
@mcp1.minimum_brightness_diff, Color::COLOR_TOLERANCE)
|
107
95
|
mcps = @mcp1.dup
|
108
|
-
|
96
|
+
@mcp1.minimum_brightness_diff = 0.75
|
109
97
|
assert_in_delta(0.75, @mcp1.minimum_brightness_diff, Color::COLOR_TOLERANCE)
|
110
|
-
|
111
|
-
|
98
|
+
refute_equal(@mcp1.foreground[-5], mcps.foreground[-5])
|
99
|
+
@mcp1.minimum_brightness_diff = 4.0
|
112
100
|
assert_in_delta(1, @mcp1.minimum_brightness_diff, Color::COLOR_TOLERANCE)
|
113
|
-
|
101
|
+
@mcp1.minimum_brightness_diff = -4.0
|
114
102
|
assert_in_delta(0, @mcp1.minimum_brightness_diff, Color::COLOR_TOLERANCE)
|
115
|
-
|
103
|
+
@mcp1.minimum_brightness_diff = nil
|
116
104
|
assert_in_delta(MonoContrast::DEFAULT_MINIMUM_BRIGHTNESS_DIFF,
|
117
105
|
@mcp1.minimum_brightness_diff, Color::COLOR_TOLERANCE)
|
118
106
|
end
|
@@ -126,14 +114,14 @@ module TestColor
|
|
126
114
|
assert_in_delta(MonoContrast::DEFAULT_MINIMUM_COLOR_DIFF,
|
127
115
|
@mcp1.minimum_color_diff, Color::COLOR_TOLERANCE)
|
128
116
|
mcps = @mcp1.dup
|
129
|
-
|
117
|
+
@mcp1.minimum_color_diff = 0.75
|
130
118
|
assert_in_delta(0.75, @mcp1.minimum_color_diff, Color::COLOR_TOLERANCE)
|
131
|
-
|
132
|
-
|
119
|
+
refute_equal(@mcp1.foreground[-5], mcps.foreground[-5])
|
120
|
+
@mcp1.minimum_color_diff = 4.0
|
133
121
|
assert_in_delta(3, @mcp1.minimum_color_diff, Color::COLOR_TOLERANCE)
|
134
|
-
|
122
|
+
@mcp1.minimum_color_diff = -4.0
|
135
123
|
assert_in_delta(0, @mcp1.minimum_color_diff, Color::COLOR_TOLERANCE)
|
136
|
-
|
124
|
+
@mcp1.minimum_color_diff = nil
|
137
125
|
assert_in_delta(MonoContrast::DEFAULT_MINIMUM_COLOR_DIFF,
|
138
126
|
@mcp1.minimum_color_diff, Color::COLOR_TOLERANCE)
|
139
127
|
end
|
data/test/test_rgb.rb
CHANGED
@@ -1,22 +1,10 @@
|
|
1
|
-
|
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'
|
1
|
+
# -*- ruby encoding: utf-8 -*-
|
2
|
+
|
16
3
|
require 'color'
|
4
|
+
require 'minitest_helper'
|
17
5
|
|
18
6
|
module TestColor
|
19
|
-
class TestRGB < Test
|
7
|
+
class TestRGB < Minitest::Test
|
20
8
|
def test_adjust_brightness
|
21
9
|
assert_equal("#1a1aff", Color::RGB::Blue.adjust_brightness(10).html)
|
22
10
|
assert_equal("#0000e6", Color::RGB::Blue.adjust_brightness(-10).html)
|
@@ -40,11 +28,11 @@ module TestColor
|
|
40
28
|
assert_in_delta(100, red.red_p, Color::COLOR_TOLERANCE)
|
41
29
|
assert_in_delta(255, red.red, Color::COLOR_TOLERANCE)
|
42
30
|
assert_in_delta(1.0, red.r, Color::COLOR_TOLERANCE)
|
43
|
-
|
31
|
+
red.red_p = 33
|
44
32
|
assert_in_delta(0.33, red.r, Color::COLOR_TOLERANCE)
|
45
|
-
|
33
|
+
red.red = 330
|
46
34
|
assert_in_delta(1.0, red.r, Color::COLOR_TOLERANCE)
|
47
|
-
|
35
|
+
red.r = -3.3
|
48
36
|
assert_in_delta(0.0, red.r, Color::COLOR_TOLERANCE)
|
49
37
|
end
|
50
38
|
|
@@ -53,11 +41,11 @@ module TestColor
|
|
53
41
|
assert_in_delta(1.0, lime.g, Color::COLOR_TOLERANCE)
|
54
42
|
assert_in_delta(100, lime.green_p, Color::COLOR_TOLERANCE)
|
55
43
|
assert_in_delta(255, lime.green, Color::COLOR_TOLERANCE)
|
56
|
-
|
44
|
+
lime.green_p = 33
|
57
45
|
assert_in_delta(0.33, lime.g, Color::COLOR_TOLERANCE)
|
58
|
-
|
46
|
+
lime.green = 330
|
59
47
|
assert_in_delta(1.0, lime.g, Color::COLOR_TOLERANCE)
|
60
|
-
|
48
|
+
lime.g = -3.3
|
61
49
|
assert_in_delta(0.0, lime.g, Color::COLOR_TOLERANCE)
|
62
50
|
end
|
63
51
|
|
@@ -66,11 +54,11 @@ module TestColor
|
|
66
54
|
assert_in_delta(1.0, blue.b, Color::COLOR_TOLERANCE)
|
67
55
|
assert_in_delta(255, blue.blue, Color::COLOR_TOLERANCE)
|
68
56
|
assert_in_delta(100, blue.blue_p, Color::COLOR_TOLERANCE)
|
69
|
-
|
57
|
+
blue.blue_p = 33
|
70
58
|
assert_in_delta(0.33, blue.b, Color::COLOR_TOLERANCE)
|
71
|
-
|
59
|
+
blue.blue = 330
|
72
60
|
assert_in_delta(1.0, blue.b, Color::COLOR_TOLERANCE)
|
73
|
-
|
61
|
+
blue.b = -3.3
|
74
62
|
assert_in_delta(0.0, blue.b, Color::COLOR_TOLERANCE)
|
75
63
|
end
|
76
64
|
|
@@ -103,8 +91,8 @@ module TestColor
|
|
103
91
|
assert_equal("rgba(0.00%, 0.00%, 100.00%, 1.00)", Color::RGB::Blue.css_rgba)
|
104
92
|
assert_equal("rgba(0.00%, 100.00%, 0.00%, 1.00)", Color::RGB::Lime.css_rgba)
|
105
93
|
assert_equal("rgba(100.00%, 0.00%, 0.00%, 1.00)", Color::RGB::Red.css_rgba)
|
106
|
-
assert_equal("rgba(100.00%, 100.00%, 100.00%, 1.00)",
|
107
|
-
|
94
|
+
assert_equal("rgba(100.00%, 100.00%, 100.00%, 1.00)", Color::RGB::White.css_rgba)
|
95
|
+
assert_equal("rgba(100.00%, 0.00%, 0.00%, 0.50)", Color::RGB::Red.css_rgba(0.5))
|
108
96
|
end
|
109
97
|
|
110
98
|
def test_lighten_by
|
@@ -254,7 +242,7 @@ module TestColor
|
|
254
242
|
# where HSL conversion was not quite correct, resulting in a bad
|
255
243
|
# round-trip.
|
256
244
|
assert_equal("#008800", Color::RGB.from_html("#008800").to_hsl.html)
|
257
|
-
|
245
|
+
refute_equal("#002288", Color::RGB.from_html("#008800").to_hsl.html)
|
258
246
|
|
259
247
|
# The following tests a bug reported by Adam Johnson on 29 October
|
260
248
|
# 2010.
|
@@ -266,7 +254,7 @@ module TestColor
|
|
266
254
|
end
|
267
255
|
|
268
256
|
def test_to_rgb
|
269
|
-
|
257
|
+
assert_same(Color::RGB::Black, Color::RGB::Black.to_rgb)
|
270
258
|
end
|
271
259
|
|
272
260
|
def test_to_yiq
|
@@ -289,11 +277,51 @@ module TestColor
|
|
289
277
|
Color::RGB::Cayenne.to_yiq)
|
290
278
|
end
|
291
279
|
|
280
|
+
def test_to_lab
|
281
|
+
# Luminosity can be an absolute.
|
282
|
+
assert_in_delta(0.0, Color::RGB::Black.to_lab[:L], Color::COLOR_TOLERANCE)
|
283
|
+
assert_in_delta(100.0, Color::RGB::White.to_lab[:L], Color::COLOR_TOLERANCE)
|
284
|
+
|
285
|
+
# It's not really possible to have absolute
|
286
|
+
# numbers here because of how L*a*b* works, but
|
287
|
+
# negative/positive comparisons work
|
288
|
+
assert(Color::RGB::Green.to_lab[:a] < 0)
|
289
|
+
assert(Color::RGB::Magenta.to_lab[:a] > 0)
|
290
|
+
assert(Color::RGB::Blue.to_lab[:b] < 0)
|
291
|
+
assert(Color::RGB::Yellow.to_lab[:b] > 0)
|
292
|
+
end
|
293
|
+
|
294
|
+
def test_closest_match
|
295
|
+
# It should match Blue to Indigo (very simple match)
|
296
|
+
match_from = [Color::RGB::Red, Color::RGB::Green, Color::RGB::Blue]
|
297
|
+
assert_equal(Color::RGB::Blue, Color::RGB::Indigo.closest_match(match_from))
|
298
|
+
# But fails if using the :just_noticeable difference.
|
299
|
+
assert_nil(Color::RGB::Indigo.closest_match(match_from, :just_noticeable))
|
300
|
+
|
301
|
+
# Crimson & Firebrick are visually closer than DarkRed and Firebrick
|
302
|
+
# (more precise match)
|
303
|
+
match_from += [Color::RGB::DarkRed, Color::RGB::Crimson]
|
304
|
+
assert_equal(Color::RGB::Crimson,
|
305
|
+
Color::RGB::Firebrick.closest_match(match_from))
|
306
|
+
# Specifying a threshold low enough will cause even that match to
|
307
|
+
# fail, though.
|
308
|
+
assert_nil(Color::RGB::Firebrick.closest_match(match_from, 8.0))
|
309
|
+
# If the match_from list is an empty array, it also returns nil
|
310
|
+
assert_nil(Color::RGB::Red.closest_match([]))
|
311
|
+
|
312
|
+
# RGB::Green is 0,128,0, so we'll pick something VERY close to it, visually
|
313
|
+
jnd_green = Color::RGB.new(3, 132, 3)
|
314
|
+
assert_equal(Color::RGB::Green,
|
315
|
+
jnd_green.closest_match(match_from, :jnd))
|
316
|
+
# And then something that's just barely out of the tolerance range
|
317
|
+
diff_green = Color::RGB.new(9, 142, 9)
|
318
|
+
assert_nil(diff_green.closest_match(match_from, :jnd))
|
319
|
+
end
|
320
|
+
|
292
321
|
def test_add
|
293
|
-
|
294
|
-
white
|
295
|
-
|
296
|
-
assert_equal(Color::RGB::White, white)
|
322
|
+
white = Color::RGB::Cyan + Color::RGB::Yellow
|
323
|
+
refute_nil(white)
|
324
|
+
assert_equal(Color::RGB::White, white)
|
297
325
|
|
298
326
|
c1 = Color::RGB.new(0x80, 0x80, 0x00)
|
299
327
|
c2 = Color::RGB.new(0x45, 0x20, 0xf0)
|
@@ -304,7 +332,7 @@ module TestColor
|
|
304
332
|
|
305
333
|
def test_subtract
|
306
334
|
black = Color::RGB::LightCoral - Color::RGB::Honeydew
|
307
|
-
assert_equal(Color::RGB::Black, black)
|
335
|
+
assert_equal(Color::RGB::Black, black)
|
308
336
|
|
309
337
|
c1 = Color::RGB.new(0x85, 0x80, 0x00)
|
310
338
|
c2 = Color::RGB.new(0x40, 0x20, 0xf0)
|
@@ -315,7 +343,7 @@ module TestColor
|
|
315
343
|
|
316
344
|
def test_mean_grayscale
|
317
345
|
c1 = Color::RGB.new(0x85, 0x80, 0x00)
|
318
|
-
c1_max =
|
346
|
+
c1_max = c1.max_rgb_as_greyscale
|
319
347
|
c1_max = c1.max_rgb_as_greyscale
|
320
348
|
c1_result = Color::GrayScale.from_fraction(0x85 / 255.0)
|
321
349
|
|
@@ -333,6 +361,41 @@ module TestColor
|
|
333
361
|
assert_raises(ArgumentError) { Color::RGB.from_html("55555") }
|
334
362
|
end
|
335
363
|
|
364
|
+
def test_by_hex
|
365
|
+
assert_same(Color::RGB::Cyan, Color::RGB.by_hex('#0ff'))
|
366
|
+
assert_same(Color::RGB::Cyan, Color::RGB.by_hex('#00ffff'))
|
367
|
+
assert_equal("RGB [#333333]", Color::RGB.by_hex("#333").inspect)
|
368
|
+
assert_equal("RGB [#333333]", Color::RGB.by_hex("333").inspect)
|
369
|
+
assert_raises(ArgumentError) { Color::RGB.by_hex("5555555") }
|
370
|
+
assert_raises(ArgumentError) { Color::RGB.by_hex("#55555") }
|
371
|
+
assert_equal(:boom, Color::RGB.by_hex('#55555') { :boom })
|
372
|
+
end
|
373
|
+
|
374
|
+
def test_by_name
|
375
|
+
assert_same(Color::RGB::Cyan, Color::RGB.by_name('cyan'))
|
376
|
+
|
377
|
+
fetch_error = if RUBY_VERSION < "1.9"
|
378
|
+
IndexError
|
379
|
+
else
|
380
|
+
KeyError
|
381
|
+
end
|
382
|
+
|
383
|
+
assert_raises(fetch_error) { Color::RGB.by_name('cyanide') }
|
384
|
+
assert_equal(:boom, Color::RGB.by_name('cyanide') { :boom })
|
385
|
+
end
|
386
|
+
|
387
|
+
def test_by_css
|
388
|
+
assert_same(Color::RGB::Cyan, Color::RGB.by_css('#0ff'))
|
389
|
+
assert_same(Color::RGB::Cyan, Color::RGB.by_css('cyan'))
|
390
|
+
assert_raises(ArgumentError) { Color::RGB.by_css('cyanide') }
|
391
|
+
assert_equal(:boom, Color::RGB.by_css('cyanide') { :boom })
|
392
|
+
end
|
393
|
+
|
394
|
+
def test_extract_colors
|
395
|
+
assert_equal([ Color::RGB::BlanchedAlmond, Color::RGB::Cyan ],
|
396
|
+
Color::RGB.extract_colors('BlanchedAlmond is a nice shade, but #00ffff is not.'))
|
397
|
+
end
|
398
|
+
|
336
399
|
def test_inspect
|
337
400
|
assert_equal("RGB [#000000]", Color::RGB::Black.inspect)
|
338
401
|
assert_equal("RGB [#0000ff]", Color::RGB::Blue.inspect)
|