File: test_yiq.rb

package info (click to toggle)
ruby-color 2.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 328 kB
  • sloc: ruby: 2,006; makefile: 5
file content (91 lines) | stat: -rw-r--r-- 2,118 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# frozen_string_literal: true

require "color"
require "minitest_helper"

module TestColor
  class TestYIQ < Minitest::Test
    def setup
      @yiq = Color::YIQ.from_fraction(0.1, 0.2, 0.3)
    end

    def test_brightness
      assert_in_tolerance(0.1, @yiq.brightness)
    end

    def test_i
      assert_in_tolerance(0.2, @yiq.i)
      assert_in_tolerance(0.2, @yiq.i)
    end

    def test_q
      assert_in_tolerance(0.3, @yiq.q)
      assert_in_tolerance(0.3, @yiq.q)
    end

    def test_y
      assert_in_tolerance(0.1, @yiq.y)
      assert_in_tolerance(0.1, @yiq.y)
    end

    def test_inspect
      assert_equal("YIQ [10.00% 20.00% 30.00%]", @yiq.inspect)
    end

    def test_pretty_print
      assert_pretty_inspect "YIQ\n[10.00%\n  20.00%\n  30.00%]\n", @yiq
    end
  end

  class TestYIQConversions < Minitest::Test
    def setup
      @yiq = Color::YIQ.from_fraction(0.1, 0.2, 0.3)
    end

    def test_to_cmyk
      skip("to_cmyk conversion not yet implemented")
      cmyk = @yiq.to_cmyk
      assert_kind_of(Color::CMYK, cmyk)
    end

    def test_to_grayscale
      gs = @yiq.to_grayscale
      assert_kind_of(Color::Grayscale, gs)
      assert_in_tolerance(0.1, gs.g)
      assert_equal(Color::Grayscale.from_fraction(0), Color::YIQ.from_values(0, 0, 0).to_grayscale)
    end

    def test_to_hsl
      skip("to_hsl conversion not yet implemented")
      hsl = @yiq.to_hsl
      assert_kind_of(Color::HSL, hsl)
    end

    def test_to_lab
      skip("to_lab conversion not yet implemented")
      lab = @yiq.to_lab
      assert_kind_of(Color::CIELAB, lab)
    end

    def test_to_rgb
      skip("to_rgb conversion not yet implemented")
      rgb = @yiq.to_rgb
      assert_kind_of(Color::RGB, rgb)
    end

    def test_to_xyz
      skip("to_xyz conversion not yet implemented")
      xyz = @yiq.to_xyz
      assert_kind_of(Color::XYZ, xyz)
    end

    def test_to_yiq
      assert_equal(@yiq, @yiq.to_yiq)
      assert_kind_of(Color::YIQ, @yiq.to_yiq)
    end

    def test_to_internal
      assert_equal([0.0, 0.0, 0.0], Color::YIQ.from_values(0, 0, 0).to_internal)
    end
  end
end