pnm 0.4.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +25 -20
- data/Rakefile +11 -10
- data/benchmark/bm_converter.rb +21 -17
- data/lib/pnm.rb +54 -54
- data/lib/pnm/converter.rb +44 -47
- data/lib/pnm/exceptions.rb +2 -0
- data/lib/pnm/image.rb +81 -54
- data/lib/pnm/parser.rb +48 -39
- data/lib/pnm/version.rb +4 -2
- data/pnm.gemspec +23 -19
- data/test/backports.rb +19 -0
- data/test/test_converter.rb +85 -80
- data/test/test_exceptions.rb +124 -120
- data/test/test_image.rb +198 -122
- data/test/test_parser.rb +57 -53
- data/test/test_pnm.rb +58 -54
- metadata +17 -16
data/test/backports.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PNM
|
4
|
+
module Backports # :nodoc:
|
5
|
+
module Minitest # :nodoc:
|
6
|
+
|
7
|
+
# Provides workaround for missing value wrappers in minitest < 5.6.0.
|
8
|
+
def _(value = nil, &block)
|
9
|
+
block || value
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
if Gem.loaded_specs["minitest"].version < Gem::Version.new("5.6.0")
|
17
|
+
warn "Using workaround for missing value wrappers in minitest < 5.6.0."
|
18
|
+
include PNM::Backports::Minitest
|
19
|
+
end
|
data/test/test_converter.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# test_converter.rb: Unit tests for the PNM library.
|
2
4
|
#
|
3
|
-
# Copyright (C) 2013-
|
5
|
+
# Copyright (C) 2013-2020 Marcus Stollsteimer
|
6
|
+
|
7
|
+
require "minitest/autorun"
|
8
|
+
require "pnm/converter"
|
4
9
|
|
5
|
-
|
6
|
-
require 'pnm/converter'
|
10
|
+
require_relative "backports"
|
7
11
|
|
8
12
|
|
9
13
|
describe PNM::Converter do
|
@@ -11,196 +15,197 @@ describe PNM::Converter do
|
|
11
15
|
before do
|
12
16
|
@converter = PNM::Converter
|
13
17
|
|
14
|
-
@pbm6
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
@pbm6 = {
|
19
|
+
width: 6,
|
20
|
+
height: 2,
|
21
|
+
array: [[0, 1, 0, 0, 1, 1], [0, 0, 0, 1, 1, 1]],
|
22
|
+
ascii: "0 1 0 0 1 1\n0 0 0 1 1 1\n",
|
23
|
+
binary: ["4C1C"].pack("H*")
|
24
|
+
}
|
21
25
|
|
22
26
|
@pbm14 = {
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
width: 14,
|
28
|
+
height: 2,
|
29
|
+
array: [[0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0],
|
30
|
+
[0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1]],
|
31
|
+
ascii: "0 0 1 1 1 0 0 0 1 1 0 0 1 0\n0 1 0 1 1 0 1 1 1 0 1 1 1 1\n",
|
32
|
+
binary: ["38C85BBC"].pack("H*")
|
33
|
+
}
|
29
34
|
|
30
35
|
@pbm = @pbm14
|
31
36
|
|
32
|
-
@pgm =
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
@ppm =
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
it
|
37
|
+
@pgm = {
|
38
|
+
width: 4,
|
39
|
+
height: 3,
|
40
|
+
array: [[0, 85, 170, 255], [85, 170, 255, 0], [170, 255, 0, 85]],
|
41
|
+
ascii: "0 85 170 255\n85 170 255 0\n170 255 0 85\n",
|
42
|
+
binary: ["0055AAFF55AAFF00AAFF0055"].pack("H*")
|
43
|
+
}
|
44
|
+
|
45
|
+
@ppm = {
|
46
|
+
width: 3,
|
47
|
+
height: 2,
|
48
|
+
array: [[[0, 128, 255], [128, 255, 0], [255, 0, 128]],
|
49
|
+
[[255, 128, 0], [128, 0, 255], [0, 255, 128]]],
|
50
|
+
ascii: "0 128 255 128 255 0 255 0 128\n255 128 0 128 0 255 0 255 128\n",
|
51
|
+
binary: ["0080FF80FF00FF0080FF80008000FF00FF80"].pack("H*")
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
it "can convert from ASCII encoded PBM data" do
|
51
56
|
width = @pbm[:width]
|
52
57
|
height = @pbm[:height]
|
53
58
|
data = @pbm[:ascii]
|
54
59
|
expected = @pbm[:array]
|
55
60
|
|
56
|
-
@converter.ascii2array(:pbm, width, height, data).must_equal expected
|
61
|
+
_(@converter.ascii2array(:pbm, width, height, data)).must_equal expected
|
57
62
|
end
|
58
63
|
|
59
|
-
it
|
64
|
+
it "can convert from ASCII encoded PGM data" do
|
60
65
|
width = @pgm[:width]
|
61
66
|
height = @pgm[:height]
|
62
67
|
data = @pgm[:ascii]
|
63
68
|
expected = @pgm[:array]
|
64
69
|
|
65
|
-
@converter.ascii2array(:pgm, width, height, data).must_equal expected
|
70
|
+
_(@converter.ascii2array(:pgm, width, height, data)).must_equal expected
|
66
71
|
end
|
67
72
|
|
68
|
-
it
|
73
|
+
it "can convert from ASCII encoded PPM data" do
|
69
74
|
width = @ppm[:width]
|
70
75
|
height = @ppm[:height]
|
71
76
|
data = @ppm[:ascii]
|
72
77
|
expected = @ppm[:array]
|
73
78
|
|
74
|
-
@converter.ascii2array(:ppm, width, height, data).must_equal expected
|
79
|
+
_(@converter.ascii2array(:ppm, width, height, data)).must_equal expected
|
75
80
|
end
|
76
81
|
|
77
|
-
it
|
82
|
+
it "accepts ASCII encoded PBM data with omitted whitespace" do
|
78
83
|
width = 4
|
79
84
|
height = 3
|
80
85
|
data = " 010100\n000110"
|
81
86
|
expected = [[0, 1, 0, 1], [0, 0, 0, 0], [0, 1, 1, 0]]
|
82
87
|
|
83
|
-
@converter.ascii2array(:pbm, width, height, data).must_equal expected
|
88
|
+
_(@converter.ascii2array(:pbm, width, height, data)).must_equal expected
|
84
89
|
end
|
85
90
|
|
86
|
-
it
|
91
|
+
it "accepts ASCII encoded PGM data with arbitrary whitespace" do
|
87
92
|
width = 4
|
88
93
|
height = 3
|
89
94
|
data = " \n 10 90\t170\r250\n90 \t170 250 \t\r\n\t 10\n\n\n170\n250\n10\n90\n"
|
90
95
|
expected = [[10, 90, 170, 250], [90, 170, 250, 10], [170, 250, 10, 90]]
|
91
96
|
|
92
|
-
@converter.ascii2array(:pgm, width, height, data).must_equal expected
|
97
|
+
_(@converter.ascii2array(:pgm, width, height, data)).must_equal expected
|
93
98
|
end
|
94
99
|
|
95
|
-
it
|
100
|
+
it "can convert from binary encoded PBM data (width 6)" do
|
96
101
|
width = @pbm6[:width]
|
97
102
|
height = @pbm6[:height]
|
98
103
|
data = @pbm6[:binary]
|
99
104
|
expected = @pbm6[:array]
|
100
105
|
|
101
|
-
@converter.binary2array(:pbm, width, height, data).must_equal expected
|
106
|
+
_(@converter.binary2array(:pbm, width, height, data)).must_equal expected
|
102
107
|
end
|
103
108
|
|
104
|
-
it
|
109
|
+
it "can convert from binary encoded PBM data (width 14)" do
|
105
110
|
width = @pbm14[:width]
|
106
111
|
height = @pbm14[:height]
|
107
112
|
data = @pbm14[:binary]
|
108
113
|
expected = @pbm14[:array]
|
109
114
|
|
110
|
-
@converter.binary2array(:pbm, width, height, data).must_equal expected
|
115
|
+
_(@converter.binary2array(:pbm, width, height, data)).must_equal expected
|
111
116
|
end
|
112
117
|
|
113
|
-
it
|
118
|
+
it "can convert from binary encoded PGM data" do
|
114
119
|
width = @pgm[:width]
|
115
120
|
height = @pgm[:height]
|
116
121
|
data = @pgm[:binary]
|
117
122
|
expected = @pgm[:array]
|
118
123
|
|
119
|
-
@converter.binary2array(:pgm, width, height, data).must_equal expected
|
124
|
+
_(@converter.binary2array(:pgm, width, height, data)).must_equal expected
|
120
125
|
end
|
121
126
|
|
122
|
-
it
|
127
|
+
it "can convert from binary encoded PPM data" do
|
123
128
|
width = @ppm[:width]
|
124
129
|
height = @ppm[:height]
|
125
130
|
data = @ppm[:binary]
|
126
131
|
expected = @ppm[:array]
|
127
132
|
|
128
|
-
@converter.binary2array(:ppm, width, height, data).must_equal expected
|
133
|
+
_(@converter.binary2array(:ppm, width, height, data)).must_equal expected
|
129
134
|
end
|
130
135
|
|
131
|
-
it
|
136
|
+
it "accepts an additional whitespace character for binary encoded data" do
|
132
137
|
width = @pbm14[:width]
|
133
138
|
height = @pbm14[:height]
|
134
139
|
data = @pbm14[:binary] + "\t"
|
135
140
|
expected = @pbm14[:array]
|
136
141
|
|
137
|
-
@converter.binary2array(:pbm, width, height, data).must_equal expected
|
142
|
+
_(@converter.binary2array(:pbm, width, height, data)).must_equal expected
|
138
143
|
end
|
139
144
|
|
140
|
-
it
|
145
|
+
it "can convert to ASCII encoded PBM data" do
|
141
146
|
data = @pbm[:array]
|
142
147
|
expected = @pbm[:ascii]
|
143
148
|
|
144
|
-
@converter.array2ascii(data).must_equal expected
|
149
|
+
_(@converter.array2ascii(data)).must_equal expected
|
145
150
|
end
|
146
151
|
|
147
|
-
it
|
152
|
+
it "can convert to ASCII encoded PGM data" do
|
148
153
|
data = @pgm[:array]
|
149
154
|
expected = @pgm[:ascii]
|
150
155
|
|
151
|
-
@converter.array2ascii(data).must_equal expected
|
156
|
+
_(@converter.array2ascii(data)).must_equal expected
|
152
157
|
end
|
153
158
|
|
154
|
-
it
|
159
|
+
it "can convert to ASCII encoded PPM data" do
|
155
160
|
data = @ppm[:array]
|
156
161
|
expected = @ppm[:ascii]
|
157
162
|
|
158
|
-
@converter.array2ascii(data).must_equal expected
|
163
|
+
_(@converter.array2ascii(data)).must_equal expected
|
159
164
|
end
|
160
165
|
|
161
|
-
it
|
166
|
+
it "can convert to binary encoded PBM data (width 6)" do
|
162
167
|
data = @pbm6[:array]
|
163
168
|
expected = @pbm6[:binary]
|
164
169
|
|
165
|
-
@converter.array2binary(:pbm, data).must_equal expected
|
170
|
+
_(@converter.array2binary(:pbm, data)).must_equal expected
|
166
171
|
end
|
167
172
|
|
168
|
-
it
|
173
|
+
it "can convert to binary encoded PBM data (width 14)" do
|
169
174
|
data = @pbm14[:array]
|
170
175
|
expected = @pbm14[:binary]
|
171
176
|
|
172
|
-
@converter.array2binary(:pbm, data).must_equal expected
|
177
|
+
_(@converter.array2binary(:pbm, data)).must_equal expected
|
173
178
|
end
|
174
179
|
|
175
|
-
it
|
180
|
+
it "can convert to binary encoded PGM data" do
|
176
181
|
data = @pgm[:array]
|
177
182
|
expected = @pgm[:binary]
|
178
183
|
|
179
|
-
@converter.array2binary(:pgm, data).must_equal expected
|
184
|
+
_(@converter.array2binary(:pgm, data)).must_equal expected
|
180
185
|
end
|
181
186
|
|
182
|
-
it
|
187
|
+
it "can convert to binary encoded PPM data" do
|
183
188
|
data = @ppm[:array]
|
184
189
|
expected = @ppm[:binary]
|
185
190
|
|
186
|
-
@converter.array2binary(:ppm, data).must_equal expected
|
191
|
+
_(@converter.array2binary(:ppm, data)).must_equal expected
|
187
192
|
end
|
188
193
|
|
189
|
-
it
|
190
|
-
@converter.byte_width(:pbm, 0).must_equal 0
|
191
|
-
@converter.byte_width(:pbm, 1).must_equal 1
|
192
|
-
@converter.byte_width(:pbm, 7).must_equal 1
|
193
|
-
@converter.byte_width(:pbm, 8).must_equal 1
|
194
|
-
@converter.byte_width(:pbm, 9).must_equal 2
|
195
|
-
@converter.byte_width(:pbm, 64).must_equal 8
|
196
|
-
@converter.byte_width(:pbm, 65).must_equal 9
|
194
|
+
it "can calculate correct byte widths for a PBM image" do
|
195
|
+
_(@converter.byte_width(:pbm, 0)).must_equal 0
|
196
|
+
_(@converter.byte_width(:pbm, 1)).must_equal 1
|
197
|
+
_(@converter.byte_width(:pbm, 7)).must_equal 1
|
198
|
+
_(@converter.byte_width(:pbm, 8)).must_equal 1
|
199
|
+
_(@converter.byte_width(:pbm, 9)).must_equal 2
|
200
|
+
_(@converter.byte_width(:pbm, 64)).must_equal 8
|
201
|
+
_(@converter.byte_width(:pbm, 65)).must_equal 9
|
197
202
|
end
|
198
203
|
|
199
|
-
it
|
200
|
-
@converter.byte_width(:pgm, 13).must_equal 13
|
204
|
+
it "can calculate correct byte widths for a PGM image" do
|
205
|
+
_(@converter.byte_width(:pgm, 13)).must_equal 13
|
201
206
|
end
|
202
207
|
|
203
|
-
it
|
204
|
-
@converter.byte_width(:ppm, 13).must_equal 39
|
208
|
+
it "can calculate correct byte widths for a PPM image" do
|
209
|
+
_(@converter.byte_width(:ppm, 13)).must_equal 39
|
205
210
|
end
|
206
211
|
end
|
data/test/test_exceptions.rb
CHANGED
@@ -1,234 +1,238 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# test_exceptions.rb: Unit tests for the PNM library.
|
2
4
|
#
|
3
|
-
# Copyright (C) 2013-
|
5
|
+
# Copyright (C) 2013-2020 Marcus Stollsteimer
|
6
|
+
|
7
|
+
require "minitest/autorun"
|
8
|
+
require "stringio"
|
9
|
+
require "pnm"
|
4
10
|
|
5
|
-
|
6
|
-
require 'stringio'
|
7
|
-
require 'pnm'
|
11
|
+
require_relative "backports"
|
8
12
|
|
9
13
|
|
10
|
-
describe
|
14
|
+
describe "PNM.create" do
|
11
15
|
|
12
|
-
it
|
13
|
-
data =
|
14
|
-
|
16
|
+
it "raises an exception for invalid data type (String)" do
|
17
|
+
data = "0"
|
18
|
+
_ { PNM.create(data) }.must_raise PNM::ArgumentError
|
15
19
|
end
|
16
20
|
|
17
|
-
it
|
21
|
+
it "raises an exception for invalid type" do
|
18
22
|
data = [[0, 0], [0, 0]]
|
19
|
-
|
23
|
+
_ { PNM.create(data, type: :abc) }.must_raise PNM::ArgumentError
|
20
24
|
end
|
21
25
|
|
22
|
-
it
|
26
|
+
it "raises an exception for invalid maxgray (String)" do
|
23
27
|
data = [[0, 0], [0, 0]]
|
24
|
-
|
28
|
+
_ { PNM.create(data, maxgray: "255") }.must_raise PNM::ArgumentError
|
25
29
|
end
|
26
30
|
|
27
|
-
it
|
31
|
+
it "raises an exception for invalid maxgray (> 255)" do
|
28
32
|
data = [[0, 0], [0, 0]]
|
29
|
-
|
33
|
+
_ { PNM.create(data, maxgray: 256) }.must_raise PNM::ArgumentError
|
30
34
|
end
|
31
35
|
|
32
|
-
it
|
36
|
+
it "raises an exception for invalid maxgray (0)" do
|
33
37
|
data = [[0, 0], [0, 0]]
|
34
|
-
|
38
|
+
_ { PNM.create(data, maxgray: 0) }.must_raise PNM::ArgumentError
|
35
39
|
end
|
36
40
|
|
37
|
-
it
|
41
|
+
it "raises an exception for invalid comment (Integer)" do
|
38
42
|
data = [[0, 0], [0, 0]]
|
39
|
-
|
43
|
+
_ { PNM.create(data, comment: 1) }.must_raise PNM::ArgumentError
|
40
44
|
end
|
41
45
|
|
42
|
-
it
|
43
|
-
data = [[[0,0,0], [0,0,0]], [[0,0,0], [0,0,0]]]
|
44
|
-
|
46
|
+
it "raises an exception for image type and data mismatch (PBM)" do
|
47
|
+
data = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 0], [0, 0, 0]]]
|
48
|
+
_ { PNM.create(data, type: :pbm) }.must_raise PNM::DataError
|
45
49
|
end
|
46
50
|
|
47
|
-
it
|
48
|
-
data = [[[0,0,0], [0,0,0]], [[0,0,0], [0,0,0]]]
|
49
|
-
|
51
|
+
it "raises an exception for image type and data mismatch (PGM)" do
|
52
|
+
data = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 0], [0, 0, 0]]]
|
53
|
+
_ { PNM.create(data, type: :pgm) }.must_raise PNM::DataError
|
50
54
|
end
|
51
55
|
|
52
|
-
it
|
53
|
-
data = [[0, 0], [
|
54
|
-
|
56
|
+
it "raises an exception for non-integer pixel value (String)" do
|
57
|
+
data = [[0, 0], ["X", 0]]
|
58
|
+
_ { PNM.create(data) }.must_raise PNM::DataError
|
55
59
|
end
|
56
60
|
|
57
|
-
it
|
61
|
+
it "raises an exception for non-integer pixel value (Float)" do
|
58
62
|
data = [[0, 0], [0.5, 0]]
|
59
|
-
|
63
|
+
_ { PNM.create(data) }.must_raise PNM::DataError
|
60
64
|
end
|
61
65
|
|
62
|
-
it
|
66
|
+
it "raises an exception for rows of different size" do
|
63
67
|
data = [[0, 0], [0, 0, 0]]
|
64
|
-
|
68
|
+
_ { PNM.create(data) }.must_raise PNM::DataError
|
65
69
|
end
|
66
70
|
|
67
|
-
it
|
71
|
+
it "raises an exception for invalid array dimensions (#1)" do
|
68
72
|
data = [0, 0, 0]
|
69
|
-
|
73
|
+
_ { PNM.create(data) }.must_raise PNM::DataError
|
70
74
|
end
|
71
75
|
|
72
|
-
it
|
76
|
+
it "raises an exception for invalid array dimensions (#2)" do
|
73
77
|
data = [[0, 0], 0, 0]
|
74
|
-
|
78
|
+
_ { PNM.create(data) }.must_raise PNM::DataError
|
75
79
|
end
|
76
80
|
|
77
|
-
it
|
81
|
+
it "raises an exception for invalid array dimensions (#3)" do
|
78
82
|
data = [[0, 0], [0, [0, 0]]]
|
79
|
-
|
83
|
+
_ { PNM.create(data) }.must_raise PNM::DataError
|
80
84
|
end
|
81
85
|
|
82
|
-
it
|
83
|
-
data = [[[0,0], [0,0]], [[0,0], [0,0]]]
|
84
|
-
|
86
|
+
it "raises an exception for invalid array dimensions (#4)" do
|
87
|
+
data = [[[0, 0], [0, 0]], [[0, 0], [0, 0]]]
|
88
|
+
_ { PNM.create(data) }.must_raise PNM::DataError
|
85
89
|
end
|
86
90
|
|
87
|
-
it
|
88
|
-
data = [[[0,0,0], [0,0,0]], [0
|
89
|
-
|
91
|
+
it "raises an exception for invalid array dimensions (#5)" do
|
92
|
+
data = [[[0, 0, 0], [0, 0, 0]], [0, 0]]
|
93
|
+
_ { PNM.create(data) }.must_raise PNM::DataError
|
90
94
|
end
|
91
95
|
|
92
|
-
it
|
93
|
-
data = [[[0,0,0], 0], [0
|
94
|
-
|
96
|
+
it "raises an exception for invalid array dimensions (#6)" do
|
97
|
+
data = [[[0, 0, 0], 0], [0, 0]]
|
98
|
+
_ { PNM.create(data) }.must_raise PNM::DataError
|
95
99
|
end
|
96
100
|
|
97
|
-
it
|
101
|
+
it "raises an exception for an empty array" do
|
98
102
|
data = [[]]
|
99
|
-
|
103
|
+
_ { PNM.create(data) }.must_raise PNM::DataError
|
100
104
|
end
|
101
105
|
|
102
|
-
it
|
106
|
+
it "raises an exception for invalid PBM data (> 1)" do
|
103
107
|
data = [[0, 0], [2, 0]]
|
104
|
-
|
108
|
+
_ { PNM.create(data, type: :pbm) }.must_raise PNM::DataError
|
105
109
|
end
|
106
110
|
|
107
|
-
it
|
111
|
+
it "raises an exception for invalid PBM data (< 0)" do
|
108
112
|
data = [[0, 0], [-1, 0]]
|
109
|
-
|
113
|
+
_ { PNM.create(data, type: :pbm) }.must_raise PNM::DataError
|
110
114
|
end
|
111
115
|
|
112
|
-
it
|
116
|
+
it "raises an exception for invalid PGM data (> 255)" do
|
113
117
|
data = [[0, 0], [1, 500]]
|
114
|
-
|
118
|
+
_ { PNM.create(data, type: :pgm) }.must_raise PNM::DataError
|
115
119
|
end
|
116
120
|
|
117
|
-
it
|
121
|
+
it "raises an exception for invalid PGM data (> maxgray)" do
|
118
122
|
data = [[0, 0], [1, 200]]
|
119
|
-
|
123
|
+
_ { PNM.create(data, maxgray: 100) }.must_raise PNM::DataError
|
120
124
|
end
|
121
125
|
end
|
122
126
|
|
123
127
|
|
124
|
-
describe
|
128
|
+
describe "PNM.read" do
|
125
129
|
|
126
|
-
it
|
127
|
-
|
130
|
+
it "raises an exception for integer argument" do
|
131
|
+
_ { PNM.read(123) }.must_raise PNM::ArgumentError
|
128
132
|
end
|
129
133
|
|
130
|
-
it
|
131
|
-
file = StringIO.new(
|
132
|
-
|
134
|
+
it "raises an exception for unknown magic number" do
|
135
|
+
file = StringIO.new("P0 1 1 0")
|
136
|
+
_ { PNM.read(file) }.must_raise PNM::ParserError
|
133
137
|
end
|
134
138
|
|
135
|
-
it
|
136
|
-
file = StringIO.new(
|
137
|
-
|
139
|
+
it "raises an exception for an empty file" do
|
140
|
+
file = StringIO.new("")
|
141
|
+
_ { PNM.read(file) }.must_raise PNM::ParserError
|
138
142
|
end
|
139
143
|
|
140
|
-
it
|
141
|
-
file = StringIO.new(
|
142
|
-
|
144
|
+
it "raises an exception for missing tokens (#1)" do
|
145
|
+
file = StringIO.new("P1")
|
146
|
+
_ { PNM.read(file) }.must_raise PNM::ParserError
|
143
147
|
end
|
144
148
|
|
145
|
-
it
|
146
|
-
file = StringIO.new(
|
147
|
-
|
149
|
+
it "raises an exception for missing tokens (#2)" do
|
150
|
+
file = StringIO.new("P1 1")
|
151
|
+
_ { PNM.read(file) }.must_raise PNM::ParserError
|
148
152
|
end
|
149
153
|
|
150
|
-
it
|
151
|
-
file = StringIO.new(
|
152
|
-
|
154
|
+
it "raises an exception for missing tokens (#3)" do
|
155
|
+
file = StringIO.new("P1 1 ")
|
156
|
+
_ { PNM.read(file) }.must_raise PNM::ParserError
|
153
157
|
end
|
154
158
|
|
155
|
-
it
|
156
|
-
file = StringIO.new(
|
157
|
-
|
159
|
+
it "raises an exception for missing tokens (#4)" do
|
160
|
+
file = StringIO.new("P1 1 1")
|
161
|
+
_ { PNM.read(file) }.must_raise PNM::ParserError
|
158
162
|
end
|
159
163
|
|
160
|
-
it
|
164
|
+
it "raises an exception for missing tokens (#5)" do
|
161
165
|
file = StringIO.new("P1 1 # Test\n 1")
|
162
|
-
|
166
|
+
_ { PNM.read(file) }.must_raise PNM::ParserError
|
163
167
|
end
|
164
168
|
|
165
|
-
it
|
169
|
+
it "raises an exception for missing tokens (#6)" do
|
166
170
|
file = StringIO.new("P2 1 1 255")
|
167
|
-
|
171
|
+
_ { PNM.read(file) }.must_raise PNM::ParserError
|
168
172
|
end
|
169
173
|
|
170
|
-
it
|
171
|
-
file = StringIO.new(
|
172
|
-
|
174
|
+
it "raises an exception for token of wrong type (#1)" do
|
175
|
+
file = StringIO.new("P1 ? 1 0")
|
176
|
+
_ { PNM.read(file) }.must_raise PNM::ParserError
|
173
177
|
end
|
174
178
|
|
175
|
-
it
|
176
|
-
file = StringIO.new(
|
177
|
-
|
179
|
+
it "raises an exception for token of wrong type (#2)" do
|
180
|
+
file = StringIO.new("P1 1 X 0")
|
181
|
+
_ { PNM.read(file) }.must_raise PNM::ParserError
|
178
182
|
end
|
179
183
|
|
180
|
-
it
|
181
|
-
file = StringIO.new(
|
182
|
-
|
184
|
+
it "raises an exception for token of wrong type (#3)" do
|
185
|
+
file = StringIO.new("P2 1 1 foo 0")
|
186
|
+
_ { PNM.read(file) }.must_raise PNM::ParserError
|
183
187
|
end
|
184
188
|
|
185
|
-
it
|
186
|
-
file = StringIO.new(
|
187
|
-
|
189
|
+
it "raises an exception for zero width" do
|
190
|
+
file = StringIO.new("P2 0 1 255 0")
|
191
|
+
_ { PNM.read(file) }.must_raise PNM::ParserError
|
188
192
|
end
|
189
193
|
|
190
|
-
it
|
191
|
-
file = StringIO.new(
|
192
|
-
|
194
|
+
it "raises an exception for zero height" do
|
195
|
+
file = StringIO.new("P2 1 0 255 0")
|
196
|
+
_ { PNM.read(file) }.must_raise PNM::ParserError
|
193
197
|
end
|
194
198
|
|
195
|
-
it
|
196
|
-
file = StringIO.new(
|
197
|
-
|
199
|
+
it "raises an exception for invalid maxgray (> 255)" do
|
200
|
+
file = StringIO.new("P2 1 1 256 0")
|
201
|
+
_ { PNM.read(file) }.must_raise PNM::ParserError
|
198
202
|
end
|
199
203
|
|
200
|
-
it
|
201
|
-
file = StringIO.new(
|
202
|
-
|
204
|
+
it "raises an exception for invalid maxgray (0)" do
|
205
|
+
file = StringIO.new("P2 1 1 0 0")
|
206
|
+
_ { PNM.read(file) }.must_raise PNM::ParserError
|
203
207
|
end
|
204
208
|
|
205
|
-
it
|
206
|
-
file = StringIO.new(
|
207
|
-
|
209
|
+
it "raises an exception for image dimension mismatch (#1)" do
|
210
|
+
file = StringIO.new("P1 2 3 0 0 0 0 0")
|
211
|
+
_ { PNM.read(file) }.must_raise PNM::DataSizeError
|
208
212
|
end
|
209
213
|
|
210
|
-
it
|
211
|
-
file = StringIO.new(
|
212
|
-
|
214
|
+
it "raises an exception for image dimension mismatch (#2)" do
|
215
|
+
file = StringIO.new("P1 2 3 0 0 0 0 0 0 0")
|
216
|
+
_ { PNM.read(file) }.must_raise PNM::DataSizeError
|
213
217
|
end
|
214
218
|
|
215
|
-
it
|
216
|
-
file = StringIO.new(
|
217
|
-
|
219
|
+
it "raises an exception for image dimension mismatch (#3)" do
|
220
|
+
file = StringIO.new("P3 2 3 255 0 0 0 0 0 0")
|
221
|
+
_ { PNM.read(file) }.must_raise PNM::DataSizeError
|
218
222
|
end
|
219
223
|
|
220
|
-
it
|
221
|
-
file = StringIO.new(
|
222
|
-
|
224
|
+
it "raises an exception for image dimension mismatch (#4)" do
|
225
|
+
file = StringIO.new("P5 2 3 255 AAAAAAA")
|
226
|
+
_ { PNM.read(file) }.must_raise PNM::DataSizeError
|
223
227
|
end
|
224
228
|
|
225
|
-
it
|
226
|
-
file = StringIO.new(
|
227
|
-
|
229
|
+
it "raises an exception for image dimension mismatch (#5)" do
|
230
|
+
file = StringIO.new("P5 2 3 255 AAAAAAA")
|
231
|
+
_ { PNM.read(file) }.must_raise PNM::DataSizeError
|
228
232
|
end
|
229
233
|
|
230
|
-
it
|
231
|
-
file = StringIO.new(
|
232
|
-
|
234
|
+
it "raises an exception for non-numeric image data" do
|
235
|
+
file = StringIO.new("P1 2 3 0 X 0 0 0 0")
|
236
|
+
_ { PNM.read(file) }.must_raise PNM::DataError
|
233
237
|
end
|
234
238
|
end
|