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.
Files changed (52) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +301 -0
  3. data/CODE_OF_CONDUCT.md +128 -0
  4. data/CONTRIBUTING.md +70 -0
  5. data/CONTRIBUTORS.md +10 -0
  6. data/LICENCE.md +27 -0
  7. data/Manifest.txt +11 -23
  8. data/README.md +54 -0
  9. data/Rakefile +74 -61
  10. data/SECURITY.md +34 -0
  11. data/lib/color/cielab.rb +348 -0
  12. data/lib/color/cmyk.rb +279 -213
  13. data/lib/color/grayscale.rb +128 -160
  14. data/lib/color/hsl.rb +205 -173
  15. data/lib/color/rgb/colors.rb +177 -163
  16. data/lib/color/rgb.rb +536 -541
  17. data/lib/color/version.rb +5 -0
  18. data/lib/color/xyz.rb +214 -0
  19. data/lib/color/yiq.rb +91 -46
  20. data/lib/color.rb +208 -142
  21. data/test/fixtures/cielab.json +444 -0
  22. data/test/minitest_helper.rb +20 -4
  23. data/test/test_cmyk.rb +49 -72
  24. data/test/test_color.rb +58 -112
  25. data/test/test_grayscale.rb +35 -57
  26. data/test/test_hsl.rb +71 -77
  27. data/test/test_rgb.rb +195 -267
  28. data/test/test_yiq.rb +12 -30
  29. metadata +90 -107
  30. data/.autotest +0 -5
  31. data/.coveralls.yml +0 -2
  32. data/.gemtest +0 -0
  33. data/.hoerc +0 -2
  34. data/.minitest.rb +0 -2
  35. data/.travis.yml +0 -41
  36. data/Code-of-Conduct.rdoc +0 -41
  37. data/Contributing.rdoc +0 -62
  38. data/Gemfile +0 -9
  39. data/History.rdoc +0 -194
  40. data/Licence.rdoc +0 -27
  41. data/README.rdoc +0 -52
  42. data/lib/color/css.rb +0 -7
  43. data/lib/color/palette/adobecolor.rb +0 -260
  44. data/lib/color/palette/gimp.rb +0 -104
  45. data/lib/color/palette/monocontrast.rb +0 -164
  46. data/lib/color/palette.rb +0 -4
  47. data/lib/color/rgb/contrast.rb +0 -57
  48. data/lib/color/rgb/metallic.rb +0 -28
  49. data/test/test_adobecolor.rb +0 -405
  50. data/test/test_css.rb +0 -19
  51. data/test/test_gimp.rb +0 -87
  52. data/test/test_monocontrast.rb +0 -130
data/test/test_color.rb CHANGED
@@ -1,134 +1,80 @@
1
- # -*- ruby encoding: utf-8 -*-
1
+ # frozen_string_literal: true
2
2
 
3
- require 'color'
4
- require 'minitest_helper'
3
+ require "color"
4
+ require "minitest_helper"
5
5
 
6
6
  module TestColor
7
7
  class TestColor < Minitest::Test
8
8
  def setup
9
- Kernel.module_eval do
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 test_const
27
- $last_warn = nil
28
- assert_equal(Color::RGB::AliceBlue, Color::AliceBlue)
29
- assert_equal("Color::AliceBlue has been deprecated. Use Color::RGB::AliceBlue instead.", $last_warn)
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, Color.normalize(-7 * i))
61
- assert_equal(0.0, Color.normalize(-7 / i))
62
- assert_equal(0.0, Color.normalize(0 - i))
63
- assert_equal(1.0, Color.normalize(255 + i))
64
- assert_equal(1.0, Color.normalize(256 * i))
65
- assert_equal(1.0, Color.normalize(65536 / i))
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, Color.normalize(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 test_normalize_range
74
- assert_equal(0, Color.normalize_8bit(-1))
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(-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))
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 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)
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
- $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)
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
@@ -1,106 +1,84 @@
1
- # -*- ruby encoding: utf-8 -*-
1
+ # frozen_string_literal: true
2
2
 
3
- require 'color'
4
- require 'minitest_helper'
3
+ require "color"
4
+ require "minitest_helper"
5
5
 
6
6
  module TestColor
7
- class TestGrayScale < Minitest::Test
7
+ class TestGrayscale < Minitest::Test
8
8
  def setup
9
- @gs = Color::GrayScale.from_percent(33)
9
+ @gs = Color::Grayscale.from_percentage(33)
10
10
  end
11
11
 
12
12
  def test_brightness
13
- assert_in_delta(0.33, @gs.brightness, Color::COLOR_TOLERANCE)
13
+ assert_in_tolerance(0.33, @gs.brightness)
14
14
  end
15
15
 
16
16
  def test_darken_by
17
- assert_in_delta(29.7, @gs.darken_by(10).gray, Color::COLOR_TOLERANCE)
17
+ assert_in_tolerance(29.7, @gs.darken_by(10).gray)
18
18
  end
19
19
 
20
20
  def test_g
21
- assert_in_delta(0.33, @gs.g, Color::COLOR_TOLERANCE)
22
- assert_in_delta(33, @gs.grey, Color::COLOR_TOLERANCE)
23
- @gs.gray = 40
24
- assert_in_delta(0.4, @gs.g, Color::COLOR_TOLERANCE)
25
- @gs.g = 2.0
26
- assert_in_delta(100, @gs.gray, Color::COLOR_TOLERANCE)
27
- @gs.grey = -2.0
28
- assert_in_delta(0.0, @gs.g, Color::COLOR_TOLERANCE)
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 test_html_css
31
+ def test_css
32
32
  assert_equal("#545454", @gs.html)
33
- assert_equal("rgb(33.00%, 33.00%, 33.00%)", @gs.css_rgb)
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))
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
- assert_in_delta(0.363, @gs.lighten_by(10).g, Color::COLOR_TOLERANCE)
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
- assert_in_delta(0.0, cmyk.c, Color::COLOR_TOLERANCE)
51
- assert_in_delta(0.0, cmyk.m, Color::COLOR_TOLERANCE)
52
- assert_in_delta(0.0, cmyk.y, Color::COLOR_TOLERANCE)
53
- assert_in_delta(0.67, cmyk.k, Color::COLOR_TOLERANCE)
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.to_greyscale)
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
- assert_in_delta(0.0, hsl.h, Color::COLOR_TOLERANCE)
65
- assert_in_delta(0.0, hsl.s, Color::COLOR_TOLERANCE)
66
- assert_in_delta(0.33, hsl.l, Color::COLOR_TOLERANCE)
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
- assert_in_delta(0.33, rgb.r, Color::COLOR_TOLERANCE)
75
- assert_in_delta(0.33, rgb.g, Color::COLOR_TOLERANCE)
76
- assert_in_delta(0.33, rgb.b, Color::COLOR_TOLERANCE)
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
- assert_in_delta(0.33, yiq.y, Color::COLOR_TOLERANCE)
83
- assert_in_delta(0.0, yiq.i, Color::COLOR_TOLERANCE)
84
- assert_in_delta(0.0, yiq.q, Color::COLOR_TOLERANCE)
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("Gray [33.00%]", @gs.inspect)
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
- # -*- ruby encoding: utf-8 -*-
1
+ # frozen_string_literal: true
2
2
 
3
- require 'color'
4
- require 'minitest_helper'
3
+ require "color"
4
+ require "minitest_helper"
5
5
 
6
6
  module TestColor
7
7
  class TestHSL < Minitest::Test
8
8
  def setup
9
- # @hsl = Color::HSL.new(262, 67, 42)
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.new(262, 67, 42)
13
+ hsl = Color::HSL.from_values(262, 67, 42)
16
14
  c = hsl.to_rgb.to_hsl
17
- assert_in_delta hsl.h, c.h, Color::COLOR_TOLERANCE, "Hue"
18
- assert_in_delta hsl.s, c.s, Color::COLOR_TOLERANCE, "Saturation"
19
- assert_in_delta hsl.l, c.l, Color::COLOR_TOLERANCE, "Luminance"
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
- assert_in_delta 0.3, @hsl.brightness, Color::COLOR_TOLERANCE
21
+ assert_in_tolerance 0.3, @hsl.brightness
24
22
  end
25
23
 
26
24
  def test_hue
27
- assert_in_delta 0.4027, @hsl.h, Color::COLOR_TOLERANCE
28
- assert_in_delta 145, @hsl.hue, Color::COLOR_TOLERANCE
29
- @hsl.hue = 33
30
- assert_in_delta 0.09167, @hsl.h, Color::COLOR_TOLERANCE
31
- @hsl.hue = -33
32
- assert_in_delta 0.90833, @hsl.h, Color::COLOR_TOLERANCE
33
- @hsl.h = 3.3
34
- assert_in_delta 360, @hsl.hue, Color::COLOR_TOLERANCE
35
- @hsl.h = -3.3
36
- assert_in_delta 0.0, @hsl.h, Color::COLOR_TOLERANCE
37
- @hsl.hue = 0
38
- @hsl.hue -= 20
39
- assert_in_delta 340, @hsl.hue, Color::COLOR_TOLERANCE
40
- @hsl.hue += 45
41
- assert_in_delta 25, @hsl.hue, Color::COLOR_TOLERANCE
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
- assert_in_delta 0.2, @hsl.s, Color::COLOR_TOLERANCE
46
- assert_in_delta 20, @hsl.saturation, Color::COLOR_TOLERANCE
47
- @hsl.saturation = 33
48
- assert_in_delta 0.33, @hsl.s, Color::COLOR_TOLERANCE
49
- @hsl.s = 3.3
50
- assert_in_delta 100, @hsl.saturation, Color::COLOR_TOLERANCE
51
- @hsl.s = -3.3
52
- assert_in_delta 0.0, @hsl.s, Color::COLOR_TOLERANCE
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
- assert_in_delta 0.3, @hsl.l, Color::COLOR_TOLERANCE
57
- assert_in_delta 30, @hsl.luminosity, Color::COLOR_TOLERANCE
58
- @hsl.luminosity = 33
59
- assert_in_delta 0.33, @hsl.l, Color::COLOR_TOLERANCE
60
- @hsl.l = 3.3
61
- assert_in_delta 100, @hsl.lightness, Color::COLOR_TOLERANCE
62
- @hsl.l = -3.3
63
- assert_in_delta 0.0, @hsl.l, Color::COLOR_TOLERANCE
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 test_html_css
67
- assert_equal "hsl(145.00, 20.00%, 30.00%)", @hsl.css_hsl
68
- assert_equal "hsla(145.00, 20.00%, 30.00%, 1.00)", @hsl.css_hsla
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
- assert_in_delta 0.3223, cmyk.c, Color::COLOR_TOLERANCE
75
- assert_in_delta 0.2023, cmyk.m, Color::COLOR_TOLERANCE
76
- assert_in_delta 0.2723, cmyk.y, Color::COLOR_TOLERANCE
77
- assert_in_delta 0.4377, cmyk.k, Color::COLOR_TOLERANCE
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::GreyScale, gs
83
- assert_in_delta 30, gs.gray, Color::COLOR_TOLERANCE
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
- assert_in_delta 0.24, rgb.r, Color::COLOR_TOLERANCE
90
- assert_in_delta 0.36, rgb.g, Color::COLOR_TOLERANCE
91
- assert_in_delta 0.29, rgb.b, Color::COLOR_TOLERANCE
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 excercise some previously unexercised code in to_rgb.
99
- assert_equal Color::RGB::Black, Color::HSL.new(75, 75, 0)
100
- assert_equal Color::RGB::White, Color::HSL.new(75, 75, 100)
101
- assert_equal Color::RGB::Gray80, Color::HSL.new(75, 0, 80)
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.new(262, 67, 42).to_rgb
107
- assert_in_delta rgb.r, c.r, Color::COLOR_TOLERANCE, "Red"
108
- assert_in_delta rgb.g, c.g, Color::COLOR_TOLERANCE, "Green"
109
- assert_in_delta rgb.b, c.b, Color::COLOR_TOLERANCE, "Blue"
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
- assert_in_delta 0.3161, yiq.y, Color::COLOR_TOLERANCE
116
- assert_in_delta 0.0, yiq.i, Color::COLOR_TOLERANCE
117
- assert_in_delta 0.0, yiq.q, Color::COLOR_TOLERANCE
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 = Color::RGB::Red.to_hsl
122
- yellow = Color::RGB::Yellow.to_hsl
123
- assert_in_delta 0, red.hue, Color::COLOR_TOLERANCE
124
- assert_in_delta 60, yellow.hue, Color::COLOR_TOLERANCE
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
- assert_in_delta 15, ry25.hue, Color::COLOR_TOLERANCE
120
+ assert_in_tolerance 15, ry25.hue
127
121
  ry50 = red.mix_with yellow, 0.50
128
- assert_in_delta 30, ry50.hue, Color::COLOR_TOLERANCE
122
+ assert_in_tolerance 30, ry50.hue
129
123
  ry75 = red.mix_with yellow, 0.75
130
- assert_in_delta 45, ry75.hue, Color::COLOR_TOLERANCE
124
+ assert_in_tolerance 45, ry75.hue
131
125
  end
132
126
 
133
127
  def test_inspect
134
- assert_equal "HSL [145.00 deg, 20.00%, 30.00%]", @hsl.inspect
128
+ assert_equal "HSL [145.00deg 20.00% 30.00%]", @hsl.inspect
135
129
  end
136
130
  end
137
131
  end