ripta-color-tools 1.4.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.
@@ -0,0 +1,116 @@
1
+ #!/usr/bin/env ruby
2
+ #--
3
+ # Colour management with Ruby.
4
+ #
5
+ # Copyright 2005 Austin Ziegler
6
+ # http://rubyforge.org/ruby-pdf/
7
+ #
8
+ # Licensed under a MIT-style licence.
9
+ #
10
+ # $Id$
11
+ #++
12
+
13
+ $LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib") if __FILE__ == $0
14
+ require 'test/unit' unless defined? $ZENTEST and $ZENTEST
15
+ require 'color'
16
+
17
+ module TestColor
18
+ class TestCMYK < Test::Unit::TestCase
19
+ def setup
20
+ @cmyk = Color::CMYK.new(10, 20, 30, 40)
21
+ end
22
+
23
+ def test_c
24
+ assert_in_delta(0.1, @cmyk.c, 1e-4)
25
+ end
26
+
27
+ def test_c_equals
28
+ assert_in_delta(0.1, @cmyk.c, 1e-4)
29
+ assert_nothing_raised { @cmyk.c = 0.2 }
30
+ assert_in_delta(0.2, @cmyk.c, 1e-4)
31
+ assert_nothing_raised { @cmyk.c = 2.0 }
32
+ assert_in_delta(1.0, @cmyk.c, 1e-4)
33
+ assert_nothing_raised { @cmyk.c = -1.0 }
34
+ assert_in_delta(0.0, @cmyk.c, 1e-4)
35
+ end
36
+
37
+ def test_html
38
+ assert(@cmyk.html =~ /^#[0-9a-fA-F]{6}/)
39
+ end
40
+
41
+ def test_k
42
+ assert_in_delta(0.4, @cmyk.k, 1e-4)
43
+ end
44
+
45
+ def test_k_equals
46
+ assert_in_delta(0.4, @cmyk.k, 1e-4)
47
+ assert_nothing_raised { @cmyk.k = 0.2 }
48
+ assert_in_delta(0.2, @cmyk.k, 1e-4)
49
+ assert_nothing_raised { @cmyk.k = 2.0 }
50
+ assert_in_delta(1.0, @cmyk.k, 1e-4)
51
+ assert_nothing_raised { @cmyk.k = -1.0 }
52
+ assert_in_delta(0.0, @cmyk.k, 1e-4)
53
+ end
54
+
55
+ def test_m
56
+ assert_in_delta(0.2, @cmyk.m, 1e-4)
57
+ end
58
+
59
+ def test_m_equals
60
+ assert_in_delta(0.2, @cmyk.m, 1e-4)
61
+ assert_nothing_raised { @cmyk.m = 0.3 }
62
+ assert_in_delta(0.3, @cmyk.m, 1e-4)
63
+ assert_nothing_raised { @cmyk.m = 2.0 }
64
+ assert_in_delta(1.0, @cmyk.m, 1e-4)
65
+ assert_nothing_raised { @cmyk.m = -1.0 }
66
+ assert_in_delta(0.0, @cmyk.m, 1e-4)
67
+ end
68
+
69
+ def test_pdf_fill
70
+ assert_equal("0.100 0.200 0.300 0.400 k", @cmyk.pdf_fill)
71
+ end
72
+
73
+ def test_pdf_stroke
74
+ assert_equal("0.100 0.200 0.300 0.400 K", @cmyk.pdf_stroke)
75
+ end
76
+
77
+ def test_to_cmyk
78
+ assert(@cmyk.to_cmyk == @cmyk)
79
+ end
80
+
81
+ def test_to_grayscale
82
+ assert_kind_of(Color::GrayScale, @cmyk.to_grayscale)
83
+ end
84
+
85
+ def test_to_greyscale
86
+ assert_kind_of(Color::GreyScale, @cmyk.to_grayscale)
87
+ end
88
+
89
+ def test_to_hsl
90
+ assert_kind_of(Color::HSL, @cmyk.to_hsl)
91
+ end
92
+
93
+ def test_to_rgb
94
+ assert_kind_of(Color::RGB, @cmyk.to_rgb(true))
95
+ assert_kind_of(Color::RGB, @cmyk.to_rgb)
96
+ end
97
+
98
+ def test_to_yiq
99
+ assert_kind_of(Color::YIQ, @cmyk.to_yiq)
100
+ end
101
+
102
+ def test_y
103
+ assert_in_delta(0.3, @cmyk.y, 1e-4)
104
+ end
105
+
106
+ def test_y_equals
107
+ assert_in_delta(0.3, @cmyk.y, 1e-4)
108
+ assert_nothing_raised { @cmyk.y = 0.2 }
109
+ assert_in_delta(0.2, @cmyk.y, 1e-4)
110
+ assert_nothing_raised { @cmyk.y = 2.0 }
111
+ assert_in_delta(1.0, @cmyk.y, 1e-4)
112
+ assert_nothing_raised { @cmyk.y = -1.0 }
113
+ assert_in_delta(0.0, @cmyk.y, 1e-4)
114
+ end
115
+ end
116
+ end
data/tests/test_css.rb ADDED
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+ #--
3
+ # Colour management with Ruby.
4
+ #
5
+ # Copyright 2005 Austin Ziegler
6
+ # http://rubyforge.org/ruby-pdf/
7
+ #
8
+ # Licensed under a MIT-style licence.
9
+ #
10
+ # $Id$
11
+ #++
12
+
13
+ $LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib") if __FILE__ == $0
14
+ require 'test/unit' unless defined? $ZENTEST and $ZENTEST
15
+ require 'color'
16
+ require 'color/css'
17
+
18
+ module TestColor
19
+ class TestCSS < Test::Unit::TestCase
20
+ def test_index
21
+ assert_equal(Color::RGB::AliceBlue, Color::CSS[:aliceblue])
22
+ assert_equal(Color::RGB::AliceBlue, Color::CSS["AliceBlue"])
23
+ assert_equal(Color::RGB::AliceBlue, Color::CSS["aliceBlue"])
24
+ assert_equal(Color::RGB::AliceBlue, Color::CSS["aliceblue"])
25
+ assert_equal(Color::RGB::AliceBlue, Color::CSS[:AliceBlue])
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/env ruby
2
+ #--
3
+ # Colour management with Ruby.
4
+ #
5
+ # Copyright 2005 Austin Ziegler
6
+ # http://rubyforge.org/ruby-pdf/
7
+ #
8
+ # Licensed under a MIT-style licence.
9
+ #
10
+ # $Id$
11
+ #++
12
+
13
+ $LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib") if __FILE__ == $0
14
+ require 'test/unit' unless defined? $ZENTEST and $ZENTEST
15
+ require 'color'
16
+ require 'color/palette/gimp'
17
+
18
+ module TestColor
19
+ module TestPalette
20
+ class TestGimp < Test::Unit::TestCase
21
+ def setup
22
+ wsc = <<-EOS
23
+ GIMP Palette
24
+ Name: W3C Named Colors
25
+ Columns: 2
26
+ #
27
+ # ColorZilla W3C Named Colors
28
+ #
29
+ 255 255 255 White
30
+ 255 255 0 Yellow
31
+ 255 0 255 Fuchsia
32
+ 255 0 0 Red
33
+ 192 192 192 Silver
34
+ 128 128 128 Gray
35
+ 128 128 0 Olive
36
+ 128 0 128 Purple
37
+ 128 0 0 Maroon
38
+ 0 255 255 Aqua
39
+ 0 255 0 Lime
40
+ 0 128 128 Teal
41
+ 0 128 0 Green
42
+ 0 0 255 Blue
43
+ 0 0 128 Navy
44
+ 0 0 0 Black
45
+ EOS
46
+ @gimp = Color::Palette::Gimp.new(wsc)
47
+ end
48
+
49
+ def test_each
50
+ assert_equal(16, @gimp.instance_variable_get(:@colors).size)
51
+ @gimp.each { |el| assert_kind_of(Color::RGB, el) }
52
+ end
53
+
54
+ def test_each_name
55
+ assert_equal(16, @gimp.instance_variable_get(:@names).size)
56
+
57
+ @gimp.each_name { |color_name, color_set|
58
+ assert_kind_of(Array, color_set)
59
+ color_set.each { |el|
60
+ assert_kind_of(Color::RGB, el)
61
+ }
62
+ }
63
+ end
64
+
65
+ def test_index
66
+ assert_equal(Color::RGB::White, @gimp[0])
67
+ assert_equal(Color::RGB::White, @gimp["White"][0])
68
+ end
69
+
70
+ def test_valid_eh
71
+ assert(@gimp.valid?)
72
+ end
73
+
74
+ def test_name
75
+ assert_equal("W3C Named Colors", @gimp.name)
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/env ruby
2
+ #--
3
+ # Colour management with Ruby.
4
+ #
5
+ # Copyright 2005 Austin Ziegler
6
+ # http://rubyforge.org/ruby-pdf/
7
+ #
8
+ # Licensed under a MIT-style licence.
9
+ #
10
+ # $Id$
11
+ #++
12
+
13
+ $LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib") if __FILE__ == $0
14
+ require 'test/unit' unless defined? $ZENTEST and $ZENTEST
15
+ require 'color'
16
+
17
+ module TestColor
18
+ class TestGrayScale < Test::Unit::TestCase
19
+ def setup
20
+ @gs = Color::GrayScale.new(33)
21
+ end
22
+
23
+ def test_brightness
24
+ assert_in_delta(0.33, @gs.brightness, 1e-4)
25
+ end
26
+
27
+ def test_darken_by
28
+ assert_in_delta(0.297, @gs.darken_by(10).g, 1e-4)
29
+ end
30
+
31
+ def test_g
32
+ assert_in_delta(0.33, @gs.g, 1e-4)
33
+ end
34
+
35
+ def test_g_equals
36
+ assert_in_delta(0.33, @gs.g, 1e-4)
37
+ assert_nothing_raised { @gs.g = 0.4 }
38
+ assert_in_delta(0.4, @gs.g, 1e-4)
39
+ assert_nothing_raised { @gs.g = 2.0 }
40
+ assert_in_delta(1.0, @gs.g, 1e-4)
41
+ assert_nothing_raised { @gs.g = -2.0 }
42
+ assert_in_delta(0.0, @gs.g, 1e-4)
43
+ end
44
+
45
+ def test_html
46
+ assert_equal("#545454", @gs.html)
47
+ end
48
+
49
+ def test_lighten_by
50
+ assert_in_delta(0.363, @gs.lighten_by(10).g, 1e-4)
51
+ end
52
+
53
+ def test_pdf_fill
54
+ assert_equal("0.330 g", @gs.pdf_fill)
55
+ end
56
+
57
+ def test_pdf_stroke
58
+ assert_equal("0.330 G", @gs.pdf_stroke)
59
+ end
60
+
61
+ def test_to_cmyk
62
+ assert_kind_of(Color::CMYK, @gs.to_cmyk)
63
+ end
64
+
65
+ def test_to_grayscale
66
+ assert_equal(@gs, @gs.to_grayscale)
67
+ end
68
+
69
+ def test_to_greyscale
70
+ assert_equal(@gs, @gs.to_greyscale)
71
+ end
72
+
73
+ def test_to_hsl
74
+ assert_kind_of(Color::HSL, @gs.to_hsl)
75
+ end
76
+
77
+ def test_to_rgb
78
+ assert_kind_of(Color::RGB, @gs.to_rgb)
79
+ end
80
+
81
+ def test_to_yiq
82
+ assert_kind_of(Color::YIQ, @gs.to_yiq)
83
+ end
84
+ end
85
+ end
86
+
87
+ # Number of errors detected: 2
data/tests/test_hsl.rb ADDED
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env ruby
2
+ #--
3
+ # Colour management with Ruby.
4
+ #
5
+ # Copyright 2005 Austin Ziegler
6
+ # http://rubyforge.org/ruby-pdf/
7
+ #
8
+ # Licensed under a MIT-style licence.
9
+ #
10
+ # $Id$
11
+ #++
12
+
13
+ $LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib") if __FILE__ == $0
14
+ require 'test/unit' unless defined? $ZENTEST and $ZENTEST
15
+ require 'color'
16
+
17
+ module TestColor
18
+ class TestHSL < Test::Unit::TestCase
19
+ def setup
20
+ @hsl = Color::HSL.new(145, 20, 30)
21
+ end
22
+
23
+ def brightness
24
+ assert_in_delta(0.3, @hsl.brightness, 1e-4)
25
+ end
26
+
27
+ def test_h
28
+ assert_in_delta(0.4027, @hsl.h, 1e-4)
29
+ end
30
+
31
+ def test_h_equals
32
+ assert_in_delta(0.4027, @hsl.h, 1e-4)
33
+ assert_nothing_raised { @hsl.h = 0.33 }
34
+ assert_in_delta(0.33, @hsl.h, 1e-4)
35
+ assert_nothing_raised { @hsl.h = 3.3 }
36
+ assert_in_delta(1.0, @hsl.h, 1e-4)
37
+ assert_nothing_raised { @hsl.h = -3.3 }
38
+ assert_in_delta(0.0, @hsl.h, 1e-4)
39
+ end
40
+
41
+ def test_html
42
+ assert_equal("#3d5c4a", @hsl.html)
43
+ end
44
+
45
+ def test_l
46
+ assert_in_delta(0.3, @hsl.l, 1e-4)
47
+ end
48
+
49
+ def test_l_equals
50
+ assert_in_delta(0.3, @hsl.l, 1e-4)
51
+ assert_nothing_raised { @hsl.l = 0.33 }
52
+ assert_in_delta(0.33, @hsl.l, 1e-4)
53
+ assert_nothing_raised { @hsl.l = 3.3 }
54
+ assert_in_delta(1.0, @hsl.l, 1e-4)
55
+ assert_nothing_raised { @hsl.l = -3.3 }
56
+ assert_in_delta(0.0, @hsl.l, 1e-4)
57
+ end
58
+
59
+ def test_s
60
+ assert_in_delta(0.2, @hsl.s, 1e-4)
61
+ end
62
+
63
+ def test_s_equals
64
+ assert_in_delta(0.2, @hsl.s, 1e-4)
65
+ assert_nothing_raised { @hsl.s = 0.33 }
66
+ assert_in_delta(0.33, @hsl.s, 1e-4)
67
+ assert_nothing_raised { @hsl.s = 3.3 }
68
+ assert_in_delta(1.0, @hsl.s, 1e-4)
69
+ assert_nothing_raised { @hsl.s = -3.3 }
70
+ assert_in_delta(0.0, @hsl.s, 1e-4)
71
+ end
72
+
73
+ def test_to_cmyk
74
+ assert_kind_of(Color::CMYK, @hsl.to_cmyk)
75
+ end
76
+
77
+ def test_to_grayscale
78
+ assert_kind_of(Color::GrayScale, @hsl.to_grayscale)
79
+ end
80
+
81
+ def test_to_greyscale
82
+ assert_kind_of(Color::GreyScale, @hsl.to_greyscale)
83
+ end
84
+
85
+ def test_to_rgb
86
+ assert_kind_of(Color::RGB, @hsl.to_rgb)
87
+ end
88
+
89
+ def test_to_yiq
90
+ assert_kind_of(Color::YIQ, @hsl.to_yiq)
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,145 @@
1
+ #!/usr/bin/env ruby
2
+ #--
3
+ # Colour management with Ruby.
4
+ #
5
+ # Copyright 2005 Austin Ziegler
6
+ # http://rubyforge.org/ruby-pdf/
7
+ #
8
+ # Licensed under a MIT-style licence.
9
+ #
10
+ # $Id$
11
+ #++
12
+
13
+ $LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib") if __FILE__ == $0
14
+ require 'test/unit' unless defined? $ZENTEST and $ZENTEST
15
+ require 'color'
16
+ require 'color/palette/monocontrast'
17
+
18
+ module TestColor
19
+ module TestPalette
20
+ class TestMonoContrast < Test::Unit::TestCase
21
+ include Color::Palette
22
+ def setup
23
+ @high = Color::RGB.from_html("#c9e3a6")
24
+ @low = Color::RGB.from_html("#746b8e")
25
+ @mcp1 = MonoContrast.new(@high)
26
+ @mcp2 = MonoContrast.new(@low)
27
+ end
28
+
29
+ def test_background
30
+ assert_equal("#141711", @mcp1.background[-5].html)
31
+ assert_equal("#32392a", @mcp1.background[-4].html)
32
+ assert_equal("#657253", @mcp1.background[-3].html)
33
+ assert_equal("#97aa7d", @mcp1.background[-2].html)
34
+ assert_equal("#abc18d", @mcp1.background[-1].html)
35
+ assert_equal("#c9e3a6", @mcp1.background[ 0].html)
36
+ assert_equal("#d1e7b3", @mcp1.background[+1].html)
37
+ assert_equal("#d7eabc", @mcp1.background[+2].html) # d7eabd
38
+ assert_equal("#e4f1d3", @mcp1.background[+3].html) # e5f2d3
39
+ assert_equal("#f2f8e9", @mcp1.background[+4].html) # f1f8e9
40
+ assert_equal("#fafcf6", @mcp1.background[+5].html) # fafdf7
41
+
42
+ assert_equal("#0c0b0e", @mcp2.background[-5].html)
43
+ assert_equal("#1d1b24", @mcp2.background[-4].html)
44
+ assert_equal("#3a3647", @mcp2.background[-3].html)
45
+ assert_equal("#57506b", @mcp2.background[-2].html)
46
+ assert_equal("#635b79", @mcp2.background[-1].html)
47
+ assert_equal("#746b8e", @mcp2.background[ 0].html)
48
+ assert_equal("#89819f", @mcp2.background[+1].html)
49
+ assert_equal("#9790aa", @mcp2.background[+2].html) # 9790ab
50
+ assert_equal("#bab5c7", @mcp2.background[+3].html) # bab6c7
51
+ assert_equal("#dcdae3", @mcp2.background[+4].html)
52
+ assert_equal("#f1f0f4", @mcp2.background[+5].html) # f2f1f4
53
+ end
54
+
55
+ def test_brightness_diff
56
+ bd1 = @mcp1.brightness_diff(@high, @low)
57
+ bd2 = @mcp1.brightness_diff(@low, @high)
58
+ assert_in_delta(bd1, bd2, 1e-4)
59
+ end
60
+
61
+ def test_calculate_foreground
62
+ assert_equal("#ffffff", @mcp1.calculate_foreground(@low, @high).html)
63
+ assert_equal("#1d1b24", @mcp1.calculate_foreground(@high, @low).html)
64
+ end
65
+
66
+ def test_color_diff
67
+ assert_in_delta(@mcp1.color_diff(@low, @high),
68
+ @mcp1.color_diff(@high, @low), 1e-4)
69
+ end
70
+
71
+ def test_foreground
72
+ assert_equal("#c9e3a6", @mcp1.foreground[-5].html)
73
+ assert_equal("#e4f1d3", @mcp1.foreground[-4].html) # e5f2d3
74
+ assert_equal("#ffffff", @mcp1.foreground[-3].html)
75
+ assert_equal("#000000", @mcp1.foreground[-2].html)
76
+ assert_equal("#000000", @mcp1.foreground[-1].html)
77
+ assert_equal("#000000", @mcp1.foreground[ 0].html)
78
+ assert_equal("#000000", @mcp1.foreground[+1].html)
79
+ assert_equal("#000000", @mcp1.foreground[+2].html)
80
+ assert_equal("#32392a", @mcp1.foreground[+3].html)
81
+ assert_equal("#32392a", @mcp1.foreground[+4].html)
82
+ assert_equal("#32392a", @mcp1.foreground[+5].html)
83
+
84
+ assert_equal("#bab5c7", @mcp2.foreground[-5].html) # bab6c7
85
+ assert_equal("#dcdae3", @mcp2.foreground[-4].html)
86
+ assert_equal("#ffffff", @mcp2.foreground[-3].html)
87
+ assert_equal("#ffffff", @mcp2.foreground[-2].html)
88
+ assert_equal("#ffffff", @mcp2.foreground[-1].html)
89
+ assert_equal("#ffffff", @mcp2.foreground[ 0].html)
90
+ assert_equal("#000000", @mcp2.foreground[+1].html)
91
+ assert_equal("#000000", @mcp2.foreground[+2].html)
92
+ assert_equal("#000000", @mcp2.foreground[+3].html)
93
+ assert_equal("#1d1b24", @mcp2.foreground[+4].html)
94
+ assert_equal("#3a3647", @mcp2.foreground[+5].html)
95
+ end
96
+
97
+ def test_minimum_brightness_diff
98
+ assert_in_delta(MonoContrast::DEFAULT_MINIMUM_BRIGHTNESS_DIFF,
99
+ @mcp1.minimum_brightness_diff, 1e-4)
100
+ end
101
+
102
+ def test_minimum_brightness_diff_equals
103
+ assert_in_delta(MonoContrast::DEFAULT_MINIMUM_BRIGHTNESS_DIFF,
104
+ @mcp1.minimum_brightness_diff, 1e-4)
105
+ mcps = @mcp1.dup
106
+ assert_nothing_raised { @mcp1.minimum_brightness_diff = 0.75 }
107
+ assert_in_delta(0.75, @mcp1.minimum_brightness_diff, 1e-4)
108
+ assert_not_equal(@mcp1.foreground[-5], mcps.foreground[-5])
109
+ assert_nothing_raised { @mcp1.minimum_brightness_diff = 4.0 }
110
+ assert_in_delta(1, @mcp1.minimum_brightness_diff, 1e-4)
111
+ assert_nothing_raised { @mcp1.minimum_brightness_diff = -4.0 }
112
+ assert_in_delta(0, @mcp1.minimum_brightness_diff, 1e-4)
113
+ assert_nothing_raised { @mcp1.minimum_brightness_diff = nil }
114
+ assert_in_delta(MonoContrast::DEFAULT_MINIMUM_BRIGHTNESS_DIFF,
115
+ @mcp1.minimum_brightness_diff, 1e-4)
116
+ end
117
+
118
+ def test_minimum_color_diff
119
+ assert_in_delta(MonoContrast::DEFAULT_MINIMUM_COLOR_DIFF,
120
+ @mcp1.minimum_color_diff, 1e-4)
121
+ end
122
+
123
+ def test_minimum_color_diff_equals
124
+ assert_in_delta(MonoContrast::DEFAULT_MINIMUM_COLOR_DIFF,
125
+ @mcp1.minimum_color_diff, 1e-4)
126
+ mcps = @mcp1.dup
127
+ assert_nothing_raised { @mcp1.minimum_color_diff = 0.75 }
128
+ assert_in_delta(0.75, @mcp1.minimum_color_diff, 1e-4)
129
+ assert_not_equal(@mcp1.foreground[-5], mcps.foreground[-5])
130
+ assert_nothing_raised { @mcp1.minimum_color_diff = 4.0 }
131
+ assert_in_delta(3, @mcp1.minimum_color_diff, 1e-4)
132
+ assert_nothing_raised { @mcp1.minimum_color_diff = -4.0 }
133
+ assert_in_delta(0, @mcp1.minimum_color_diff, 1e-4)
134
+ assert_nothing_raised { @mcp1.minimum_color_diff = nil }
135
+ assert_in_delta(MonoContrast::DEFAULT_MINIMUM_COLOR_DIFF,
136
+ @mcp1.minimum_color_diff, 1e-4)
137
+ end
138
+
139
+ # This is empty because the #regenerate method is automatically run
140
+ # when changing the minimum_brightness_diff or minimum_color_diff.
141
+ def test_regenerate
142
+ end
143
+ end
144
+ end
145
+ end