color 1.7.1 → 2.0.0.pre.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 (53) hide show
  1. checksums.yaml +5 -13
  2. data/CHANGELOG.md +298 -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 -21
  8. data/README.md +54 -0
  9. data/Rakefile +74 -53
  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 +534 -537
  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 -141
  21. data/test/fixtures/cielab.json +444 -0
  22. data/test/minitest_helper.rb +20 -4
  23. data/test/test_cmyk.rb +49 -71
  24. data/test/test_color.rb +58 -106
  25. data/test/test_grayscale.rb +35 -56
  26. data/test/test_hsl.rb +72 -76
  27. data/test/test_rgb.rb +195 -267
  28. data/test/test_yiq.rb +12 -30
  29. metadata +165 -150
  30. checksums.yaml.gz.sig +0 -0
  31. data/.autotest +0 -5
  32. data/.gemtest +0 -0
  33. data/.hoerc +0 -2
  34. data/.minitest.rb +0 -2
  35. data/.travis.yml +0 -35
  36. data/Contributing.rdoc +0 -60
  37. data/Gemfile +0 -9
  38. data/History.rdoc +0 -172
  39. data/Licence.rdoc +0 -27
  40. data/README.rdoc +0 -50
  41. data/lib/color/css.rb +0 -7
  42. data/lib/color/palette/adobecolor.rb +0 -260
  43. data/lib/color/palette/gimp.rb +0 -104
  44. data/lib/color/palette/monocontrast.rb +0 -164
  45. data/lib/color/palette.rb +0 -4
  46. data/lib/color/rgb/contrast.rb +0 -57
  47. data/lib/color/rgb/metallic.rb +0 -28
  48. data/test/test_adobecolor.rb +0 -405
  49. data/test/test_css.rb +0 -19
  50. data/test/test_gimp.rb +0 -87
  51. data/test/test_monocontrast.rb +0 -130
  52. data.tar.gz.sig +0 -0
  53. metadata.gz.sig +0 -0
data/test/test_color.rb CHANGED
@@ -1,128 +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
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
51
17
 
52
18
  def test_normalize
19
+ normalize = @subject.method(:normalize)
20
+
53
21
  (1..10).each do |i|
54
- assert_equal(0.0, Color.normalize(-7 * i))
55
- assert_equal(0.0, Color.normalize(-7 / i))
56
- assert_equal(0.0, Color.normalize(0 - i))
57
- assert_equal(1.0, Color.normalize(255 + i))
58
- assert_equal(1.0, Color.normalize(256 * i))
59
- 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))
60
28
  end
29
+
61
30
  (0..255).each do |i|
62
- assert_in_delta(i / 255.0, Color.normalize(i / 255.0),
63
- 1e-2)
31
+ assert_in_delta(i / 255.0, normalize.call(i / 255.0), 1e-2)
64
32
  end
65
33
  end
66
34
 
67
- def test_normalize_range
68
- assert_equal(0, Color.normalize_8bit(-1))
69
- assert_equal(0, Color.normalize_8bit(0))
70
- assert_equal(127, Color.normalize_8bit(127))
71
- assert_equal(172, Color.normalize_8bit(172))
72
- assert_equal(255, Color.normalize_8bit(255))
73
- assert_equal(255, Color.normalize_8bit(256))
74
-
75
- assert_equal(0, Color.normalize_16bit(-1))
76
- assert_equal(0, Color.normalize_16bit(0))
77
- assert_equal(127, Color.normalize_16bit(127))
78
- assert_equal(172, Color.normalize_16bit(172))
79
- assert_equal(255, Color.normalize_16bit(255))
80
- assert_equal(256, Color.normalize_16bit(256))
81
- assert_equal(65535, Color.normalize_16bit(65535))
82
- assert_equal(65535, Color.normalize_16bit(66536))
35
+ def test_normalize_byte
36
+ normalize_byte = @subject.method(:normalize_byte)
83
37
 
84
- assert_equal(-100, Color.normalize_to_range(-101, -100..100))
85
- assert_equal(-100, Color.normalize_to_range(-100.5, -100..100))
86
- assert_equal(-100, Color.normalize_to_range(-100, -100..100))
87
- assert_equal(-100, Color.normalize_to_range(-100.0, -100..100))
88
- assert_equal(-99.5, Color.normalize_to_range(-99.5, -100..100))
89
- assert_equal(-50, Color.normalize_to_range(-50, -100..100))
90
- assert_equal(-50.5, Color.normalize_to_range(-50.5, -100..100))
91
- assert_equal(0, Color.normalize_to_range(0, -100..100))
92
- assert_equal(50, Color.normalize_to_range(50, -100..100))
93
- assert_equal(50.5, Color.normalize_to_range(50.5, -100..100))
94
- assert_equal(99, Color.normalize_to_range(99, -100..100))
95
- assert_equal(99.5, Color.normalize_to_range(99.5, -100..100))
96
- assert_equal(100, Color.normalize_to_range(100, -100..100))
97
- assert_equal(100, Color.normalize_to_range(100.0, -100..100))
98
- assert_equal(100, Color.normalize_to_range(100.5, -100..100))
99
- 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))
100
44
  end
101
45
 
102
- def test_new
103
- $last_warn = nil
104
- c = Color.new("#fff")
105
- assert_kind_of(Color::HSL, c)
106
- assert_equal(Color::RGB::White.to_hsl, c)
107
- assert_equal("Color.new has been deprecated. Use Color::RGB.new instead.", $last_warn)
108
-
109
- $last_warn = nil
110
- c = Color.new([0, 0, 0])
111
- assert_kind_of(Color::HSL, c)
112
- assert_equal(Color::RGB::Black.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([10, 20, 30], :hsl)
117
- assert_kind_of(Color::HSL, c)
118
- assert_equal(Color::HSL.new(10, 20, 30), c)
119
- 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
120
58
 
121
- $last_warn = nil
122
- c = Color.new([10, 20, 30, 40], :cmyk)
123
- assert_kind_of(Color::HSL, c)
124
- assert_equal(Color::CMYK.new(10, 20, 30, 40).to_hsl, c)
125
- 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))
126
78
  end
127
79
  end
128
80
  end
@@ -1,105 +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)
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))
35
36
  end
36
37
 
37
38
  def test_lighten_by
38
- assert_in_delta(0.363, @gs.lighten_by(10).g, Color::COLOR_TOLERANCE)
39
- end
40
-
41
- def test_pdf_fill
42
- assert_equal("0.330 g", @gs.pdf_fill)
43
- assert_equal("0.330 G", @gs.pdf_stroke)
39
+ assert_in_tolerance(0.363, @gs.lighten_by(10).g)
44
40
  end
45
41
 
46
42
  def test_to_cmyk
47
43
  cmyk = @gs.to_cmyk
48
44
  assert_kind_of(Color::CMYK, cmyk)
49
- assert_in_delta(0.0, cmyk.c, Color::COLOR_TOLERANCE)
50
- assert_in_delta(0.0, cmyk.m, Color::COLOR_TOLERANCE)
51
- assert_in_delta(0.0, cmyk.y, Color::COLOR_TOLERANCE)
52
- 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)
53
49
  end
54
50
 
55
51
  def test_to_grayscale
56
52
  assert_equal(@gs, @gs.to_grayscale)
57
- assert_equal(@gs, @gs.to_greyscale)
53
+ assert_equal(@gs, @gs.to_grayscale)
58
54
  end
59
55
 
60
56
  def test_to_hsl
61
57
  hsl = @gs.to_hsl
62
58
  assert_kind_of(Color::HSL, hsl)
63
- assert_in_delta(0.0, hsl.h, Color::COLOR_TOLERANCE)
64
- assert_in_delta(0.0, hsl.s, Color::COLOR_TOLERANCE)
65
- assert_in_delta(0.33, hsl.l, Color::COLOR_TOLERANCE)
66
- assert_equal("hsl(0.00, 0.00%, 33.00%)", @gs.css_hsl)
67
- 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)
68
62
  end
69
63
 
70
64
  def test_to_rgb
71
65
  rgb = @gs.to_rgb
72
66
  assert_kind_of(Color::RGB, rgb)
73
- assert_in_delta(0.33, rgb.r, Color::COLOR_TOLERANCE)
74
- assert_in_delta(0.33, rgb.g, Color::COLOR_TOLERANCE)
75
- 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)
76
70
  end
77
71
 
78
72
  def test_to_yiq
79
73
  yiq = @gs.to_yiq
80
74
  assert_kind_of(Color::YIQ, yiq)
81
- assert_in_delta(0.33, yiq.y, Color::COLOR_TOLERANCE)
82
- assert_in_delta(0.0, yiq.i, Color::COLOR_TOLERANCE)
83
- assert_in_delta(0.0, yiq.q, Color::COLOR_TOLERANCE)
84
- end
85
-
86
- def test_add
87
- delta = @gs + Color::GrayScale.new(20)
88
- max = @gs + Color::GrayScale.new(80)
89
-
90
- assert_in_delta(1.0, max.g, Color::COLOR_TOLERANCE)
91
- assert_in_delta(0.53, delta.g, Color::COLOR_TOLERANCE)
92
- end
93
-
94
- def test_subtract
95
- delta = @gs - Color::GrayScale.new(20)
96
- max = @gs - Color::GrayScale.new(80)
97
- assert_in_delta(0.0, max.g, Color::COLOR_TOLERANCE)
98
- 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)
99
78
  end
100
79
 
101
80
  def test_inspect
102
- assert_equal("Gray [33.00%]", @gs.inspect)
81
+ assert_equal("Grayscale [33.00%]", @gs.inspect)
103
82
  end
104
83
  end
105
84
  end
data/test/test_hsl.rb CHANGED
@@ -1,135 +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
87
+ assert_in_tolerance 0.24, rgb.r
88
+ assert_in_tolerance 0.36, rgb.g
89
+ assert_in_tolerance 0.29, rgb.b
90
+
95
91
  # The following tests address a bug reported by Jean Krohn on June 6,
96
- # 2006 and excercise some previously unexercised code in to_rgb.
97
- assert_equal Color::RGB::Black, Color::HSL.new(75, 75, 0)
98
- assert_equal Color::RGB::White, Color::HSL.new(75, 75, 100)
99
- 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)
100
96
 
101
97
  # The following tests a bug reported by Adam Johnson on 29 October
102
98
  # 2010.
103
99
  rgb = Color::RGB.from_fraction(0.34496, 0.1386, 0.701399)
104
- c = Color::HSL.new(262, 67, 42).to_rgb
105
- assert_in_delta rgb.r, c.r, Color::COLOR_TOLERANCE, "Red"
106
- assert_in_delta rgb.g, c.g, Color::COLOR_TOLERANCE, "Green"
107
- 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"
108
104
  end
109
105
 
110
106
  def test_to_yiq
111
107
  yiq = @hsl.to_yiq
112
108
  assert_kind_of Color::YIQ, yiq
113
- assert_in_delta 0.3161, yiq.y, Color::COLOR_TOLERANCE
114
- assert_in_delta 0.0, yiq.i, Color::COLOR_TOLERANCE
115
- 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
116
112
  end
117
113
 
118
114
  def test_mix_with
119
- red = Color::RGB::Red.to_hsl
120
- yellow = Color::RGB::Yellow.to_hsl
121
- assert_in_delta 0, red.hue, Color::COLOR_TOLERANCE
122
- 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
123
119
  ry25 = red.mix_with yellow, 0.25
124
- assert_in_delta 15, ry25.hue, Color::COLOR_TOLERANCE
120
+ assert_in_tolerance 15, ry25.hue
125
121
  ry50 = red.mix_with yellow, 0.50
126
- assert_in_delta 30, ry50.hue, Color::COLOR_TOLERANCE
122
+ assert_in_tolerance 30, ry50.hue
127
123
  ry75 = red.mix_with yellow, 0.75
128
- assert_in_delta 45, ry75.hue, Color::COLOR_TOLERANCE
124
+ assert_in_tolerance 45, ry75.hue
129
125
  end
130
126
 
131
127
  def test_inspect
132
- assert_equal "HSL [145.00 deg, 20.00%, 30.00%]", @hsl.inspect
128
+ assert_equal "HSL [145.00deg 20.00% 30.00%]", @hsl.inspect
133
129
  end
134
130
  end
135
131
  end