pnm 0.5.1 → 0.5.2

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.
@@ -1,234 +1,236 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # test_exceptions.rb: Unit tests for the PNM library.
2
4
  #
3
- # Copyright (C) 2013-2016 Marcus Stollsteimer
5
+ # Copyright (C) 2013-2019 Marcus Stollsteimer
4
6
 
5
- require 'minitest/autorun'
6
- require 'stringio'
7
- require 'pnm'
7
+ require "minitest/autorun"
8
+ require "stringio"
9
+ require "pnm"
8
10
 
9
11
 
10
- describe 'PNM.create' do
12
+ describe "PNM.create" do
11
13
 
12
- it 'raises an exception for invalid data type (String)' do
13
- data = '0'
14
- lambda { PNM.create(data) }.must_raise PNM::ArgumentError
14
+ it "raises an exception for invalid data type (String)" do
15
+ data = "0"
16
+ proc { PNM.create(data) }.must_raise PNM::ArgumentError
15
17
  end
16
18
 
17
- it 'raises an exception for invalid type' do
19
+ it "raises an exception for invalid type" do
18
20
  data = [[0, 0], [0, 0]]
19
- lambda { PNM.create(data, :type => :abc) }.must_raise PNM::ArgumentError
21
+ proc { PNM.create(data, type: :abc) }.must_raise PNM::ArgumentError
20
22
  end
21
23
 
22
- it 'raises an exception for invalid maxgray (String)' do
24
+ it "raises an exception for invalid maxgray (String)" do
23
25
  data = [[0, 0], [0, 0]]
24
- lambda { PNM.create(data, :maxgray => '255') }.must_raise PNM::ArgumentError
26
+ proc { PNM.create(data, maxgray: "255") }.must_raise PNM::ArgumentError
25
27
  end
26
28
 
27
- it 'raises an exception for invalid maxgray (> 255)' do
29
+ it "raises an exception for invalid maxgray (> 255)" do
28
30
  data = [[0, 0], [0, 0]]
29
- lambda { PNM.create(data, :maxgray => 256) }.must_raise PNM::ArgumentError
31
+ proc { PNM.create(data, maxgray: 256) }.must_raise PNM::ArgumentError
30
32
  end
31
33
 
32
- it 'raises an exception for invalid maxgray (0)' do
34
+ it "raises an exception for invalid maxgray (0)" do
33
35
  data = [[0, 0], [0, 0]]
34
- lambda { PNM.create(data, :maxgray => 0) }.must_raise PNM::ArgumentError
36
+ proc { PNM.create(data, maxgray: 0) }.must_raise PNM::ArgumentError
35
37
  end
36
38
 
37
- it 'raises an exception for invalid comment (Integer)' do
39
+ it "raises an exception for invalid comment (Integer)" do
38
40
  data = [[0, 0], [0, 0]]
39
- lambda { PNM.create(data, :comment => 1) }.must_raise PNM::ArgumentError
41
+ proc { PNM.create(data, comment: 1) }.must_raise PNM::ArgumentError
40
42
  end
41
43
 
42
- it 'raises an exception for image type and data mismatch (PBM)' do
43
- data = [[[0,0,0], [0,0,0]], [[0,0,0], [0,0,0]]]
44
- lambda { PNM.create(data, :type => :pbm) }.must_raise PNM::DataError
44
+ it "raises an exception for image type and data mismatch (PBM)" do
45
+ data = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 0], [0, 0, 0]]]
46
+ proc { PNM.create(data, type: :pbm) }.must_raise PNM::DataError
45
47
  end
46
48
 
47
- it 'raises an exception for image type and data mismatch (PGM)' do
48
- data = [[[0,0,0], [0,0,0]], [[0,0,0], [0,0,0]]]
49
- lambda { PNM.create(data, :type => :pgm) }.must_raise PNM::DataError
49
+ it "raises an exception for image type and data mismatch (PGM)" do
50
+ data = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 0], [0, 0, 0]]]
51
+ proc { PNM.create(data, type: :pgm) }.must_raise PNM::DataError
50
52
  end
51
53
 
52
- it 'raises an exception for non-integer pixel value (String)' do
53
- data = [[0, 0], ['X', 0]]
54
- lambda { PNM.create(data) }.must_raise PNM::DataError
54
+ it "raises an exception for non-integer pixel value (String)" do
55
+ data = [[0, 0], ["X", 0]]
56
+ proc { PNM.create(data) }.must_raise PNM::DataError
55
57
  end
56
58
 
57
- it 'raises an exception for non-integer pixel value (Float)' do
59
+ it "raises an exception for non-integer pixel value (Float)" do
58
60
  data = [[0, 0], [0.5, 0]]
59
- lambda { PNM.create(data) }.must_raise PNM::DataError
61
+ proc { PNM.create(data) }.must_raise PNM::DataError
60
62
  end
61
63
 
62
- it 'raises an exception for rows of different size' do
64
+ it "raises an exception for rows of different size" do
63
65
  data = [[0, 0], [0, 0, 0]]
64
- lambda { PNM.create(data) }.must_raise PNM::DataError
66
+ proc { PNM.create(data) }.must_raise PNM::DataError
65
67
  end
66
68
 
67
- it 'raises an exception for invalid array dimensions (#1)' do
69
+ it "raises an exception for invalid array dimensions (#1)" do
68
70
  data = [0, 0, 0]
69
- lambda { PNM.create(data) }.must_raise PNM::DataError
71
+ proc { PNM.create(data) }.must_raise PNM::DataError
70
72
  end
71
73
 
72
- it 'raises an exception for invalid array dimensions (#2)' do
74
+ it "raises an exception for invalid array dimensions (#2)" do
73
75
  data = [[0, 0], 0, 0]
74
- lambda { PNM.create(data) }.must_raise PNM::DataError
76
+ proc { PNM.create(data) }.must_raise PNM::DataError
75
77
  end
76
78
 
77
- it 'raises an exception for invalid array dimensions (#3)' do
79
+ it "raises an exception for invalid array dimensions (#3)" do
78
80
  data = [[0, 0], [0, [0, 0]]]
79
- lambda { PNM.create(data) }.must_raise PNM::DataError
81
+ proc { PNM.create(data) }.must_raise PNM::DataError
80
82
  end
81
83
 
82
- it 'raises an exception for invalid array dimensions (#4)' do
83
- data = [[[0,0], [0,0]], [[0,0], [0,0]]]
84
- lambda { PNM.create(data) }.must_raise PNM::DataError
84
+ it "raises an exception for invalid array dimensions (#4)" do
85
+ data = [[[0, 0], [0, 0]], [[0, 0], [0, 0]]]
86
+ proc { PNM.create(data) }.must_raise PNM::DataError
85
87
  end
86
88
 
87
- it 'raises an exception for invalid array dimensions (#5)' do
88
- data = [[[0,0,0], [0,0,0]], [0 ,0]]
89
- lambda { PNM.create(data) }.must_raise PNM::DataError
89
+ it "raises an exception for invalid array dimensions (#5)" do
90
+ data = [[[0, 0, 0], [0, 0, 0]], [0, 0]]
91
+ proc { PNM.create(data) }.must_raise PNM::DataError
90
92
  end
91
93
 
92
- it 'raises an exception for invalid array dimensions (#6)' do
93
- data = [[[0,0,0], 0], [0 ,0]]
94
- lambda { PNM.create(data) }.must_raise PNM::DataError
94
+ it "raises an exception for invalid array dimensions (#6)" do
95
+ data = [[[0, 0, 0], 0], [0, 0]]
96
+ proc { PNM.create(data) }.must_raise PNM::DataError
95
97
  end
96
98
 
97
- it 'raises an exception for an empty array' do
99
+ it "raises an exception for an empty array" do
98
100
  data = [[]]
99
- lambda { PNM.create(data) }.must_raise PNM::DataError
101
+ proc { PNM.create(data) }.must_raise PNM::DataError
100
102
  end
101
103
 
102
- it 'raises an exception for invalid PBM data (> 1)' do
104
+ it "raises an exception for invalid PBM data (> 1)" do
103
105
  data = [[0, 0], [2, 0]]
104
- lambda { PNM.create(data, :type => :pbm) }.must_raise PNM::DataError
106
+ proc { PNM.create(data, type: :pbm) }.must_raise PNM::DataError
105
107
  end
106
108
 
107
- it 'raises an exception for invalid PBM data (< 0)' do
109
+ it "raises an exception for invalid PBM data (< 0)" do
108
110
  data = [[0, 0], [-1, 0]]
109
- lambda { PNM.create(data, :type => :pbm) }.must_raise PNM::DataError
111
+ proc { PNM.create(data, type: :pbm) }.must_raise PNM::DataError
110
112
  end
111
113
 
112
- it 'raises an exception for invalid PGM data (> 255)' do
114
+ it "raises an exception for invalid PGM data (> 255)" do
113
115
  data = [[0, 0], [1, 500]]
114
- lambda { PNM.create(data, :type => :pgm) }.must_raise PNM::DataError
116
+ proc { PNM.create(data, type: :pgm) }.must_raise PNM::DataError
115
117
  end
116
118
 
117
- it 'raises an exception for invalid PGM data (> maxgray)' do
119
+ it "raises an exception for invalid PGM data (> maxgray)" do
118
120
  data = [[0, 0], [1, 200]]
119
- lambda { PNM.create(data, :maxgray => 100) }.must_raise PNM::DataError
121
+ proc { PNM.create(data, maxgray: 100) }.must_raise PNM::DataError
120
122
  end
121
123
  end
122
124
 
123
125
 
124
- describe 'PNM.read' do
126
+ describe "PNM.read" do
125
127
 
126
- it 'raises an exception for integer argument' do
127
- lambda { PNM.read(123) }.must_raise PNM::ArgumentError
128
+ it "raises an exception for integer argument" do
129
+ proc { PNM.read(123) }.must_raise PNM::ArgumentError
128
130
  end
129
131
 
130
- it 'raises an exception for unknown magic number' do
131
- file = StringIO.new('P0 1 1 0')
132
- lambda { PNM.read(file) }.must_raise PNM::ParserError
132
+ it "raises an exception for unknown magic number" do
133
+ file = StringIO.new("P0 1 1 0")
134
+ proc { PNM.read(file) }.must_raise PNM::ParserError
133
135
  end
134
136
 
135
- it 'raises an exception for an empty file' do
136
- file = StringIO.new('')
137
- lambda { PNM.read(file) }.must_raise PNM::ParserError
137
+ it "raises an exception for an empty file" do
138
+ file = StringIO.new("")
139
+ proc { PNM.read(file) }.must_raise PNM::ParserError
138
140
  end
139
141
 
140
- it 'raises an exception for missing tokens (#1)' do
141
- file = StringIO.new('P1')
142
- lambda { PNM.read(file) }.must_raise PNM::ParserError
142
+ it "raises an exception for missing tokens (#1)" do
143
+ file = StringIO.new("P1")
144
+ proc { PNM.read(file) }.must_raise PNM::ParserError
143
145
  end
144
146
 
145
- it 'raises an exception for missing tokens (#2)' do
146
- file = StringIO.new('P1 1')
147
- lambda { PNM.read(file) }.must_raise PNM::ParserError
147
+ it "raises an exception for missing tokens (#2)" do
148
+ file = StringIO.new("P1 1")
149
+ proc { PNM.read(file) }.must_raise PNM::ParserError
148
150
  end
149
151
 
150
- it 'raises an exception for missing tokens (#3)' do
151
- file = StringIO.new('P1 1 ')
152
- lambda { PNM.read(file) }.must_raise PNM::ParserError
152
+ it "raises an exception for missing tokens (#3)" do
153
+ file = StringIO.new("P1 1 ")
154
+ proc { PNM.read(file) }.must_raise PNM::ParserError
153
155
  end
154
156
 
155
- it 'raises an exception for missing tokens (#4)' do
156
- file = StringIO.new('P1 1 1')
157
- lambda { PNM.read(file) }.must_raise PNM::ParserError
157
+ it "raises an exception for missing tokens (#4)" do
158
+ file = StringIO.new("P1 1 1")
159
+ proc { PNM.read(file) }.must_raise PNM::ParserError
158
160
  end
159
161
 
160
- it 'raises an exception for missing tokens (#5)' do
162
+ it "raises an exception for missing tokens (#5)" do
161
163
  file = StringIO.new("P1 1 # Test\n 1")
162
- lambda { PNM.read(file) }.must_raise PNM::ParserError
164
+ proc { PNM.read(file) }.must_raise PNM::ParserError
163
165
  end
164
166
 
165
- it 'raises an exception for missing tokens (#6)' do
167
+ it "raises an exception for missing tokens (#6)" do
166
168
  file = StringIO.new("P2 1 1 255")
167
- lambda { PNM.read(file) }.must_raise PNM::ParserError
169
+ proc { PNM.read(file) }.must_raise PNM::ParserError
168
170
  end
169
171
 
170
- it 'raises an exception for token of wrong type (#1)' do
171
- file = StringIO.new('P1 ? 1 0')
172
- lambda { PNM.read(file) }.must_raise PNM::ParserError
172
+ it "raises an exception for token of wrong type (#1)" do
173
+ file = StringIO.new("P1 ? 1 0")
174
+ proc { PNM.read(file) }.must_raise PNM::ParserError
173
175
  end
174
176
 
175
- it 'raises an exception for token of wrong type (#2)' do
176
- file = StringIO.new('P1 1 X 0')
177
- lambda { PNM.read(file) }.must_raise PNM::ParserError
177
+ it "raises an exception for token of wrong type (#2)" do
178
+ file = StringIO.new("P1 1 X 0")
179
+ proc { PNM.read(file) }.must_raise PNM::ParserError
178
180
  end
179
181
 
180
- it 'raises an exception for token of wrong type (#3)' do
181
- file = StringIO.new('P2 1 1 foo 0')
182
- lambda { PNM.read(file) }.must_raise PNM::ParserError
182
+ it "raises an exception for token of wrong type (#3)" do
183
+ file = StringIO.new("P2 1 1 foo 0")
184
+ proc { PNM.read(file) }.must_raise PNM::ParserError
183
185
  end
184
186
 
185
- it 'raises an exception for zero width' do
186
- file = StringIO.new('P2 0 1 255 0')
187
- lambda { PNM.read(file) }.must_raise PNM::ParserError
187
+ it "raises an exception for zero width" do
188
+ file = StringIO.new("P2 0 1 255 0")
189
+ proc { PNM.read(file) }.must_raise PNM::ParserError
188
190
  end
189
191
 
190
- it 'raises an exception for zero height' do
191
- file = StringIO.new('P2 1 0 255 0')
192
- lambda { PNM.read(file) }.must_raise PNM::ParserError
192
+ it "raises an exception for zero height" do
193
+ file = StringIO.new("P2 1 0 255 0")
194
+ proc { PNM.read(file) }.must_raise PNM::ParserError
193
195
  end
194
196
 
195
- it 'raises an exception for invalid maxgray (> 255)' do
196
- file = StringIO.new('P2 1 1 256 0')
197
- lambda { PNM.read(file) }.must_raise PNM::ParserError
197
+ it "raises an exception for invalid maxgray (> 255)" do
198
+ file = StringIO.new("P2 1 1 256 0")
199
+ proc { PNM.read(file) }.must_raise PNM::ParserError
198
200
  end
199
201
 
200
- it 'raises an exception for invalid maxgray (0)' do
201
- file = StringIO.new('P2 1 1 0 0')
202
- lambda { PNM.read(file) }.must_raise PNM::ParserError
202
+ it "raises an exception for invalid maxgray (0)" do
203
+ file = StringIO.new("P2 1 1 0 0")
204
+ proc { PNM.read(file) }.must_raise PNM::ParserError
203
205
  end
204
206
 
205
- it 'raises an exception for image dimension mismatch (#1)' do
206
- file = StringIO.new('P1 2 3 0 0 0 0 0')
207
- lambda { PNM.read(file) }.must_raise PNM::DataSizeError
207
+ it "raises an exception for image dimension mismatch (#1)" do
208
+ file = StringIO.new("P1 2 3 0 0 0 0 0")
209
+ proc { PNM.read(file) }.must_raise PNM::DataSizeError
208
210
  end
209
211
 
210
- it 'raises an exception for image dimension mismatch (#2)' do
211
- file = StringIO.new('P1 2 3 0 0 0 0 0 0 0')
212
- lambda { PNM.read(file) }.must_raise PNM::DataSizeError
212
+ it "raises an exception for image dimension mismatch (#2)" do
213
+ file = StringIO.new("P1 2 3 0 0 0 0 0 0 0")
214
+ proc { PNM.read(file) }.must_raise PNM::DataSizeError
213
215
  end
214
216
 
215
- it 'raises an exception for image dimension mismatch (#3)' do
216
- file = StringIO.new('P3 2 3 255 0 0 0 0 0 0')
217
- lambda { PNM.read(file) }.must_raise PNM::DataSizeError
217
+ it "raises an exception for image dimension mismatch (#3)" do
218
+ file = StringIO.new("P3 2 3 255 0 0 0 0 0 0")
219
+ proc { PNM.read(file) }.must_raise PNM::DataSizeError
218
220
  end
219
221
 
220
- it 'raises an exception for image dimension mismatch (#4)' do
221
- file = StringIO.new('P5 2 3 255 AAAAAAA')
222
- lambda { PNM.read(file) }.must_raise PNM::DataSizeError
222
+ it "raises an exception for image dimension mismatch (#4)" do
223
+ file = StringIO.new("P5 2 3 255 AAAAAAA")
224
+ proc { PNM.read(file) }.must_raise PNM::DataSizeError
223
225
  end
224
226
 
225
- it 'raises an exception for image dimension mismatch (#5)' do
226
- file = StringIO.new('P5 2 3 255 AAAAAAA')
227
- lambda { PNM.read(file) }.must_raise PNM::DataSizeError
227
+ it "raises an exception for image dimension mismatch (#5)" do
228
+ file = StringIO.new("P5 2 3 255 AAAAAAA")
229
+ proc { PNM.read(file) }.must_raise PNM::DataSizeError
228
230
  end
229
231
 
230
- it 'raises an exception for non-numeric image data' do
231
- file = StringIO.new('P1 2 3 0 X 0 0 0 0')
232
- lambda { PNM.read(file) }.must_raise PNM::DataError
232
+ it "raises an exception for non-numeric image data" do
233
+ file = StringIO.new("P1 2 3 0 X 0 0 0 0")
234
+ proc { PNM.read(file) }.must_raise PNM::DataError
233
235
  end
234
236
  end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # test_image.rb: Unit tests for the PNM library.
2
4
  #
3
- # Copyright (C) 2013-2016 Marcus Stollsteimer
5
+ # Copyright (C) 2013-2019 Marcus Stollsteimer
4
6
 
5
- require 'minitest/autorun'
6
- require 'pnm'
7
+ require "minitest/autorun"
8
+ require "pnm"
7
9
 
8
10
 
9
11
  describe PNM::Image do
@@ -12,261 +14,261 @@ describe PNM::Image do
12
14
  @srcpath = File.dirname(__FILE__)
13
15
  @temp_path = File.expand_path("#{@srcpath}/temp.pnm")
14
16
 
15
- pixels = [[0,0,0,0,0],
16
- [0,1,1,1,0],
17
- [0,0,1,0,0],
18
- [0,0,1,0,0],
19
- [0,0,1,0,0],
20
- [0,0,0,0,0]]
21
- comment = 'Bilevel'
22
- @bilevel = PNM.create(pixels, {:comment => comment})
23
-
24
- pixels = [[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
25
- [0,1,1,1,0,1,1,1,1,0,1,1,1,1,1,0],
26
- [0,0,1,0,0,1,0,0,1,0,1,0,1,0,1,0],
27
- [0,0,1,0,0,1,0,0,1,0,1,0,1,0,1,0],
28
- [0,0,1,0,0,1,1,1,1,0,1,0,1,0,1,0],
29
- [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]
30
- @bilevel_2 = PNM.create(pixels)
31
-
32
- pixels = [[ 0, 50,100,150],
33
- [ 50,100,150,200],
34
- [100,150,200,250]]
17
+ pixels = [[0, 0, 0, 0, 0],
18
+ [0, 1, 1, 1, 0],
19
+ [0, 0, 1, 0, 0],
20
+ [0, 0, 1, 0, 0],
21
+ [0, 0, 1, 0, 0],
22
+ [0, 0, 0, 0, 0]]
23
+ comment = "Bilevel"
24
+ @bilevel = PNM.create(pixels, comment: comment)
25
+
26
+ pixels = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
27
+ [0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0],
28
+ [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0],
29
+ [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0],
30
+ [0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0],
31
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
32
+ @bilevel2 = PNM.create(pixels)
33
+
34
+ pixels = [[ 0, 50, 100, 150],
35
+ [ 50, 100, 150, 200],
36
+ [100, 150, 200, 250]]
35
37
  comment = "Grayscale\n(with multiline comment)"
36
- @grayscale = PNM.create(pixels, {:maxgray => 250, :comment => comment})
38
+ @grayscale = PNM.create(pixels, maxgray: 250, comment: comment)
37
39
 
38
- pixels = [[65,66], [13,10], [65,66]]
40
+ pixels = [[65, 66], [13, 10], [65, 66]]
39
41
  @grayscale_crlf = PNM.create(pixels)
40
42
 
41
- pixels = [[[0,6,0], [1,5,1], [2,4,2], [3,3,4], [4,2,6]],
42
- [[1,5,2], [2,4,2], [3,3,2], [4,2,2], [5,1,2]],
43
- [[2,4,6], [3,3,4], [4,2,2], [5,1,1], [6,0,0]]]
44
- @color = PNM.create(pixels, {:maxgray => 6})
43
+ pixels = [[[0, 6, 0], [1, 5, 1], [2, 4, 2], [3, 3, 4], [4, 2, 6]],
44
+ [[1, 5, 2], [2, 4, 2], [3, 3, 2], [4, 2, 2], [5, 1, 2]],
45
+ [[2, 4, 6], [3, 3, 4], [4, 2, 2], [5, 1, 1], [6, 0, 0]]]
46
+ @color = PNM.create(pixels, maxgray: 6)
45
47
  end
46
48
 
47
- it 'freezes pixel data' do
48
- lambda { @bilevel.pixels << [1,1,0,1,1] }.must_raise RuntimeError
49
+ it "freezes pixel data" do
50
+ proc { @bilevel.pixels << [1, 1, 0, 1, 1] }.must_raise RuntimeError
49
51
  end
50
52
 
51
- it 'freezes comment string' do
52
- lambda { @bilevel.comment << "string" }.must_raise RuntimeError
53
+ it "freezes comment string" do
54
+ proc { @bilevel.comment << "string" }.must_raise RuntimeError
53
55
  end
54
56
 
55
- it 'sets maxgray to 1 for bilevel images' do
56
- image = PNM.create([[0,1,0], [1,0,1]])
57
+ it "sets maxgray to 1 for bilevel images" do
58
+ image = PNM.create([[0, 1, 0], [1, 0, 1]])
57
59
  image.type.must_equal :pbm
58
60
  image.maxgray.must_equal 1
59
61
  end
60
62
 
61
- it 'sets maxgray by default to 255 for grayscale images' do
62
- image = PNM.create([[0,10,20], [10,20,30]])
63
+ it "sets maxgray by default to 255 for grayscale images" do
64
+ image = PNM.create([[0, 10, 20], [10, 20, 30]])
63
65
  image.type.must_equal :pgm
64
66
  image.maxgray.must_equal 255
65
67
  end
66
68
 
67
- it 'sets maxgray by default to 255 for color images' do
68
- image = PNM.create([[[0,0,0], [10,10,10]], [[10,10,10], [20,20,20]]])
69
+ it "sets maxgray by default to 255 for color images" do
70
+ image = PNM.create([[[0, 0, 0], [10, 10, 10]], [[10, 10, 10], [20, 20, 20]]])
69
71
  image.type.must_equal :ppm
70
72
  image.maxgray.must_equal 255
71
73
  end
72
74
 
73
- it 'accepts setting of maxgray to 1 for bilevel images' do
74
- image = PNM.create([[0,1,0], [1,0,1]], {:maxgray => 1})
75
+ it "accepts setting of maxgray to 1 for bilevel images" do
76
+ image = PNM.create([[0, 1, 0], [1, 0, 1]], maxgray: 1)
75
77
  image.type.must_equal :pbm
76
78
  image.maxgray.must_equal 1
77
79
  end
78
80
 
79
- it 'ignores invalid maxgray for bilevel images and sets it to 1' do
80
- image = PNM.create([[0,1,0], [1,0,1]], {:type => :pbm, :maxgray => 255})
81
+ it "ignores invalid maxgray for bilevel images and sets it to 1" do
82
+ image = PNM.create([[0, 1, 0], [1, 0, 1]], type: :pbm, maxgray: 255)
81
83
  image.type.must_equal :pbm
82
84
  image.maxgray.must_equal 1
83
85
  end
84
86
 
85
- it 'can create a grayscale image from bilevel values (using type)' do
86
- image = PNM.create([[0,1,0], [1,0,1]], {:type => :pgm})
87
+ it "can create a grayscale image from bilevel values (using type)" do
88
+ image = PNM.create([[0, 1, 0], [1, 0, 1]], type: :pgm)
87
89
  image.type.must_equal :pgm
88
- image.pixels.must_equal [[0,1,0], [1,0,1]]
90
+ image.pixels.must_equal [[0, 1, 0], [1, 0, 1]]
89
91
  image.maxgray.must_equal 255
90
92
  end
91
93
 
92
- it 'also accepts types given as string instead of symbol' do
93
- image = PNM.create([[0,1,0], [1,0,1]], {:type => "pgm"})
94
+ it "also accepts types given as string instead of symbol" do
95
+ image = PNM.create([[0, 1, 0], [1, 0, 1]], type: "pgm")
94
96
  image.type.must_equal :pgm
95
97
  end
96
98
 
97
- it 'can create a grayscale image from bilevel values (using maxgray)' do
98
- image = PNM.create([[0,1,0], [1,0,1]], {:maxgray => 2})
99
+ it "can create a grayscale image from bilevel values (using maxgray)" do
100
+ image = PNM.create([[0, 1, 0], [1, 0, 1]], maxgray: 2)
99
101
  image.type.must_equal :pgm
100
- image.pixels.must_equal [[0,1,0], [1,0,1]]
102
+ image.pixels.must_equal [[0, 1, 0], [1, 0, 1]]
101
103
  image.maxgray.must_equal 2
102
104
  end
103
105
 
104
- it 'can create a color image from bilevel values' do
105
- image = PNM.create([[0,1,0], [1,0,1]], {:type => :ppm})
106
+ it "can create a color image from bilevel values" do
107
+ image = PNM.create([[0, 1, 0], [1, 0, 1]], type: :ppm)
106
108
  image.info.must_match %r{^PPM 3x2 Color}
107
- image.pixels.must_equal [[[0,0,0], [1,1,1], [0,0,0]], [[1,1,1], [0,0,0], [1,1,1]]]
109
+ image.pixels.must_equal [[[0, 0, 0], [1, 1, 1], [0, 0, 0]], [[1, 1, 1], [0, 0, 0], [1, 1, 1]]]
108
110
  image.maxgray.must_equal 255
109
111
  end
110
112
 
111
- it 'can create a color image from bilevel values with a given maxgray' do
112
- image = PNM.create([[0,1,0], [1,0,1]], {:type => :ppm, :maxgray => 2})
113
+ it "can create a color image from bilevel values with a given maxgray" do
114
+ image = PNM.create([[0, 1, 0], [1, 0, 1]], type: :ppm, maxgray: 2)
113
115
  image.info.must_match %r{^PPM 3x2 Color}
114
- image.pixels.must_equal [[[0,0,0], [1,1,1], [0,0,0]], [[1,1,1], [0,0,0], [1,1,1]]]
116
+ image.pixels.must_equal [[[0, 0, 0], [1, 1, 1], [0, 0, 0]], [[1, 1, 1], [0, 0, 0], [1, 1, 1]]]
115
117
  image.maxgray.must_equal 2
116
118
  end
117
119
 
118
- it 'can create a color image from gray values' do
119
- image = PNM.create([[0,3,6], [3,6,9]], {:type => :ppm})
120
+ it "can create a color image from gray values" do
121
+ image = PNM.create([[0, 3, 6], [3, 6, 9]], type: :ppm)
120
122
  image.info.must_match %r{^PPM 3x2 Color}
121
- image.pixels.must_equal [[[0,0,0], [3,3,3], [6,6,6]], [[3,3,3], [6,6,6], [9,9,9]]]
123
+ image.pixels.must_equal [[[0, 0, 0], [3, 3, 3], [6, 6, 6]], [[3, 3, 3], [6, 6, 6], [9, 9, 9]]]
122
124
  end
123
125
 
124
- it 'does not modify the input data for color images created from gray values' do
125
- data = [[0,3,6], [3,6,9]]
126
- PNM.create(data, {:type => :ppm})
127
- data.must_equal [[0,3,6], [3,6,9]]
126
+ it "does not modify the input data for color images created from gray values" do
127
+ data = [[0, 3, 6], [3, 6, 9]]
128
+ PNM.create(data, type: :ppm)
129
+ data.must_equal [[0, 3, 6], [3, 6, 9]]
128
130
  end
129
131
 
130
- it 'can write a bilevel image to an ASCII encoded file' do
132
+ it "can write a bilevel image to an ASCII encoded file" do
131
133
  @bilevel.write(@temp_path, :ascii)
132
134
  File.binread(@temp_path).must_equal File.binread("#{@srcpath}/bilevel_ascii.pbm")
133
135
  File.delete(@temp_path)
134
136
  end
135
137
 
136
- it 'can write a bilevel image (width 5) to a binary encoded file' do
138
+ it "can write a bilevel image (width 5) to a binary encoded file" do
137
139
  @bilevel.write(@temp_path, :binary)
138
140
  File.binread(@temp_path).must_equal File.binread("#{@srcpath}/bilevel_binary.pbm")
139
141
  File.delete(@temp_path)
140
142
  end
141
143
 
142
- it 'can write a bilevel image (width 16) to a binary encoded file' do
143
- @bilevel_2.write(@temp_path, :binary)
144
+ it "can write a bilevel image (width 16) to a binary encoded file" do
145
+ @bilevel2.write(@temp_path, :binary)
144
146
  File.binread(@temp_path).must_equal File.binread("#{@srcpath}/bilevel_2_binary.pbm")
145
147
  File.delete(@temp_path)
146
148
  end
147
149
 
148
- it 'can write a grayscale image to an ASCII encoded file' do
150
+ it "can write a grayscale image to an ASCII encoded file" do
149
151
  @grayscale.write(@temp_path, :ascii)
150
152
  File.binread(@temp_path).must_equal File.binread("#{@srcpath}/grayscale_ascii.pgm")
151
153
  File.delete(@temp_path)
152
154
  end
153
155
 
154
- it 'can write a grayscale image to a binary encoded file' do
156
+ it "can write a grayscale image to a binary encoded file" do
155
157
  @grayscale.write(@temp_path, :binary)
156
158
  File.binread(@temp_path).must_equal File.binread("#{@srcpath}/grayscale_binary.pgm")
157
159
  File.delete(@temp_path)
158
160
  end
159
161
 
160
- it 'can write a color image to an ASCII encoded file' do
162
+ it "can write a color image to an ASCII encoded file" do
161
163
  @color.write(@temp_path, :ascii)
162
164
  File.binread(@temp_path).must_equal File.binread("#{@srcpath}/color_ascii.ppm")
163
165
  File.delete(@temp_path)
164
166
  end
165
167
 
166
- it 'can write a color image to a binary encoded file' do
168
+ it "can write a color image to a binary encoded file" do
167
169
  @color.write(@temp_path, :binary)
168
170
  File.binread(@temp_path).must_equal File.binread("#{@srcpath}/color_binary.ppm")
169
171
  File.delete(@temp_path)
170
172
  end
171
173
 
172
- it 'can write a bilevel image to a file, adding the extension' do
174
+ it "can write a bilevel image to a file, adding the extension" do
173
175
  @bilevel.write_with_extension(@temp_path)
174
176
  File.binread("#{@temp_path}.pbm").must_equal File.binread("#{@srcpath}/bilevel_binary.pbm")
175
177
  File.delete("#{@temp_path}.pbm")
176
178
  end
177
179
 
178
- it 'can write a grayscale image to a file, adding the extension' do
180
+ it "can write a grayscale image to a file, adding the extension" do
179
181
  @grayscale.write_with_extension(@temp_path, :ascii)
180
182
  File.binread("#{@temp_path}.pgm").must_equal File.binread("#{@srcpath}/grayscale_ascii.pgm")
181
183
  File.delete("#{@temp_path}.pgm")
182
184
  end
183
185
 
184
- it 'can write a color image to a file, adding the extension' do
186
+ it "can write a color image to a file, adding the extension" do
185
187
  @color.write_with_extension(@temp_path, :binary)
186
188
  File.binread("#{@temp_path}.ppm").must_equal File.binread("#{@srcpath}/color_binary.ppm")
187
189
  File.delete("#{@temp_path}.ppm")
188
190
  end
189
191
 
190
- it 'can return image information' do
191
- @bilevel.info.must_equal 'PBM 5x6 Bilevel'
192
- @grayscale.info.must_equal 'PGM 4x3 Grayscale'
193
- @color.info.must_equal 'PPM 5x3 Color'
192
+ it "can return image information" do
193
+ @bilevel.info.must_equal "PBM 5x6 Bilevel"
194
+ @grayscale.info.must_equal "PGM 4x3 Grayscale"
195
+ @color.info.must_equal "PPM 5x3 Color"
194
196
  end
195
197
 
196
- it 'can return meaningful debugging information' do
198
+ it "can return meaningful debugging information" do
197
199
  @bilevel.inspect.must_match %r{^#<PNM::\w+Image:0x\h+ PBM 5x6 Bilevel>$}
198
200
  @grayscale.inspect.must_match %r{^#<PNM::\w+Image:0x\h+ PGM 4x3 Grayscale, maxgray=250>$}
199
201
  @color.inspect.must_match %r{^#<PNM::\w+Image:0x\h+ PPM 5x3 Color, maxgray=6>$}
200
202
  end
201
203
 
202
- it 'can write binary data containing CRLF' do
204
+ it "can write binary data containing CRLF" do
203
205
  @grayscale_crlf.write(@temp_path, :binary)
204
206
  File.binread(@temp_path).must_equal File.binread("#{@srcpath}/grayscale_binary_crlf.pgm")
205
207
  File.delete(@temp_path)
206
208
  end
207
209
 
208
- it 'can write binary data containing CRLF to an I/O stream' do
209
- File.open(@temp_path, 'w') {|f| @grayscale_crlf.write(f, :binary) }
210
+ it "can write binary data containing CRLF to an I/O stream" do
211
+ File.open(@temp_path, "w") {|f| @grayscale_crlf.write(f, :binary) }
210
212
  File.binread(@temp_path).must_equal File.binread("#{@srcpath}/grayscale_binary_crlf.pgm")
211
213
  File.delete(@temp_path)
212
214
  end
213
215
 
214
- it 'can write zero-length comments' do
215
- comment = ''
216
- PNM.create([[0,0]], :comment => comment).write(@temp_path, :ascii)
216
+ it "can write zero-length comments" do
217
+ comment = ""
218
+ PNM.create([[0, 0]], comment: comment).write(@temp_path, :ascii)
217
219
  File.binread(@temp_path).must_equal "P1\n#\n2 1\n0 0\n"
218
220
  File.delete(@temp_path)
219
221
  end
220
222
 
221
- it 'can write comments with trailing zero-length line' do
223
+ it "can write comments with trailing zero-length line" do
222
224
  comment = "An empty line:\n"
223
- PNM.create([[0,0]], :comment => comment).write(@temp_path, :ascii)
225
+ PNM.create([[0, 0]], comment: comment).write(@temp_path, :ascii)
224
226
  File.binread(@temp_path).must_equal "P1\n# An empty line:\n#\n2 1\n0 0\n"
225
227
  File.delete(@temp_path)
226
228
  end
227
229
 
228
- it 'can check equality of images (1)' do
229
- pixels = [[0,1,0], [1,0,1]]
230
- bilevel = PNM.create(pixels, {:comment => "image"})
231
- bilevel2 = PNM.create(pixels, {:comment => "image"})
230
+ it "can check equality of images (1)" do
231
+ pixels = [[0, 1, 0], [1, 0, 1]]
232
+ bilevel = PNM.create(pixels, comment: "image")
233
+ bilevel2 = PNM.create(pixels, comment: "image")
232
234
 
233
235
  (bilevel2 == bilevel).must_equal true
234
236
  end
235
237
 
236
- it 'can check equality of images (2)' do
237
- pixels = [[0,1,0], [1,0,1]]
238
- bilevel = PNM.create(pixels, {:comment => "image"})
239
- bilevel2 = PNM.create(pixels, {:comment => "other image"})
238
+ it "can check equality of images (2)" do
239
+ pixels = [[0, 1, 0], [1, 0, 1]]
240
+ bilevel = PNM.create(pixels, comment: "image")
241
+ bilevel2 = PNM.create(pixels, comment: "other image")
240
242
 
241
243
  (bilevel2 == bilevel).must_equal false
242
244
  end
243
245
 
244
- it 'can check equality of images (3)' do
245
- pixels = [[0,1,0], [1,0,1]]
246
+ it "can check equality of images (3)" do
247
+ pixels = [[0, 1, 0], [1, 0, 1]]
246
248
  bilevel = PNM.create(pixels)
247
249
  bilevel2 = PNM.create(pixels.reverse)
248
250
 
249
251
  (bilevel2 == bilevel).must_equal false
250
252
  end
251
253
 
252
- it 'can check equality of images (4)' do
253
- pixels = [[0,1,0], [1,0,1]]
254
- bilevel = PNM.create(pixels, {:type => :pbm})
255
- graylevel = PNM.create(pixels, {:type => :pgm})
254
+ it "can check equality of images (4)" do
255
+ pixels = [[0, 1, 0], [1, 0, 1]]
256
+ bilevel = PNM.create(pixels, type: :pbm)
257
+ graylevel = PNM.create(pixels, type: :pgm)
256
258
 
257
259
  (graylevel == bilevel).must_equal false
258
260
  end
259
261
 
260
- it 'can check equality of images (5)' do
261
- pixels = [[0,1,2], [3,4,5]]
262
- graylevel = PNM.create(pixels, {:maxgray => 10})
263
- graylevel2 = PNM.create(pixels, {:maxgray => 255})
262
+ it "can check equality of images (5)" do
263
+ pixels = [[0, 1, 2], [3, 4, 5]]
264
+ graylevel = PNM.create(pixels, maxgray: 10)
265
+ graylevel2 = PNM.create(pixels, maxgray: 255)
264
266
 
265
267
  (graylevel2 == graylevel).must_equal false
266
268
  end
267
269
 
268
- it 'can check equality of images (6)' do
269
- image = PNM.create([[0,1,2], [3,4,5]])
270
+ it "can check equality of images (6)" do
271
+ image = PNM.create([[0, 1, 2], [3, 4, 5]])
270
272
 
271
273
  (image == "a string").must_equal false
272
274
  end