spectrum 0.0.1 → 0.2.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.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/HISTORY.md +56 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.md +255 -0
  5. data/lib/spectrum/describe.rb +55 -0
  6. data/lib/spectrum/feature/advice.rb +31 -0
  7. data/lib/spectrum/feature/feature.rb +192 -0
  8. data/lib/spectrum/feature/featurette.rb +68 -0
  9. data/lib/spectrum/feature/scenario.rb +203 -0
  10. data/lib/spectrum/feature/step.rb +50 -0
  11. data/lib/spectrum/feature.rb +45 -0
  12. data/lib/spectrum/spec/context.rb +409 -0
  13. data/lib/spectrum/spec/example.rb +231 -0
  14. data/lib/spectrum/spec/hooks.rb +83 -0
  15. data/lib/spectrum/testcase/test_case.rb +328 -0
  16. data/lib/spectrum/testcase/test_proc.rb +143 -0
  17. data/lib/spectrum/testcase.rb +28 -0
  18. data/lib/spectrum/version.rb +3 -0
  19. data/lib/spectrum/world.rb +15 -0
  20. data/lib/spectrum.rb +14 -138
  21. metadata +71 -72
  22. data/History.txt +0 -93
  23. data/Install.txt +0 -18
  24. data/Licence.txt +0 -27
  25. data/README.txt +0 -35
  26. data/lib/spectrum/cmyk.rb +0 -281
  27. data/lib/spectrum/css.rb +0 -28
  28. data/lib/spectrum/grayscale.rb +0 -212
  29. data/lib/spectrum/hsl.rb +0 -221
  30. data/lib/spectrum/palette/adobecolor.rb +0 -272
  31. data/lib/spectrum/palette/gimp.rb +0 -116
  32. data/lib/spectrum/palette/monocontrast.rb +0 -180
  33. data/lib/spectrum/palette.rb +0 -16
  34. data/lib/spectrum/rgb/metallic.rb +0 -43
  35. data/lib/spectrum/rgb-colors.rb +0 -355
  36. data/lib/spectrum/rgb.rb +0 -453
  37. data/lib/spectrum/yiq.rb +0 -84
  38. data/test/test_adobecolor.rb +0 -419
  39. data/test/test_all.rb +0 -23
  40. data/test/test_cmyk.rb +0 -128
  41. data/test/test_color.rb +0 -141
  42. data/test/test_css.rb +0 -29
  43. data/test/test_gimp.rb +0 -101
  44. data/test/test_grayscale.rb +0 -121
  45. data/test/test_hsl.rb +0 -153
  46. data/test/test_monocontrast.rb +0 -142
  47. data/test/test_rgb.rb +0 -344
  48. data/test/test_yiq.rb +0 -73
data/test/test_color.rb DELETED
@@ -1,141 +0,0 @@
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
- require 'spectrum'
17
- require 'spectrum/css'
18
-
19
- module TestColor
20
- class TestColor < Test::Unit::TestCase
21
- def setup
22
- Kernel.module_eval do
23
- alias old_warn warn
24
-
25
- def warn(message)
26
- $last_warn = message
27
- end
28
- end
29
- end
30
-
31
- def teardown
32
- Kernel.module_eval do
33
- undef warn
34
- alias warn old_warn
35
- undef old_warn
36
- end
37
- end
38
-
39
- def test_const
40
- $last_warn = nil
41
- assert_equal(Spectrum::RGB::AliceBlue, Spectrum::AliceBlue)
42
- assert_equal("Spectrum::AliceBlue has been deprecated. Use Spectrum::RGB::AliceBlue instead.", $last_warn)
43
-
44
- $last_warn = nil # Do this twice to make sure it always happens...
45
- assert(Spectrum::AliceBlue)
46
- assert_equal("Spectrum::AliceBlue has been deprecated. Use Spectrum::RGB::AliceBlue instead.", $last_warn)
47
-
48
- $last_warn = nil
49
- assert_equal(Spectrum::COLOR_VERSION, Spectrum::VERSION)
50
- assert_equal("Spectrum::VERSION has been deprecated. Use Spectrum::COLOR_VERSION instead.", $last_warn)
51
-
52
- $last_warn = nil
53
- assert_equal(Spectrum::COLOR_VERSION, Spectrum::COLOR_TOOLS_VERSION)
54
- assert_equal("Spectrum::COLOR_TOOLS_VERSION has been deprecated. Use Spectrum::COLOR_VERSION instead.", $last_warn)
55
-
56
- $last_warn = nil
57
- assert(Spectrum::COLOR_VERSION)
58
- assert_nil($last_warn)
59
- assert(Spectrum::COLOR_EPSILON)
60
- assert_nil($last_warn)
61
-
62
- assert_raises(NameError) { assert(Spectrum::MISSING_VALUE) }
63
- end
64
-
65
- def test_normalize
66
- (1..10).each do |i|
67
- assert_equal(0.0, Spectrum.normalize(-7 * i))
68
- assert_equal(0.0, Spectrum.normalize(-7 / i))
69
- assert_equal(0.0, Spectrum.normalize(0 - i))
70
- assert_equal(1.0, Spectrum.normalize(255 + i))
71
- assert_equal(1.0, Spectrum.normalize(256 * i))
72
- assert_equal(1.0, Spectrum.normalize(65536 / i))
73
- end
74
- (0..255).each do |i|
75
- assert_in_delta(i / 255.0, Spectrum.normalize(i / 255.0),
76
- 1e-2)
77
- end
78
- end
79
-
80
- def test_normalize_range
81
- assert_equal(0, Spectrum.normalize_8bit(-1))
82
- assert_equal(0, Spectrum.normalize_8bit(0))
83
- assert_equal(127, Spectrum.normalize_8bit(127))
84
- assert_equal(172, Spectrum.normalize_8bit(172))
85
- assert_equal(255, Spectrum.normalize_8bit(255))
86
- assert_equal(255, Spectrum.normalize_8bit(256))
87
-
88
- assert_equal(0, Spectrum.normalize_16bit(-1))
89
- assert_equal(0, Spectrum.normalize_16bit(0))
90
- assert_equal(127, Spectrum.normalize_16bit(127))
91
- assert_equal(172, Spectrum.normalize_16bit(172))
92
- assert_equal(255, Spectrum.normalize_16bit(255))
93
- assert_equal(256, Spectrum.normalize_16bit(256))
94
- assert_equal(65535, Spectrum.normalize_16bit(65535))
95
- assert_equal(65535, Spectrum.normalize_16bit(66536))
96
-
97
- assert_equal(-100, Spectrum.normalize_to_range(-101, -100..100))
98
- assert_equal(-100, Spectrum.normalize_to_range(-100.5, -100..100))
99
- assert_equal(-100, Spectrum.normalize_to_range(-100, -100..100))
100
- assert_equal(-100, Spectrum.normalize_to_range(-100.0, -100..100))
101
- assert_equal(-99.5, Spectrum.normalize_to_range(-99.5, -100..100))
102
- assert_equal(-50, Spectrum.normalize_to_range(-50, -100..100))
103
- assert_equal(-50.5, Spectrum.normalize_to_range(-50.5, -100..100))
104
- assert_equal(0, Spectrum.normalize_to_range(0, -100..100))
105
- assert_equal(50, Spectrum.normalize_to_range(50, -100..100))
106
- assert_equal(50.5, Spectrum.normalize_to_range(50.5, -100..100))
107
- assert_equal(99, Spectrum.normalize_to_range(99, -100..100))
108
- assert_equal(99.5, Spectrum.normalize_to_range(99.5, -100..100))
109
- assert_equal(100, Spectrum.normalize_to_range(100, -100..100))
110
- assert_equal(100, Spectrum.normalize_to_range(100.0, -100..100))
111
- assert_equal(100, Spectrum.normalize_to_range(100.5, -100..100))
112
- assert_equal(100, Spectrum.normalize_to_range(101, -100..100))
113
- end
114
-
115
- def test_new
116
- $last_warn = nil
117
- c = Spectrum.new("#fff")
118
- assert_kind_of(Spectrum::HSL, c)
119
- assert_equal(Spectrum::RGB::White.to_hsl, c)
120
- assert_equal("Spectrum.new has been deprecated. Use Spectrum::RGB.new instead.", $last_warn)
121
-
122
- $last_warn = nil
123
- c = Spectrum.new([0, 0, 0])
124
- assert_kind_of(Spectrum::HSL, c)
125
- assert_equal(Spectrum::RGB::Black.to_hsl, c)
126
- assert_equal("Spectrum.new has been deprecated. Use Spectrum::RGB.new instead.", $last_warn)
127
-
128
- $last_warn = nil
129
- c = Spectrum.new([10, 20, 30], :hsl)
130
- assert_kind_of(Spectrum::HSL, c)
131
- assert_equal(Spectrum::HSL.new(10, 20, 30), c)
132
- assert_equal("Spectrum.new has been deprecated. Use Spectrum::HSL.new instead.", $last_warn)
133
-
134
- $last_warn = nil
135
- c = Spectrum.new([10, 20, 30, 40], :cmyk)
136
- assert_kind_of(Spectrum::HSL, c)
137
- assert_equal(Spectrum::CMYK.new(10, 20, 30, 40).to_hsl, c)
138
- assert_equal("Spectrum.new has been deprecated. Use Spectrum::CMYK.new instead.", $last_warn)
139
- end
140
- end
141
- end
data/test/test_css.rb DELETED
@@ -1,29 +0,0 @@
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
- require 'spectrum'
17
- require 'spectrum/css'
18
-
19
- module TestColor
20
- class TestCSS < Test::Unit::TestCase
21
- def test_index
22
- assert_equal(Spectrum::RGB::AliceBlue, Spectrum::CSS[:aliceblue])
23
- assert_equal(Spectrum::RGB::AliceBlue, Spectrum::CSS["AliceBlue"])
24
- assert_equal(Spectrum::RGB::AliceBlue, Spectrum::CSS["aliceBlue"])
25
- assert_equal(Spectrum::RGB::AliceBlue, Spectrum::CSS["aliceblue"])
26
- assert_equal(Spectrum::RGB::AliceBlue, Spectrum::CSS[:AliceBlue])
27
- end
28
- end
29
- end
data/test/test_gimp.rb DELETED
@@ -1,101 +0,0 @@
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
- require 'spectrum'
17
- require 'spectrum/palette/gimp'
18
-
19
- module TestColor
20
- module TestPalette
21
- class TestGimp < Test::Unit::TestCase
22
- include Spectrum::Palette
23
-
24
- GIMP_W3C = <<-EOS
25
- GIMP Palette
26
- Name: W3C Named Colors
27
- Columns: 2
28
- #
29
- # ColorZilla W3C Named Colors
30
- #
31
- 255 255 255 White
32
- 255 255 0 Yclow
33
- 255 0 255 Fuchsia
34
- 255 0 0 Red
35
- 192 192 192 Silver
36
- 128 128 128 Gray
37
- 128 128 0 Olive
38
- 128 0 128 Purple
39
- 128 0 0 Maroon
40
- 0 255 255 Aqua
41
- 0 255 0 Lime
42
- 0 128 128 Teal
43
- 0 128 0 Green
44
- 0 0 255 Blue
45
- 0 0 128 Navy
46
- 0 0 0 Black
47
- EOS
48
-
49
- def setup
50
- @filename = "test#{Process.pid}.gimp"
51
- end
52
-
53
- def teardown
54
- require 'fileutils'
55
- FileUtils.rm_f @filename if File.exist? @filename
56
- end
57
-
58
- def test_each
59
- @gimp = Gimp.new(GIMP_W3C)
60
- assert_equal(16, @gimp.instance_variable_get(:@colors).size)
61
- @gimp.each { |c| assert_kind_of(Spectrum::RGB, c) }
62
- end
63
-
64
- def test_each_name
65
- @gimp = Gimp.new(GIMP_W3C)
66
- assert_equal(16, @gimp.instance_variable_get(:@names).size)
67
-
68
- @gimp.each_name { |color_name, color_set|
69
- assert_kind_of(Array, color_set)
70
- color_set.each { |c|
71
- assert_kind_of(Spectrum::RGB, c)
72
- }
73
- }
74
- end
75
-
76
- def test_index
77
- assert_nothing_raised do
78
- File.open(@filename, "wb") do |f|
79
- f.write GIMP_W3C
80
- end
81
- end
82
- assert_nothing_raised { @gimp = Gimp.from_file(@filename) }
83
- assert_equal(Spectrum::RGB::White, @gimp[0])
84
- assert_equal(Spectrum::RGB::White, @gimp["White"][0])
85
- assert_equal([Spectrum::RGB::White, Spectrum::RGB::Black],
86
- @gimp.values_at(0, -1))
87
- assert_equal(16, @gimp.size)
88
- end
89
-
90
- def test_valid_eh
91
- @gimp = Gimp.new(GIMP_W3C)
92
- assert(@gimp.valid?)
93
- end
94
-
95
- def test_name
96
- @gimp = Gimp.new(GIMP_W3C)
97
- assert_equal("W3C Named Colors", @gimp.name)
98
- end
99
- end
100
- end
101
- end
@@ -1,121 +0,0 @@
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
- require 'spectrum'
17
-
18
- module TestColor
19
- class TestGrayScale < Test::Unit::TestCase
20
- def setup
21
- @gs = Spectrum::GrayScale.from_percent(33)
22
- end
23
-
24
- def test_brightness
25
- assert_in_delta(0.33, @gs.brightness, Spectrum::COLOR_TOLERANCE)
26
- end
27
-
28
- def test_darken_by
29
- assert_in_delta(29.7, @gs.darken_by(10).gray, Spectrum::COLOR_TOLERANCE)
30
- end
31
-
32
- def test_g
33
- assert_in_delta(0.33, @gs.g, Spectrum::COLOR_TOLERANCE)
34
- assert_in_delta(33, @gs.grey, Spectrum::COLOR_TOLERANCE)
35
- assert_nothing_raised { @gs.gray = 40 }
36
- assert_in_delta(0.4, @gs.g, Spectrum::COLOR_TOLERANCE)
37
- assert_nothing_raised { @gs.g = 2.0 }
38
- assert_in_delta(100, @gs.gray, Spectrum::COLOR_TOLERANCE)
39
- assert_nothing_raised { @gs.grey = -2.0 }
40
- assert_in_delta(0.0, @gs.g, Spectrum::COLOR_TOLERANCE)
41
- end
42
-
43
- def test_html_css
44
- assert_equal("#545454", @gs.html)
45
- assert_equal("rgb(33.00%, 33.00%, 33.00%)", @gs.css_rgb)
46
- assert_equal("rgba(33.00%, 33.00%, 33.00%, 1.00)", @gs.css_rgba)
47
- end
48
-
49
- def test_lighten_by
50
- assert_in_delta(0.363, @gs.lighten_by(10).g, Spectrum::COLOR_TOLERANCE)
51
- end
52
-
53
- def test_pdf_fill
54
- assert_equal("0.330 g", @gs.pdf_fill)
55
- assert_equal("0.330 G", @gs.pdf_stroke)
56
- end
57
-
58
- def test_to_cmyk
59
- cmyk = nil
60
- assert_nothing_raised { cmyk = @gs.to_cmyk }
61
- assert_kind_of(Spectrum::CMYK, cmyk)
62
- assert_in_delta(0.0, cmyk.c, Spectrum::COLOR_TOLERANCE)
63
- assert_in_delta(0.0, cmyk.m, Spectrum::COLOR_TOLERANCE)
64
- assert_in_delta(0.0, cmyk.y, Spectrum::COLOR_TOLERANCE)
65
- assert_in_delta(0.67, cmyk.k, Spectrum::COLOR_TOLERANCE)
66
- end
67
-
68
- def test_to_grayscale
69
- assert_equal(@gs, @gs.to_grayscale)
70
- assert_equal(@gs, @gs.to_greyscale)
71
- end
72
-
73
- def test_to_hsl
74
- hsl = nil
75
- assert_nothing_raised { hsl = @gs.to_hsl }
76
- assert_kind_of(Spectrum::HSL, hsl)
77
- assert_in_delta(0.0, hsl.h, Spectrum::COLOR_TOLERANCE)
78
- assert_in_delta(0.0, hsl.s, Spectrum::COLOR_TOLERANCE)
79
- assert_in_delta(0.33, hsl.l, Spectrum::COLOR_TOLERANCE)
80
- assert_equal("hsl(0.00, 0.00%, 33.00%)", @gs.css_hsl)
81
- assert_equal("hsla(0.00, 0.00%, 33.00%, 1.00)", @gs.css_hsla)
82
- end
83
-
84
- def test_to_rgb
85
- rgb = nil
86
- assert_nothing_raised { rgb = @gs.to_rgb }
87
- assert_kind_of(Spectrum::RGB, rgb)
88
- assert_in_delta(0.33, rgb.r, Spectrum::COLOR_TOLERANCE)
89
- assert_in_delta(0.33, rgb.g, Spectrum::COLOR_TOLERANCE)
90
- assert_in_delta(0.33, rgb.b, Spectrum::COLOR_TOLERANCE)
91
- end
92
-
93
- def test_to_yiq
94
- yiq = nil
95
- assert_nothing_raised { yiq = @gs.to_yiq }
96
- assert_kind_of(Spectrum::YIQ, yiq)
97
- assert_in_delta(0.33, yiq.y, Spectrum::COLOR_TOLERANCE)
98
- assert_in_delta(0.0, yiq.i, Spectrum::COLOR_TOLERANCE)
99
- assert_in_delta(0.0, yiq.q, Spectrum::COLOR_TOLERANCE)
100
- end
101
-
102
- def test_add
103
- delta = @gs + Spectrum::GrayScale.new(20)
104
- max = @gs + Spectrum::GrayScale.new(80)
105
-
106
- assert_in_delta(1.0, max.g, Spectrum::COLOR_TOLERANCE)
107
- assert_in_delta(0.53, delta.g, Spectrum::COLOR_TOLERANCE)
108
- end
109
-
110
- def test_subtract
111
- delta = @gs - Spectrum::GrayScale.new(20)
112
- max = @gs - Spectrum::GrayScale.new(80)
113
- assert_in_delta(0.0, max.g, Spectrum::COLOR_TOLERANCE)
114
- assert_in_delta(0.13, delta.g, Spectrum::COLOR_TOLERANCE)
115
- end
116
-
117
- def test_inspect
118
- assert_equal("Gray [33.00%]", @gs.inspect)
119
- end
120
- end
121
- end
data/test/test_hsl.rb DELETED
@@ -1,153 +0,0 @@
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
- # HSL Tests provided by Adam Johnson
14
- #++
15
-
16
- $LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib") if __FILE__ == $0
17
- require 'test/unit'
18
- require 'spectrum'
19
-
20
- module TestColor
21
- class TestHSL < Test::Unit::TestCase
22
- def setup
23
- # @hsl = Spectrum::HSL.new(262, 67, 42)
24
- @hsl = Spectrum::HSL.new(145, 20, 30)
25
- # @rgb = Spectrum::RGB.new(88, 35, 179)
26
- end
27
-
28
- def test_rgb_roundtrip_conversion
29
- hsl = Spectrum::HSL.new(262, 67, 42)
30
- c = hsl.to_rgb.to_hsl
31
- assert_in_delta hsl.h, c.h, Spectrum::COLOR_TOLERANCE, "Hue"
32
- assert_in_delta hsl.s, c.s, Spectrum::COLOR_TOLERANCE, "Saturation"
33
- assert_in_delta hsl.l, c.l, Spectrum::COLOR_TOLERANCE, "Luminance"
34
- end
35
-
36
- def test_brightness
37
- assert_in_delta 0.3, @hsl.brightness, Spectrum::COLOR_TOLERANCE
38
- end
39
-
40
- def test_hue
41
- assert_in_delta 0.4027, @hsl.h, Spectrum::COLOR_TOLERANCE
42
- assert_in_delta 145, @hsl.hue, Spectrum::COLOR_TOLERANCE
43
- assert_nothing_raised { @hsl.hue = 33 }
44
- assert_in_delta 0.09167, @hsl.h, Spectrum::COLOR_TOLERANCE
45
- assert_nothing_raised { @hsl.hue = -33 }
46
- assert_in_delta 0.90833, @hsl.h, Spectrum::COLOR_TOLERANCE
47
- assert_nothing_raised { @hsl.h = 3.3 }
48
- assert_in_delta 360, @hsl.hue, Spectrum::COLOR_TOLERANCE
49
- assert_nothing_raised { @hsl.h = -3.3 }
50
- assert_in_delta 0.0, @hsl.h, Spectrum::COLOR_TOLERANCE
51
- assert_nothing_raised { @hsl.hue = 0 }
52
- assert_nothing_raised { @hsl.hue -= 20 }
53
- assert_in_delta 340, @hsl.hue, Spectrum::COLOR_TOLERANCE
54
- assert_nothing_raised { @hsl.hue += 45 }
55
- assert_in_delta 25, @hsl.hue, Spectrum::COLOR_TOLERANCE
56
- end
57
-
58
- def test_saturation
59
- assert_in_delta 0.2, @hsl.s, Spectrum::COLOR_TOLERANCE
60
- assert_in_delta 20, @hsl.saturation, Spectrum::COLOR_TOLERANCE
61
- assert_nothing_raised { @hsl.saturation = 33 }
62
- assert_in_delta 0.33, @hsl.s, Spectrum::COLOR_TOLERANCE
63
- assert_nothing_raised { @hsl.s = 3.3 }
64
- assert_in_delta 100, @hsl.saturation, Spectrum::COLOR_TOLERANCE
65
- assert_nothing_raised { @hsl.s = -3.3 }
66
- assert_in_delta 0.0, @hsl.s, Spectrum::COLOR_TOLERANCE
67
- end
68
-
69
- def test_luminance
70
- assert_in_delta 0.3, @hsl.l, Spectrum::COLOR_TOLERANCE
71
- assert_in_delta 30, @hsl.luminosity, Spectrum::COLOR_TOLERANCE
72
- assert_nothing_raised { @hsl.luminosity = 33 }
73
- assert_in_delta 0.33, @hsl.l, Spectrum::COLOR_TOLERANCE
74
- assert_nothing_raised { @hsl.l = 3.3 }
75
- assert_in_delta 100, @hsl.lightness, Spectrum::COLOR_TOLERANCE
76
- assert_nothing_raised { @hsl.l = -3.3 }
77
- assert_in_delta 0.0, @hsl.l, Spectrum::COLOR_TOLERANCE
78
- end
79
-
80
- def test_html_css
81
- assert_equal "hsl(145.00, 20.00%, 30.00%)", @hsl.css_hsl
82
- assert_equal "hsla(145.00, 20.00%, 30.00%, 1.00)", @hsl.css_hsla
83
- end
84
-
85
- def test_to_cmyk
86
- cmyk = nil
87
- assert_nothing_raised { cmyk = @hsl.to_cmyk }
88
- assert_kind_of Spectrum::CMYK, cmyk
89
- assert_in_delta 0.3223, cmyk.c, Spectrum::COLOR_TOLERANCE
90
- assert_in_delta 0.2023, cmyk.m, Spectrum::COLOR_TOLERANCE
91
- assert_in_delta 0.2723, cmyk.y, Spectrum::COLOR_TOLERANCE
92
- assert_in_delta 0.4377, cmyk.k, Spectrum::COLOR_TOLERANCE
93
- end
94
-
95
- def test_to_grayscale
96
- gs = nil
97
- assert_nothing_raised { gs = @hsl.to_grayscale }
98
- assert_kind_of Spectrum::GreyScale, gs
99
- assert_in_delta 30, gs.gray, Spectrum::COLOR_TOLERANCE
100
- end
101
-
102
- def test_to_rgb
103
- rgb = nil
104
- assert_nothing_raised { rgb = @hsl.to_rgb }
105
- assert_kind_of Spectrum::RGB, rgb
106
- assert_in_delta 0.24, rgb.r, Spectrum::COLOR_TOLERANCE
107
- assert_in_delta 0.36, rgb.g, Spectrum::COLOR_TOLERANCE
108
- assert_in_delta 0.29, rgb.b, Spectrum::COLOR_TOLERANCE
109
- assert_equal "#3d5c4a", @hsl.html
110
- assert_equal "rgb(24.00%, 36.00%, 29.00%)", @hsl.css_rgb
111
- assert_equal "rgba(24.00%, 36.00%, 29.00%, 1.00)", @hsl.css_rgba
112
- # The following tests address a bug reported by Jean Krohn on June 6,
113
- # 2006 and excercise some previously unexercised code in to_rgb.
114
- assert_equal Spectrum::RGB::Black, Spectrum::HSL.new(75, 75, 0)
115
- assert_equal Spectrum::RGB::White, Spectrum::HSL.new(75, 75, 100)
116
- assert_equal Spectrum::RGB::Gray80, Spectrum::HSL.new(75, 0, 80)
117
-
118
- # The following tests a bug reported by Adam Johnson on 29 October
119
- # 2010.
120
- rgb = Spectrum::RGB.from_fraction(0.34496, 0.1386, 0.701399)
121
- c = Spectrum::HSL.new(262, 67, 42).to_rgb
122
- assert_in_delta rgb.r, c.r, Spectrum::COLOR_TOLERANCE, "Red"
123
- assert_in_delta rgb.g, c.g, Spectrum::COLOR_TOLERANCE, "Green"
124
- assert_in_delta rgb.b, c.b, Spectrum::COLOR_TOLERANCE, "Blue"
125
- end
126
-
127
- def test_to_yiq
128
- yiq = nil
129
- assert_nothing_raised { yiq = @hsl.to_yiq }
130
- assert_kind_of Spectrum::YIQ, yiq
131
- assert_in_delta 0.3161, yiq.y, Spectrum::COLOR_TOLERANCE
132
- assert_in_delta 0.0, yiq.i, Spectrum::COLOR_TOLERANCE
133
- assert_in_delta 0.0, yiq.q, Spectrum::COLOR_TOLERANCE
134
- end
135
-
136
- def test_mix_with
137
- red = Spectrum::RGB::Red.to_hsl
138
- yellow = Spectrum::RGB::Yellow.to_hsl
139
- assert_in_delta 0, red.hue, Spectrum::COLOR_TOLERANCE
140
- assert_in_delta 60, yellow.hue, Spectrum::COLOR_TOLERANCE
141
- ry25 = red.mix_with yellow, 0.25
142
- assert_in_delta 15, ry25.hue, Spectrum::COLOR_TOLERANCE
143
- ry50 = red.mix_with yellow, 0.50
144
- assert_in_delta 30, ry50.hue, Spectrum::COLOR_TOLERANCE
145
- ry75 = red.mix_with yellow, 0.75
146
- assert_in_delta 45, ry75.hue, Spectrum::COLOR_TOLERANCE
147
- end
148
-
149
- def test_inspect
150
- assert_equal "HSL [145.00 deg, 20.00%, 30.00%]", @hsl.inspect
151
- end
152
- end
153
- end
@@ -1,142 +0,0 @@
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
- require 'spectrum'
17
- require 'spectrum/palette/monocontrast'
18
-
19
- module TestColor
20
- module TestPalette
21
- class TestMonoContrast < Test::Unit::TestCase
22
- include Spectrum::Palette
23
- def setup
24
- @high = Spectrum::RGB.from_html("#c9e3a6")
25
- @low = Spectrum::RGB.from_html("#746b8e")
26
- @mcp1 = MonoContrast.new(@high)
27
- @mcp2 = MonoContrast.new(@low)
28
- end
29
-
30
- def test_background
31
- assert_equal("#141711", @mcp1.background[-5].html)
32
- assert_equal("#32392a", @mcp1.background[-4].html)
33
- assert_equal("#657253", @mcp1.background[-3].html)
34
- assert_equal("#97aa7d", @mcp1.background[-2].html)
35
- assert_equal("#abc18d", @mcp1.background[-1].html)
36
- assert_equal("#c9e3a6", @mcp1.background[ 0].html)
37
- assert_equal("#d1e7b3", @mcp1.background[+1].html)
38
- assert_equal("#d7eabc", @mcp1.background[+2].html) # d7eabd
39
- assert_equal("#e4f1d3", @mcp1.background[+3].html) # e5f2d3
40
- assert_equal("#f2f8e9", @mcp1.background[+4].html) # f1f8e9
41
- assert_equal("#fafcf6", @mcp1.background[+5].html) # fafdf7
42
-
43
- assert_equal("#0c0b0e", @mcp2.background[-5].html)
44
- assert_equal("#1d1b24", @mcp2.background[-4].html)
45
- assert_equal("#3a3647", @mcp2.background[-3].html)
46
- assert_equal("#57506b", @mcp2.background[-2].html)
47
- assert_equal("#635b79", @mcp2.background[-1].html)
48
- assert_equal("#746b8e", @mcp2.background[ 0].html)
49
- assert_equal("#89819f", @mcp2.background[+1].html)
50
- assert_equal("#9790aa", @mcp2.background[+2].html) # 9790ab
51
- assert_equal("#bab5c7", @mcp2.background[+3].html) # bab6c7
52
- assert_equal("#dcdae3", @mcp2.background[+4].html)
53
- assert_equal("#f1f0f4", @mcp2.background[+5].html) # f2f1f4
54
- end
55
-
56
- def test_brightness_diff
57
- bd1 = @mcp1.brightness_diff(@high, @low)
58
- bd2 = @mcp1.brightness_diff(@low, @high)
59
- assert_in_delta(bd1, bd2, Spectrum::COLOR_TOLERANCE)
60
- end
61
-
62
- def test_calculate_foreground
63
- assert_equal("#ffffff", @mcp1.calculate_foreground(@low, @high).html)
64
- assert_equal("#1d1b24", @mcp1.calculate_foreground(@high, @low).html)
65
- end
66
-
67
- def test_color_diff
68
- assert_in_delta(@mcp1.color_diff(@low, @high),
69
- @mcp1.color_diff(@high, @low),
70
- Spectrum::COLOR_TOLERANCE)
71
- end
72
-
73
- def test_foreground
74
- assert_equal("#c9e3a6", @mcp1.foreground[-5].html)
75
- assert_equal("#e4f1d3", @mcp1.foreground[-4].html) # e5f2d3
76
- assert_equal("#ffffff", @mcp1.foreground[-3].html)
77
- assert_equal("#000000", @mcp1.foreground[-2].html)
78
- assert_equal("#000000", @mcp1.foreground[-1].html)
79
- assert_equal("#000000", @mcp1.foreground[ 0].html)
80
- assert_equal("#000000", @mcp1.foreground[+1].html)
81
- assert_equal("#000000", @mcp1.foreground[+2].html)
82
- assert_equal("#32392a", @mcp1.foreground[+3].html)
83
- assert_equal("#32392a", @mcp1.foreground[+4].html)
84
- assert_equal("#32392a", @mcp1.foreground[+5].html)
85
-
86
- assert_equal("#bab5c7", @mcp2.foreground[-5].html) # bab6c7
87
- assert_equal("#dcdae3", @mcp2.foreground[-4].html)
88
- assert_equal("#ffffff", @mcp2.foreground[-3].html)
89
- assert_equal("#ffffff", @mcp2.foreground[-2].html)
90
- assert_equal("#ffffff", @mcp2.foreground[-1].html)
91
- assert_equal("#ffffff", @mcp2.foreground[ 0].html)
92
- assert_equal("#000000", @mcp2.foreground[+1].html)
93
- assert_equal("#000000", @mcp2.foreground[+2].html)
94
- assert_equal("#000000", @mcp2.foreground[+3].html)
95
- assert_equal("#1d1b24", @mcp2.foreground[+4].html)
96
- assert_equal("#3a3647", @mcp2.foreground[+5].html)
97
- end
98
-
99
- def test_minimum_brightness_diff
100
- assert_in_delta(MonoContrast::DEFAULT_MINIMUM_BRIGHTNESS_DIFF,
101
- @mcp1.minimum_brightness_diff, Spectrum::COLOR_TOLERANCE)
102
- end
103
-
104
- def test_minimum_brightness_diff_equals
105
- assert_in_delta(MonoContrast::DEFAULT_MINIMUM_BRIGHTNESS_DIFF,
106
- @mcp1.minimum_brightness_diff, Spectrum::COLOR_TOLERANCE)
107
- mcps = @mcp1.dup
108
- assert_nothing_raised { @mcp1.minimum_brightness_diff = 0.75 }
109
- assert_in_delta(0.75, @mcp1.minimum_brightness_diff, Spectrum::COLOR_TOLERANCE)
110
- assert_not_equal(@mcp1.foreground[-5], mcps.foreground[-5])
111
- assert_nothing_raised { @mcp1.minimum_brightness_diff = 4.0 }
112
- assert_in_delta(1, @mcp1.minimum_brightness_diff, Spectrum::COLOR_TOLERANCE)
113
- assert_nothing_raised { @mcp1.minimum_brightness_diff = -4.0 }
114
- assert_in_delta(0, @mcp1.minimum_brightness_diff, Spectrum::COLOR_TOLERANCE)
115
- assert_nothing_raised { @mcp1.minimum_brightness_diff = nil }
116
- assert_in_delta(MonoContrast::DEFAULT_MINIMUM_BRIGHTNESS_DIFF,
117
- @mcp1.minimum_brightness_diff, Spectrum::COLOR_TOLERANCE)
118
- end
119
-
120
- def test_minimum_color_diff
121
- assert_in_delta(MonoContrast::DEFAULT_MINIMUM_COLOR_DIFF,
122
- @mcp1.minimum_color_diff, Spectrum::COLOR_TOLERANCE)
123
- end
124
-
125
- def test_minimum_color_diff_equals
126
- assert_in_delta(MonoContrast::DEFAULT_MINIMUM_COLOR_DIFF,
127
- @mcp1.minimum_color_diff, Spectrum::COLOR_TOLERANCE)
128
- mcps = @mcp1.dup
129
- assert_nothing_raised { @mcp1.minimum_color_diff = 0.75 }
130
- assert_in_delta(0.75, @mcp1.minimum_color_diff, Spectrum::COLOR_TOLERANCE)
131
- assert_not_equal(@mcp1.foreground[-5], mcps.foreground[-5])
132
- assert_nothing_raised { @mcp1.minimum_color_diff = 4.0 }
133
- assert_in_delta(3, @mcp1.minimum_color_diff, Spectrum::COLOR_TOLERANCE)
134
- assert_nothing_raised { @mcp1.minimum_color_diff = -4.0 }
135
- assert_in_delta(0, @mcp1.minimum_color_diff, Spectrum::COLOR_TOLERANCE)
136
- assert_nothing_raised { @mcp1.minimum_color_diff = nil }
137
- assert_in_delta(MonoContrast::DEFAULT_MINIMUM_COLOR_DIFF,
138
- @mcp1.minimum_color_diff, Spectrum::COLOR_TOLERANCE)
139
- end
140
- end
141
- end
142
- end