|
1 |
| -require "rmagick" |
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'rmagick' |
2 | 4 | require 'spec_helper'
|
3 | 5 | require_relative '../../lib/is_dark'
|
4 | 6 |
|
5 | 7 | TEST_FILE_PATH = 'color_card.pdf'
|
6 | 8 |
|
7 | 9 | describe IsDark do
|
8 |
| - |
9 |
| - describe ".color" do |
10 |
| - context "dark colors tests" do |
11 |
| - it "this color #000000 is dark, returns true" do |
| 10 | + describe '.color' do |
| 11 | + context 'dark colors tests' do |
| 12 | + it 'this color #000000 is dark, returns true' do |
12 | 13 | expect(IsDark.color('#000000')).to eq(true)
|
13 | 14 | end
|
14 | 15 |
|
15 |
| - it "this color #111111 is dark, returns true" do |
| 16 | + it 'this color #111111 is dark, returns true' do |
16 | 17 | expect(IsDark.color('#111111')).to eq(true)
|
17 | 18 | end
|
18 | 19 |
|
19 |
| - it "this color #102694 is dark, returns true" do |
| 20 | + it 'this color #102694 is dark, returns true' do |
20 | 21 | expect(IsDark.color('#102694')).to eq(true)
|
21 | 22 | end
|
22 | 23 |
|
23 |
| - it "this color #ff2e17 is dark, returns true" do |
| 24 | + it 'this color #ff2e17 is dark, returns true' do |
24 | 25 | expect(IsDark.color('#800f03')).to eq(true)
|
25 | 26 | end
|
26 | 27 | end
|
27 | 28 |
|
28 |
| - context "not dark colors tests" do |
29 |
| - it "this color is not dark, returns false" do |
| 29 | + context 'not dark colors tests' do |
| 30 | + it 'this color is not dark, returns false' do |
30 | 31 | expect(IsDark.color('#444444')).to eq(false)
|
31 | 32 | end
|
32 | 33 |
|
33 |
| - it "this color is not dark, returns false" do |
| 34 | + it 'this color is not dark, returns false' do |
34 | 35 | expect(IsDark.color('#888888')).to eq(false)
|
35 | 36 | end
|
36 | 37 |
|
37 |
| - it "this color is not dark, returns false" do |
| 38 | + it 'this color is not dark, returns false' do |
38 | 39 | expect(IsDark.color('#ffffff')).to eq(false)
|
39 | 40 | end
|
40 | 41 |
|
41 |
| - it "this color is not dark, returns false" do |
| 42 | + it 'this color is not dark, returns false' do |
42 | 43 | expect(IsDark.color('#fff6b2')).to eq(false)
|
43 | 44 | end
|
44 | 45 | end
|
45 | 46 | end
|
46 | 47 |
|
47 |
| - describe ".magick_pixel_from_blob" do |
48 |
| - context "test dark pixel" do |
49 |
| - it "this pixel is dark, returns true" do |
| 48 | + describe '.magick_pixel_from_blob' do |
| 49 | + context 'test dark pixel' do |
| 50 | + it 'this pixel is dark, returns true' do |
50 | 51 | x = 120
|
51 | 52 | y = 120
|
52 | 53 | expect(IsDark.magick_pixel_from_blob(x, y, TEST_FILE_PATH)).to eq(true)
|
53 | 54 | end
|
54 | 55 | end
|
55 | 56 |
|
56 |
| - context "test not dark pixel" do |
57 |
| - it "this pixel is not dark, returns false" do |
| 57 | + context 'test not dark pixel' do |
| 58 | + it 'this pixel is not dark, returns false' do |
58 | 59 | x = 720
|
59 | 60 | y = 120
|
60 | 61 | expect(IsDark.magick_pixel_from_blob(x, y, TEST_FILE_PATH)).to eq(false)
|
61 | 62 | end
|
62 | 63 | end
|
63 | 64 | end
|
64 | 65 |
|
65 |
| - describe ".magick_pixel" do |
66 |
| - context "test dark pixel" do |
67 |
| - it "this pixel is dark, returns true" do |
| 66 | + describe '.magick_pixel' do |
| 67 | + context 'test dark pixel' do |
| 68 | + it 'this pixel is dark, returns true' do |
68 | 69 | image = Magick::Image.read(TEST_FILE_PATH).first
|
69 | 70 | pix = image.pixel_color(80, 320)
|
70 | 71 | expect(IsDark.magick_pixel(pix)).to eq(true)
|
71 | 72 | end
|
72 | 73 | end
|
73 | 74 |
|
74 |
| - context "test not dark pixel" do |
75 |
| - it "this pixel is not dark, returns false" do |
| 75 | + context 'test not dark pixel' do |
| 76 | + it 'this pixel is not dark, returns false' do |
76 | 77 | image = Magick::Image.read(TEST_FILE_PATH).first
|
77 | 78 | pix = image.pixel_color(720, 120)
|
78 | 79 | expect(IsDark.magick_pixel(pix)).to eq(false)
|
79 | 80 | end
|
80 | 81 | end
|
81 | 82 | end
|
82 | 83 |
|
83 |
| - describe ".magick_area_from_blob" do |
84 |
| - context "test dark area" do |
85 |
| - it "this area is dark, returns true" do |
86 |
| - x = 120 #coordinate of a left corner of the area's rectangle X |
87 |
| - y = 120 #coordinate of a left corner of the area's rectangle Y |
88 |
| - cf_height = 64 #height of the area's rectangle |
89 |
| - cf_width = 128 #height of the area's rectangle |
90 |
| - percent = 70 #percent of detected dark pixels to invert |
91 |
| - matrix = (1..10) #matrix of dots. Range of matrix to build dots 1..10 - means 10x10 |
92 |
| - with_not_detected = false #Sometimes Imagick can't detect a pixel or it has no color, so it detects it as (RGB: 0,0,0), the gem has an option to consider pixels like this as "white", but if you need to disable this option add true or false |
93 |
| - expect(IsDark.magick_area_from_blob(x, y, TEST_FILE_PATH, cf_height, cf_width, percent, matrix, with_not_detected)).to eq(false) |
| 84 | + describe '.magick_area_from_blob' do |
| 85 | + context 'test dark area' do |
| 86 | + it 'this area is dark, returns true' do |
| 87 | + x = 120 # coordinate of a left corner of the area's rectangle X |
| 88 | + y = 120 # coordinate of a left corner of the area's rectangle Y |
| 89 | + cf_height = 64 # height of the area's rectangle |
| 90 | + cf_width = 128 # height of the area's rectangle |
| 91 | + percent = 70 # percent of detected dark pixels to invert |
| 92 | + matrix = (1..10) # matrix of dots. Range of matrix to build dots 1..10 - means 10x10 |
| 93 | + # Sometimes Imagick can't detect a pixel or it has no color, so it detects it as (RGB: 0,0,0), the gem has an |
| 94 | + # option to consider pixels like this as "white", but if you need to disable this option add true or false. |
| 95 | + with_not_detected = false |
| 96 | + expect(IsDark.magick_area_from_blob(x, y, TEST_FILE_PATH, cf_height, cf_width, percent, matrix, |
| 97 | + with_not_detected)).to eq(false) |
94 | 98 | end
|
95 | 99 | end
|
96 | 100 |
|
97 |
| - context "test bright area" do |
98 |
| - it "this area is not dark, returns false" do |
99 |
| - x = 720 #coordinate of a left corner of the area's rectangle X |
100 |
| - y = 120 #coordinate of a left corner of the area's rectangle Y |
101 |
| - cf_height = 64 #height of the area's rectangle |
102 |
| - cf_width = 128 #height of the area's rectangle |
103 |
| - percent = 70 #percent of detected dark pixels to invert |
104 |
| - matrix = (1..10) #matrix of dots. Range of matrix to build dots 1..10 - means 10x10 |
105 |
| - with_not_detected = false #Sometimes Imagick can't detect a pixel or it has no color, so it detects it as (RGB: 0,0,0), the gem has an option to consider pixels like this as "white", but if you need to disable this option add true or false |
106 |
| - expect(IsDark.magick_area_from_blob(x, y, TEST_FILE_PATH, cf_height, cf_width, percent, matrix, with_not_detected)).to eq(false) |
| 101 | + context 'test bright area' do |
| 102 | + it 'this area is not dark, returns false' do |
| 103 | + x = 720 # coordinate of a left corner of the area's rectangle X |
| 104 | + y = 120 # coordinate of a left corner of the area's rectangle Y |
| 105 | + cf_height = 64 # height of the area's rectangle |
| 106 | + cf_width = 128 # height of the area's rectangle |
| 107 | + percent = 70 # percent of detected dark pixels to invert |
| 108 | + matrix = (1..10) # matrix of dots. Range of matrix to build dots 1..10 - means 10x10 |
| 109 | + # Sometimes Imagick can't detect a pixel or it has no color, so it detects it as (RGB: 0,0,0), the gem has |
| 110 | + # an option to consider pixels like this as "white", but if you need to disable this option add true or false. |
| 111 | + with_not_detected = false |
| 112 | + expect(IsDark.magick_area_from_blob(x, y, TEST_FILE_PATH, cf_height, cf_width, percent, matrix, |
| 113 | + with_not_detected)).to eq(false) |
107 | 114 | end
|
108 | 115 | end
|
109 | 116 |
|
110 |
| - context "test debug output" do |
111 |
| - it "test area with logs and debug file" do |
112 |
| - x = 120 #coordinate of a left corner of the area's rectangle X |
113 |
| - y = 120 #coordinate of a left corner of the area's rectangle Y |
114 |
| - cf_height = 64 #height of the area's rectangle |
115 |
| - cf_width = 128 #height of the area's rectangle |
116 |
| - percent = 70 #percent of detected dark pixels to invert |
117 |
| - matrix = (1..10) #matrix of dots. Range of matrix to build dots 1..10 - means 10x10 |
118 |
| - with_not_detected = false #Sometimes Imagick can't detect a pixel or it has no color, so it detects it as (RGB: 0,0,0), the gem has an option to consider pixels like this as "white", but if you need to disable this option add true or false |
| 117 | + context 'test debug output' do |
| 118 | + it 'test area with logs and debug file' do |
| 119 | + x = 120 # coordinate of a left corner of the area's rectangle X |
| 120 | + y = 120 # coordinate of a left corner of the area's rectangle Y |
| 121 | + cf_height = 64 # height of the area's rectangle |
| 122 | + cf_width = 128 # height of the area's rectangle |
| 123 | + percent = 70 # percent of detected dark pixels to invert |
| 124 | + matrix = (1..10) # matrix of dots. Range of matrix to build dots 1..10 - means 10x10 |
| 125 | + # Sometimes Imagick can't detect a pixel or it has no color, so it detects it as (RGB: 0,0,0), the gem has |
| 126 | + # an option to consider pixels like this as "white", but if you need to disable this option add true or false. |
| 127 | + with_not_detected = false |
119 | 128 | IsDark.set_debug_data(true, './is_dark_debug_output.pdf')
|
120 |
| - expect(IsDark.magick_area_from_blob(x, y, TEST_FILE_PATH, cf_height, cf_width, percent, matrix, with_not_detected)).to eq(false) |
| 129 | + expect(IsDark.magick_area_from_blob(x, y, TEST_FILE_PATH, cf_height, cf_width, percent, matrix, |
| 130 | + with_not_detected)).to eq(false) |
121 | 131 | end
|
122 | 132 | end
|
123 | 133 | end
|
124 |
| - |
125 | 134 | end
|
0 commit comments