rmagick 2.16.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rmagick might be problematic. Click here for more details.

Files changed (238) hide show
  1. checksums.yaml +5 -5
  2. data/.appveyor.yml +19 -0
  3. data/.circleci/config.yml +56 -0
  4. data/.rubocop.yml +8 -335
  5. data/.rubocop_todo.yml +255 -0
  6. data/.ruby-version +1 -0
  7. data/.travis.yml +6 -49
  8. data/CHANGELOG.md +23 -0
  9. data/CONTRIBUTING.md +34 -0
  10. data/Gemfile +0 -6
  11. data/README.textile +11 -3
  12. data/Rakefile +23 -15
  13. data/before_install_linux.sh +12 -15
  14. data/doc/ex/InitialCoords.rb +4 -4
  15. data/doc/ex/NewCoordSys.rb +4 -4
  16. data/doc/ex/OrigCoordSys.rb +2 -2
  17. data/doc/ex/PreserveAspectRatio.rb +34 -34
  18. data/doc/ex/RotateScale.rb +7 -7
  19. data/doc/ex/Skew.rb +7 -7
  20. data/doc/ex/Use01.rb +1 -1
  21. data/doc/ex/Use02.rb +4 -4
  22. data/doc/ex/Use03.rb +2 -2
  23. data/doc/ex/ViewBox.rb +4 -4
  24. data/doc/ex/affine.rb +5 -5
  25. data/doc/ex/affine_transform.rb +3 -3
  26. data/doc/ex/arc.rb +9 -9
  27. data/doc/ex/arcpath.rb +2 -2
  28. data/doc/ex/arcs01.rb +6 -6
  29. data/doc/ex/arcs02.rb +8 -8
  30. data/doc/ex/axes.rb +11 -11
  31. data/doc/ex/baseline_shift01.rb +5 -5
  32. data/doc/ex/bilevel_channel.rb +1 -1
  33. data/doc/ex/blur_image.rb +1 -1
  34. data/doc/ex/border.rb +1 -1
  35. data/doc/ex/bounding_box.rb +11 -11
  36. data/doc/ex/cbezier1.rb +12 -12
  37. data/doc/ex/cbezier2.rb +13 -13
  38. data/doc/ex/cbezier3.rb +13 -13
  39. data/doc/ex/cbezier4.rb +13 -13
  40. data/doc/ex/cbezier5.rb +13 -13
  41. data/doc/ex/cbezier6.rb +19 -19
  42. data/doc/ex/channel.rb +2 -2
  43. data/doc/ex/chop.rb +2 -2
  44. data/doc/ex/circle.rb +7 -7
  45. data/doc/ex/circle01.rb +2 -2
  46. data/doc/ex/clip_path.rb +6 -6
  47. data/doc/ex/coalesce.rb +6 -6
  48. data/doc/ex/color_fill_to_border.rb +8 -8
  49. data/doc/ex/color_floodfill.rb +8 -8
  50. data/doc/ex/color_histogram.rb +2 -2
  51. data/doc/ex/color_reset.rb +2 -2
  52. data/doc/ex/colors.rb +4 -4
  53. data/doc/ex/compose_mask.rb +2 -2
  54. data/doc/ex/composite.rb +39 -39
  55. data/doc/ex/composite_layers.rb +1 -2
  56. data/doc/ex/contrast.rb +3 -3
  57. data/doc/ex/crop.rb +2 -2
  58. data/doc/ex/crop_with_gravity.rb +5 -5
  59. data/doc/ex/cubic01.rb +12 -12
  60. data/doc/ex/cubic02.rb +22 -22
  61. data/doc/ex/cycle_colormap.rb +3 -3
  62. data/doc/ex/dissolve.rb +0 -0
  63. data/doc/ex/drawcomp.rb +8 -9
  64. data/doc/ex/drop_shadow.rb +4 -4
  65. data/doc/ex/ellipse.rb +9 -9
  66. data/doc/ex/ellipse01.rb +3 -3
  67. data/doc/ex/enhance.rb +2 -2
  68. data/doc/ex/evenodd.rb +19 -19
  69. data/doc/ex/fill_pattern.rb +3 -3
  70. data/doc/ex/flatten_images.rb +1 -1
  71. data/doc/ex/font_styles.rb +13 -13
  72. data/doc/ex/fonts.rb +2 -6
  73. data/doc/ex/frame.rb +1 -1
  74. data/doc/ex/get_multiline_type_metrics.rb +3 -3
  75. data/doc/ex/get_pixels.rb +4 -6
  76. data/doc/ex/get_type_metrics.rb +26 -25
  77. data/doc/ex/gradientfill.rb +2 -2
  78. data/doc/ex/grav.rb +12 -12
  79. data/doc/ex/gravity.rb +14 -16
  80. data/doc/ex/group.rb +11 -11
  81. data/doc/ex/hatchfill.rb +2 -2
  82. data/doc/ex/image.rb +9 -9
  83. data/doc/ex/implode.rb +2 -2
  84. data/doc/ex/line.rb +10 -10
  85. data/doc/ex/line01.rb +7 -7
  86. data/doc/ex/mask.rb +0 -0
  87. data/doc/ex/matte_fill_to_border.rb +3 -3
  88. data/doc/ex/matte_floodfill.rb +2 -2
  89. data/doc/ex/matte_replace.rb +3 -3
  90. data/doc/ex/median_filter.rb +2 -2
  91. data/doc/ex/mono.rb +2 -2
  92. data/doc/ex/morph.rb +1 -1
  93. data/doc/ex/mosaic.rb +7 -5
  94. data/doc/ex/motion_blur.rb +1 -1
  95. data/doc/ex/negate_channel.rb +0 -0
  96. data/doc/ex/nested_rvg.rb +2 -2
  97. data/doc/ex/nonzero.rb +19 -19
  98. data/doc/ex/opacity.rb +9 -9
  99. data/doc/ex/path.rb +17 -17
  100. data/doc/ex/pattern1.rb +4 -4
  101. data/doc/ex/pattern2.rb +2 -2
  102. data/doc/ex/polaroid.rb +0 -1
  103. data/doc/ex/polygon.rb +7 -7
  104. data/doc/ex/polygon01.rb +7 -7
  105. data/doc/ex/polyline.rb +7 -7
  106. data/doc/ex/polyline01.rb +8 -8
  107. data/doc/ex/posterize.rb +0 -0
  108. data/doc/ex/qbezierpath.rb +16 -16
  109. data/doc/ex/quad01.rb +6 -6
  110. data/doc/ex/quantize-m.rb +2 -2
  111. data/doc/ex/random_threshold_channel.rb +1 -1
  112. data/doc/ex/rect01.rb +2 -2
  113. data/doc/ex/rect02.rb +3 -3
  114. data/doc/ex/rectangle.rb +6 -6
  115. data/doc/ex/reduce_noise.rb +2 -2
  116. data/doc/ex/remap.rb +0 -0
  117. data/doc/ex/resize_to_fill.rb +0 -0
  118. data/doc/ex/resize_to_fit.rb +0 -0
  119. data/doc/ex/roll.rb +1 -1
  120. data/doc/ex/rotate.rb +8 -8
  121. data/doc/ex/rotate_f.rb +1 -1
  122. data/doc/ex/roundrect.rb +6 -6
  123. data/doc/ex/rubyname.rb +4 -4
  124. data/doc/ex/rvg_clippath.rb +3 -3
  125. data/doc/ex/rvg_linecap.rb +7 -7
  126. data/doc/ex/rvg_linejoin.rb +7 -7
  127. data/doc/ex/rvg_opacity.rb +5 -5
  128. data/doc/ex/rvg_pattern.rb +8 -8
  129. data/doc/ex/rvg_stroke_dasharray.rb +2 -2
  130. data/doc/ex/sepiatone.rb +0 -0
  131. data/doc/ex/shadow.rb +6 -6
  132. data/doc/ex/shear.rb +2 -2
  133. data/doc/ex/skewx.rb +8 -8
  134. data/doc/ex/skewy.rb +9 -9
  135. data/doc/ex/smile.rb +5 -4
  136. data/doc/ex/sparse_color.rb +0 -4
  137. data/doc/ex/splice.rb +1 -1
  138. data/doc/ex/stegano.rb +4 -5
  139. data/doc/ex/stroke_dasharray.rb +10 -10
  140. data/doc/ex/stroke_fill.rb +2 -2
  141. data/doc/ex/stroke_linecap.rb +12 -12
  142. data/doc/ex/stroke_linejoin.rb +12 -12
  143. data/doc/ex/stroke_width.rb +11 -11
  144. data/doc/ex/swirl.rb +2 -2
  145. data/doc/ex/text.rb +6 -6
  146. data/doc/ex/text01.rb +4 -4
  147. data/doc/ex/text_align.rb +5 -5
  148. data/doc/ex/text_antialias.rb +2 -2
  149. data/doc/ex/text_styles.rb +8 -8
  150. data/doc/ex/text_undercolor.rb +4 -4
  151. data/doc/ex/texture_fill_to_border.rb +8 -8
  152. data/doc/ex/texture_floodfill.rb +8 -8
  153. data/doc/ex/texturefill.rb +2 -2
  154. data/doc/ex/threshold.rb +2 -2
  155. data/doc/ex/to_blob.rb +1 -1
  156. data/doc/ex/translate.rb +8 -8
  157. data/doc/ex/transparent.rb +6 -6
  158. data/doc/ex/transpose.rb +0 -0
  159. data/doc/ex/transverse.rb +0 -0
  160. data/doc/ex/tref01.rb +6 -6
  161. data/doc/ex/triangle01.rb +2 -2
  162. data/doc/ex/trim.rb +2 -2
  163. data/doc/ex/tspan01.rb +5 -5
  164. data/doc/ex/tspan02.rb +5 -5
  165. data/doc/ex/tspan03.rb +5 -5
  166. data/doc/ex/unsharp_mask.rb +3 -3
  167. data/doc/ex/viewex.rb +5 -5
  168. data/doc/ex/vignette.rb +0 -0
  169. data/doc/ex/watermark.rb +6 -6
  170. data/doc/ex/wet_floor.rb +2 -2
  171. data/doc/ex/writing_mode01.rb +12 -12
  172. data/doc/ex/writing_mode02.rb +12 -12
  173. data/examples/constitute.rb +1 -1
  174. data/examples/crop_with_gravity.rb +5 -5
  175. data/examples/demo.rb +6 -7
  176. data/examples/describe.rb +8 -10
  177. data/examples/find_similar_region.rb +3 -3
  178. data/examples/histogram.rb +192 -201
  179. data/examples/identify.rb +62 -73
  180. data/examples/image_opacity.rb +0 -1
  181. data/examples/import_export.rb +1 -1
  182. data/examples/pattern_fill.rb +3 -4
  183. data/examples/rotating_text.rb +5 -4
  184. data/examples/spinner.rb +5 -5
  185. data/examples/thumbnail.rb +3 -3
  186. data/examples/vignette.rb +5 -5
  187. data/ext/RMagick/extconf.rb +213 -230
  188. data/ext/RMagick/rmagick.c +1 -0
  189. data/ext/RMagick/rmagick.h +26 -29
  190. data/ext/RMagick/rmdraw.c +3 -38
  191. data/ext/RMagick/rmenum.c +36 -0
  192. data/ext/RMagick/rmimage.c +166 -10
  193. data/ext/RMagick/rminfo.c +7 -2
  194. data/ext/RMagick/rmkinfo.c +247 -0
  195. data/ext/RMagick/rmmain.c +96 -0
  196. data/ext/RMagick/rmutil.c +4 -0
  197. data/lib/rmagick/version.rb +3 -3
  198. data/lib/rmagick_internal.rb +226 -308
  199. data/lib/rvg/clippath.rb +2 -4
  200. data/lib/rvg/container.rb +25 -22
  201. data/lib/rvg/deep_equal.rb +11 -11
  202. data/lib/rvg/describable.rb +2 -2
  203. data/lib/rvg/embellishable.rb +60 -66
  204. data/lib/rvg/misc.rb +122 -128
  205. data/lib/rvg/pathdata.rb +15 -17
  206. data/lib/rvg/rvg.rb +41 -44
  207. data/lib/rvg/stretchable.rb +22 -28
  208. data/lib/rvg/stylable.rb +10 -10
  209. data/lib/rvg/text.rb +164 -165
  210. data/lib/rvg/transformable.rb +15 -15
  211. data/lib/rvg/units.rb +2 -2
  212. data/rmagick.gemspec +9 -33
  213. data/spec/rmagick/draw_spec.rb +5 -6
  214. data/spec/rmagick/image/blue_shift_spec.rb +1 -3
  215. data/spec/rmagick/image/channel_entropy_spec.rb +9 -0
  216. data/spec/rmagick/image/composite_spec.rb +2 -4
  217. data/spec/rmagick/image/constitute_spec.rb +2 -4
  218. data/spec/rmagick/image/dispatch_spec.rb +1 -3
  219. data/spec/rmagick/image/from_blob_spec.rb +1 -3
  220. data/spec/rmagick/image/ping_spec.rb +1 -3
  221. data/spec/rmagick/image/properties_spec.rb +0 -2
  222. data/spec/rmagick/image/read_spec.rb +28 -0
  223. data/spec/spec_helper.rb +7 -1
  224. data/spec/support/issue_200/app.rb +8 -0
  225. data/test/Image1.rb +70 -70
  226. data/test/Image2.rb +369 -361
  227. data/test/Image3.rb +64 -63
  228. data/test/ImageList1.rb +796 -792
  229. data/test/ImageList2.rb +43 -44
  230. data/test/Image_attributes.rb +26 -48
  231. data/test/Import_Export.rb +71 -77
  232. data/test/Info.rb +30 -31
  233. data/test/Magick.rb +47 -46
  234. data/test/Pixel.rb +24 -24
  235. data/test/Preview.rb +7 -6
  236. data/test/test_all_basic.rb +15 -7
  237. data/test/tmpnam_test.rb +3 -3
  238. metadata +57 -18
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'rmagick'
4
4
  require 'test/unit'
5
- require 'test/unit/ui/console/testrunner' unless RUBY_VERSION[/^1\.9|^2/]
5
+ require 'test/unit/ui/console/testrunner' unless RUBY_VERSION[/^1\.9|^2/]
6
6
  require 'fileutils'
7
7
 
8
8
  ColorspaceTypes = [
@@ -48,8 +48,6 @@ Filters = [
48
48
  ]
49
49
 
50
50
  class Image3_UT < Test::Unit::TestCase
51
- FreezeError = RUBY_VERSION[/^1\.9|^2/] ? RuntimeError : TypeError
52
-
53
51
  def setup
54
52
  @img = Magick::Image.new(20, 20)
55
53
  @p = Magick::Image.read(IMAGE_WITH_PROFILE).first.color_profile
@@ -101,7 +99,8 @@ class Image3_UT < Test::Unit::TestCase
101
99
  Magick::OrQuantumOperator,
102
100
  Magick::RShiftQuantumOperator,
103
101
  Magick::SubtractQuantumOperator,
104
- Magick::XorQuantumOperator ]
102
+ Magick::XorQuantumOperator
103
+ ]
105
104
 
106
105
  assert_nothing_raised do
107
106
  res = @img.quantum_operator(Magick::AddQuantumOperator, 2)
@@ -142,8 +141,8 @@ class Image3_UT < Test::Unit::TestCase
142
141
  assert_instance_of(Magick::Image, res)
143
142
  end
144
143
  assert_nothing_raised { @img.raise(4) }
145
- assert_nothing_raised { @img.raise(4,4) }
146
- assert_nothing_raised { @img.raise(4,4, false) }
144
+ assert_nothing_raised { @img.raise(4, 4) }
145
+ assert_nothing_raised { @img.raise(4, 4, false) }
147
146
  assert_raise(TypeError) { @img.raise('x') }
148
147
  assert_raise(TypeError) { @img.raise(2, 'x') }
149
148
  assert_raise(ArgumentError) { @img.raise(4, 4, false, 2) }
@@ -171,15 +170,15 @@ class Image3_UT < Test::Unit::TestCase
171
170
  end
172
171
 
173
172
  def test_remap
174
- remap_image = Magick::Image.new(20,20) {self.background_color = 'green'}
175
- assert_nothing_raised { @img.remap(remap_image) }
176
- assert_nothing_raised { @img.remap(remap_image, Magick::NoDitherMethod) }
177
- assert_nothing_raised { @img.remap(remap_image, Magick::RiemersmaDitherMethod) }
178
- assert_nothing_raised { @img.remap(remap_image, Magick::FloydSteinbergDitherMethod) }
173
+ remap_image = Magick::Image.new(20, 20) { self.background_color = 'green' }
174
+ assert_nothing_raised { @img.remap(remap_image) }
175
+ assert_nothing_raised { @img.remap(remap_image, Magick::NoDitherMethod) }
176
+ assert_nothing_raised { @img.remap(remap_image, Magick::RiemersmaDitherMethod) }
177
+ assert_nothing_raised { @img.remap(remap_image, Magick::FloydSteinbergDitherMethod) }
179
178
 
180
- assert_raise(ArgumentError) {@img.remap }
181
- assert_raise(ArgumentError) {@img.remap(remap_image, Magick::NoDitherMethod, 1) }
182
- assert_raise(TypeError) {@img.remap(remap_image, 1) }
179
+ assert_raise(ArgumentError) { @img.remap }
180
+ assert_raise(ArgumentError) { @img.remap(remap_image, Magick::NoDitherMethod, 1) }
181
+ assert_raise(TypeError) { @img.remap(remap_image, 1) }
183
182
  end
184
183
 
185
184
  def test_resample
@@ -195,7 +194,7 @@ class Image3_UT < Test::Unit::TestCase
195
194
  assert_nothing_raised { @img.resample(100) }
196
195
  assert_nothing_raised { @img.resample(100, 100) }
197
196
 
198
- girl = Magick::Image.read(IMAGES_DIR+'/Flower_Hat.jpg').first
197
+ girl = Magick::Image.read(IMAGES_DIR + '/Flower_Hat.jpg').first
199
198
  assert_equal(240.0, girl.x_resolution)
200
199
  assert_equal(240.0, girl.y_resolution)
201
200
  res = girl.resample(120, 120)
@@ -236,7 +235,7 @@ class Image3_UT < Test::Unit::TestCase
236
235
  res = @img.resize(2)
237
236
  assert_instance_of(Magick::Image, res)
238
237
  end
239
- assert_nothing_raised { @img.resize(50,50) }
238
+ assert_nothing_raised { @img.resize(50, 50) }
240
239
 
241
240
  Filters.each do |filter|
242
241
  assert_nothing_raised { @img.resize(50, 50, filter) }
@@ -260,7 +259,7 @@ class Image3_UT < Test::Unit::TestCase
260
259
  end
261
260
 
262
261
  def test_resize_to_fill_0
263
- changed = @img.resize_to_fill(@img.columns,@img.rows)
262
+ changed = @img.resize_to_fill(@img.columns, @img.rows)
264
263
  assert_equal(@img.columns, changed.columns)
265
264
  assert_equal(@img.rows, changed.rows)
266
265
  assert_not_same(changed, @img)
@@ -268,48 +267,48 @@ class Image3_UT < Test::Unit::TestCase
268
267
 
269
268
  def test_resize_to_fill_1
270
269
  @img = Magick::Image.new(200, 250)
271
- @img.resize_to_fill!(100,100)
270
+ @img.resize_to_fill!(100, 100)
272
271
  assert_equal(100, @img.columns)
273
272
  assert_equal(100, @img.rows)
274
273
  end
275
274
 
276
275
  def test_resize_to_fill_2
277
276
  @img = Magick::Image.new(200, 250)
278
- changed = @img.resize_to_fill(300,100)
277
+ changed = @img.resize_to_fill(300, 100)
279
278
  assert_equal(300, changed.columns)
280
279
  assert_equal(100, changed.rows)
281
280
  end
282
281
 
283
282
  def test_resize_to_fill_3
284
283
  @img = Magick::Image.new(200, 250)
285
- changed = @img.resize_to_fill(100,300)
284
+ changed = @img.resize_to_fill(100, 300)
286
285
  assert_equal(100, changed.columns)
287
286
  assert_equal(300, changed.rows)
288
287
  end
289
288
 
290
289
  def test_resize_to_fill_4
291
290
  @img = Magick::Image.new(200, 250)
292
- changed = @img.resize_to_fill(300,350)
291
+ changed = @img.resize_to_fill(300, 350)
293
292
  assert_equal(300, changed.columns)
294
293
  assert_equal(350, changed.rows)
295
294
  end
296
295
 
297
296
  def test_resize_to_fill_5
298
- changed = @img.resize_to_fill(20,400)
297
+ changed = @img.resize_to_fill(20, 400)
299
298
  assert_equal(20, changed.columns)
300
299
  assert_equal(400, changed.rows)
301
300
  end
302
301
 
303
302
  def test_resize_to_fill_6
304
- changed = @img.resize_to_fill(3000,400)
303
+ changed = @img.resize_to_fill(3000, 400)
305
304
  assert_equal(3000, changed.columns)
306
305
  assert_equal(400, changed.rows)
307
306
  end
308
307
 
309
308
  # Make sure the old name is still around
310
309
  def test_resize_to_fill_7
311
- assert_block {@img.respond_to? :crop_resized}
312
- assert_block {@img.respond_to? :crop_resized!}
310
+ assert_block { @img.respond_to? :crop_resized }
311
+ assert_block { @img.respond_to? :crop_resized! }
313
312
  end
314
313
 
315
314
  # 2nd argument defaults to the same value as the 1st argument
@@ -437,22 +436,22 @@ class Image3_UT < Test::Unit::TestCase
437
436
 
438
437
  # Don't test colorspaces that require PsuedoColor images
439
438
  (ColorspaceTypes - [Magick::OHTAColorspace,
440
- Magick::LabColorspace,
441
- Magick::XYZColorspace,
442
- Magick::YCbCrColorspace,
443
- Magick::YCCColorspace,
444
- Magick::YIQColorspace,
445
- Magick::YPbPrColorspace,
446
- Magick::YUVColorspace,
447
- Magick::Rec601YCbCrColorspace,
448
- Magick::Rec709YCbCrColorspace,
449
- Magick::LogColorspace]).each do |cs|
439
+ Magick::LabColorspace,
440
+ Magick::XYZColorspace,
441
+ Magick::YCbCrColorspace,
442
+ Magick::YCCColorspace,
443
+ Magick::YIQColorspace,
444
+ Magick::YPbPrColorspace,
445
+ Magick::YUVColorspace,
446
+ Magick::Rec601YCbCrColorspace,
447
+ Magick::Rec709YCbCrColorspace,
448
+ Magick::LogColorspace]).each do |cs|
450
449
  assert_nothing_raised { @img.segment(cs) }
451
450
  end
452
451
 
453
452
  assert_nothing_raised { @img.segment(Magick::RGBColorspace, 2.0) }
454
453
  assert_nothing_raised { @img.segment(Magick::RGBColorspace, 2.0, 2.0) }
455
- assert_nothing_raised { @img.segment(Magick::RGBColorspace, 2.0, 2.0, false) }
454
+ assert_nothing_raised { @img.segment(Magick::RGBColorspace, 2.0, 2.0, false) }
456
455
 
457
456
  assert_raise(ArgumentError) { @img.segment(Magick::RGBColorspace, 2.0, 2.0, false, 2) }
458
457
  assert_raise(TypeError) { @img.segment(2) }
@@ -480,7 +479,7 @@ class Image3_UT < Test::Unit::TestCase
480
479
  res = @img.sepiatone
481
480
  assert_instance_of(Magick::Image, res)
482
481
  end
483
- assert_nothing_raised { @img.sepiatone(Magick::QuantumRange*0.80) }
482
+ assert_nothing_raised { @img.sepiatone(Magick::QuantumRange * 0.80) }
484
483
  assert_raise(ArgumentError) { @img.sepiatone(Magick::QuantumRange, 2) }
485
484
  assert_raise(TypeError) { @img.sepiatone('x') }
486
485
  end
@@ -494,15 +493,16 @@ class Image3_UT < Test::Unit::TestCase
494
493
  Magick::MagentaChannel,
495
494
  Magick::BlueChannel,
496
495
  Magick::YellowChannel,
497
- # Magick::AlphaChannel,
496
+ # Magick::AlphaChannel,
498
497
  Magick::OpacityChannel,
499
498
  Magick::MatteChannel,
500
499
  Magick::BlackChannel,
501
500
  Magick::IndexChannel,
502
- Magick::AllChannels]
501
+ Magick::AllChannels
502
+ ]
503
503
 
504
504
  channels.each do |ch|
505
- assert_nothing_raised {@img.set_channel_depth(ch, 8) }
505
+ assert_nothing_raised { @img.set_channel_depth(ch, 8) }
506
506
  end
507
507
  end
508
508
 
@@ -564,15 +564,15 @@ class Image3_UT < Test::Unit::TestCase
564
564
 
565
565
  def test_shave
566
566
  assert_nothing_raised do
567
- res = @img.shave(5,5)
567
+ res = @img.shave(5, 5)
568
568
  assert_instance_of(Magick::Image, res)
569
569
  end
570
570
  assert_nothing_raised do
571
- res = @img.shave!(5,5)
571
+ res = @img.shave!(5, 5)
572
572
  assert_same(@img, res)
573
573
  end
574
574
  @img.freeze
575
- assert_raise(FreezeError) { @img.shave!(2,2) }
575
+ assert_raise(FreezeError) { @img.shave!(2, 2) }
576
576
  end
577
577
 
578
578
  def test_shear
@@ -631,6 +631,7 @@ class Image3_UT < Test::Unit::TestCase
631
631
  # assert good calls work
632
632
  Magick::SparseColorMethod.values do |v|
633
633
  next if v == Magick::UndefinedColorInterpolate
634
+
634
635
  assert_nothing_raised { img.sparse_color(v, *args) }
635
636
  end
636
637
  args << Magick::RedChannel
@@ -646,10 +647,10 @@ class Image3_UT < Test::Unit::TestCase
646
647
  assert_raise(TypeError) { img.sparse_color(1, *args) }
647
648
  # missing arguments
648
649
  assert_raise(ArgumentError) { img.sparse_color(Magick::VoronoiColorInterpolate) }
649
- args << 10 # too many arguments
650
+ args << 10 # too many arguments
650
651
  assert_raise(ArgumentError) { img.sparse_color(Magick::VoronoiColorInterpolate, *args) }
651
652
  args.shift
652
- args.shift # too few
653
+ args.shift # too few
653
654
  assert_raise(ArgumentError) { img.sparse_color(Magick::VoronoiColorInterpolate, *args) }
654
655
  end
655
656
 
@@ -661,7 +662,7 @@ class Image3_UT < Test::Unit::TestCase
661
662
  assert_nothing_raised { @img.splice(0, 0, 2, 2, 'red') }
662
663
  red = Magick::Pixel.new(Magick::QuantumRange)
663
664
  assert_nothing_raised { @img.splice(0, 0, 2, 2, red) }
664
- assert_raise(ArgumentError) { @img.splice(0,0, 2, 2, red, 'x') }
665
+ assert_raise(ArgumentError) { @img.splice(0, 0, 2, 2, red, 'x') }
665
666
  assert_raise(TypeError) { @img.splice([], 0, 2, 2, red) }
666
667
  assert_raise(TypeError) { @img.splice(0, 'x', 2, 2, red) }
667
668
  assert_raise(TypeError) { @img.splice(0, 0, 'x', 2, red) }
@@ -680,7 +681,7 @@ class Image3_UT < Test::Unit::TestCase
680
681
  end
681
682
 
682
683
  def test_stegano
683
- img = Magick::Image.new(100, 100) { self.background_color = 'black' }
684
+ @img = Magick::Image.new(100, 100) { self.background_color = 'black' }
684
685
  watermark = Magick::Image.new(10, 10) { self.background_color = 'white' }
685
686
  assert_nothing_raised do
686
687
  res = @img.stegano(watermark, 0)
@@ -697,7 +698,7 @@ class Image3_UT < Test::Unit::TestCase
697
698
  assert_instance_of(Magick::Image, res)
698
699
  end
699
700
 
700
- img = Magick::Image.new(20,20)
701
+ img = Magick::Image.new(20, 20)
701
702
  img.destroy!
702
703
  assert_raise(Magick::DestroyedImageError) { @img.stereo(img) }
703
704
  end
@@ -713,8 +714,8 @@ class Image3_UT < Test::Unit::TestCase
713
714
  assert_raise(TypeError) { @img.store_pixels(0, 0, @img.columns, 1, pixels) }
714
715
  assert_raise(RangeError) { @img.store_pixels(-1, 0, @img.columns, 1, pixels) }
715
716
  assert_raise(RangeError) { @img.store_pixels(0, -1, @img.columns, 1, pixels) }
716
- assert_raise(RangeError) { @img.store_pixels(0, 0, 1+@img.columns, 1, pixels) }
717
- assert_raise(RangeError) { @img.store_pixels(-1, 0, 1, 1+@img.rows, pixels) }
717
+ assert_raise(RangeError) { @img.store_pixels(0, 0, 1 + @img.columns, 1, pixels) }
718
+ assert_raise(RangeError) { @img.store_pixels(-1, 0, 1, 1 + @img.rows, pixels) }
718
719
  assert_raise(IndexError) { @img.store_pixels(0, 0, @img.columns, 1, ['x']) }
719
720
  end
720
721
 
@@ -739,21 +740,21 @@ class Image3_UT < Test::Unit::TestCase
739
740
  def test_texture_fill_to_border
740
741
  texture = Magick::Image.read('granite:').first
741
742
  assert_nothing_raised do
742
- res = @img.texture_fill_to_border(@img.columns/2, @img.rows/2, texture)
743
+ res = @img.texture_fill_to_border(@img.columns / 2, @img.rows / 2, texture)
743
744
  assert_instance_of(Magick::Image, res)
744
745
  end
745
- assert_raise(NoMethodError) { @img.texture_fill_to_border(@img.columns/2, @img.rows/2, 'x') }
746
+ assert_raise(NoMethodError) { @img.texture_fill_to_border(@img.columns / 2, @img.rows / 2, 'x') }
746
747
  end
747
748
 
748
749
  def test_texture_floodfill
749
750
  texture = Magick::Image.read('granite:').first
750
751
  assert_nothing_raised do
751
- res = @img.texture_floodfill(@img.columns/2, @img.rows/2, texture)
752
+ res = @img.texture_floodfill(@img.columns / 2, @img.rows / 2, texture)
752
753
  assert_instance_of(Magick::Image, res)
753
754
  end
754
- assert_raise(NoMethodError) { @img.texture_floodfill(@img.columns/2, @img.rows/2, 'x') }
755
+ assert_raise(NoMethodError) { @img.texture_floodfill(@img.columns / 2, @img.rows / 2, 'x') }
755
756
  texture.destroy!
756
- assert_raise(Magick::DestroyedImageError) { @img.texture_floodfill(@img.columns/2, @img.rows/2, texture) }
757
+ assert_raise(Magick::DestroyedImageError) { @img.texture_floodfill(@img.columns / 2, @img.rows / 2, texture) }
757
758
  end
758
759
 
759
760
  def test_threshold
@@ -809,7 +810,7 @@ class Image3_UT < Test::Unit::TestCase
809
810
  assert_nothing_raised { @img.transparent(pixel) }
810
811
  assert_nothing_raised { @img.transparent('white', Magick::TransparentOpacity) }
811
812
  assert_raise(ArgumentError) { @img.transparent('white', Magick::TransparentOpacity, 2) }
812
- assert_nothing_raised { @img.transparent('white', Magick::QuantumRange/2) }
813
+ assert_nothing_raised { @img.transparent('white', Magick::QuantumRange / 2) }
813
814
  assert_raise(TypeError) { @img.transparent(2) }
814
815
  end
815
816
 
@@ -841,7 +842,7 @@ class Image3_UT < Test::Unit::TestCase
841
842
 
842
843
  def test_trim
843
844
  # Can't use the default image because it's a solid color
844
- hat = Magick::Image.read(IMAGES_DIR+'/Flower_Hat.jpg').first
845
+ hat = Magick::Image.read(IMAGES_DIR + '/Flower_Hat.jpg').first
845
846
  assert_nothing_raised do
846
847
  res = hat.trim
847
848
  assert_instance_of(Magick::Image, res)
@@ -929,7 +930,7 @@ class Image3_UT < Test::Unit::TestCase
929
930
  end
930
931
 
931
932
  def test_watermark
932
- mark = Magick::Image.new(5,5)
933
+ mark = Magick::Image.new(5, 5)
933
934
  mark_list = Magick::ImageList.new
934
935
  mark_list << mark.copy
935
936
  assert_nothing_raised { @img.watermark(mark) }
@@ -974,7 +975,7 @@ class Image3_UT < Test::Unit::TestCase
974
975
  assert_nothing_raised { @img.white_threshold(50, 50, 50, 50) }
975
976
  assert_raise(ArgumentError) { @img.white_threshold(50, 50, 50, 50, 50) }
976
977
  res = @img.white_threshold(50)
977
- assert_instance_of(Magick::Image, res)
978
+ assert_instance_of(Magick::Image, res)
978
979
  end
979
980
 
980
981
  # test write with #format= attribute
@@ -1023,8 +1024,8 @@ class Image3_UT < Test::Unit::TestCase
1023
1024
  end
1024
1025
  end
1025
1026
 
1026
- if __FILE__ == $PROGRAM_NAME
1027
- IMAGES_DIR = '../doc/ex/images'
1028
- FILES = Dir[IMAGES_DIR+'/Button_*.gif']
1029
- Test::Unit::UI::Console::TestRunner.run(Image3_UT) unless RUBY_VERSION[/^1\.9|^2/]
1027
+ if $PROGRAM_NAME == __FILE__
1028
+ IMAGES_DIR = '../doc/ex/images'
1029
+ FILES = Dir[IMAGES_DIR + '/Button_*.gif']
1030
+ Test::Unit::UI::Console::TestRunner.run(Image3UT) unless RUBY_VERSION[/^1\.9|^2/]
1030
1031
  end
@@ -4,803 +4,807 @@ require 'rmagick'
4
4
  require 'test/unit'
5
5
  require 'test/unit/ui/console/testrunner' unless RUBY_VERSION[/^1\.9|^2/]
6
6
 
7
- class ImageList1_UT < Test::Unit::TestCase
8
- def setup
9
- @list = Magick::ImageList.new(*FILES[0..9])
10
- @list2 = Magick::ImageList.new # intersection is 5..9
11
- @list2 << @list[5]
12
- @list2 << @list[6]
13
- @list2 << @list[7]
14
- @list2 << @list[8]
15
- @list2 << @list[9]
16
- end
17
-
18
- def test_delay
19
- assert_nothing_raised { @list.delay }
20
- assert_equal(0, @list.delay)
21
- assert_nothing_raised { @list.delay = 20 }
22
- assert_equal(20, @list.delay)
23
- assert_raise(ArgumentError) { @list.delay = 'x' }
24
- end
25
-
26
- def test_ticks_per_second
27
- assert_nothing_raised { @list.ticks_per_second }
28
- assert_equal(100, @list.ticks_per_second)
29
- assert_nothing_raised { @list.ticks_per_second = 1000 }
30
- assert_equal(1000, @list.ticks_per_second)
31
- assert_raise(ArgumentError) { @list.ticks_per_second = 'x' }
32
- end
33
-
34
- def test_iterations
35
- assert_nothing_raised { @list.iterations }
36
- assert_equal(1, @list.iterations)
37
- assert_nothing_raised { @list.iterations = 20 }
38
- assert_equal(20, @list.iterations)
39
- assert_raise(ArgumentError) { @list.iterations = 'x' }
40
- end
41
-
42
- # also tests #size
43
- def test_length
44
- assert_nothing_raised { @list.length }
45
- assert_equal(10, @list.length)
46
- assert_raise(NoMethodError) { @list.length = 2 }
47
- end
48
-
49
- def test_scene
50
- assert_nothing_raised { @list.scene }
51
- assert_equal(9, @list.scene)
52
- assert_nothing_raised { @list.scene = 0 }
53
- assert_equal(0, @list.scene)
54
- assert_nothing_raised { @list.scene = 1 }
55
- assert_equal(1, @list.scene)
56
- assert_raise(IndexError) { @list.scene = -1 }
57
- assert_raise(IndexError) { @list.scene = 1000 }
58
- assert_raise(IndexError) { @list.scene = nil }
59
-
60
- # allow nil on empty list
61
- empty_list = Magick::ImageList.new
62
- assert_nothing_raised { empty_list.scene = nil }
63
- end
64
-
65
- def test_undef_array_methods
66
- assert_raise(NoMethodError) { @list.assoc }
67
- assert_raise(NoMethodError) { @list.flatten }
68
- assert_raise(NoMethodError) { @list.flatten! }
69
- assert_raise(NoMethodError) { @list.join }
70
- assert_raise(NoMethodError) { @list.pack }
71
- assert_raise(NoMethodError) { @list.rassoc }
72
- end
73
-
74
- def test_all
75
- q = nil
76
- assert_nothing_raised { q = @list.all? { |i| i.class == Magick::Image } }
77
- assert(q)
78
- end
79
-
80
- def test_any
81
- q = nil
82
- assert_nothing_raised { q = @list.all? { |i| false } }
83
- assert(!q)
84
- assert_nothing_raised { q = @list.all? { |i| i.class == Magick::Image } }
85
- assert(q)
86
- end
87
-
88
- def test_aref
89
- assert_nothing_raised { @list[0] }
90
- assert_instance_of(Magick::Image, @list[0])
91
- assert_instance_of(Magick::Image, @list[-1])
92
- assert_instance_of(Magick::ImageList, @list[0,1])
93
- assert_instance_of(Magick::ImageList, @list[0..2])
94
- assert_nil(@list[20])
95
- end
96
-
97
- def test_aset
98
- img = Magick::Image.new(5,5)
99
- assert_nothing_raised do
100
- rv = @list[0] = img
101
- assert_same(img, rv)
102
- assert_same(img, @list[0])
103
- assert_equal(0, @list.scene)
104
- end
105
-
106
- # replace 2 images with 1
107
- assert_nothing_raised do
108
- img = Magick::Image.new(5,5)
109
- rv = @list[1,2] = img
110
- assert_same(img, rv)
111
- assert_equal(9, @list.length)
112
- assert_same(img, @list[1])
113
- assert_equal(1, @list.scene)
114
- end
115
-
116
- # replace 1 image with 2
117
- assert_nothing_raised do
118
- img = Magick::Image.new(5,5)
119
- img2 = Magick::Image.new(5,5)
120
- ary = [img, img2]
121
- rv = @list[3,1] = ary
122
- assert_same(ary, rv)
123
- assert_equal(10, @list.length)
124
- assert_same(img, @list[3])
125
- assert_same(img2, @list[4])
126
- assert_equal(4, @list.scene)
127
- end
128
-
129
- assert_nothing_raised do
130
- img = Magick::Image.new(5,5)
131
- rv = @list[5..6] = img
132
- assert_same(img, rv)
133
- assert_equal(9, @list.length)
134
- assert_same(img, @list[5])
135
- assert_equal(5, @list.scene)
136
- end
137
-
138
- assert_nothing_raised do
139
- ary = [img, img]
140
- rv = @list[7..8] = ary
141
- assert_same(ary, rv)
142
- assert_equal(9, @list.length)
143
- assert_same(img, @list[7])
144
- assert_same(img, @list[8])
145
- assert_equal(8, @list.scene)
146
- end
147
-
148
- assert_nothing_raised do
149
- rv = @list[-1] = img
150
- assert_same(img, rv)
151
- assert_equal(9, @list.length)
152
- assert_same(img, @list[8])
153
- assert_equal(8, @list.scene)
154
- end
155
-
156
- assert_raise(ArgumentError) { @list[0] = 1 }
157
- assert_raise(ArgumentError) { @list[0,1] = [1,2] }
158
- assert_raise(ArgumentError) { @list[2..3] = 'x' }
159
- end
160
-
161
- def test_and
162
- @list.scene = 7
163
- cur = @list.cur_image
164
- assert_nothing_raised do
165
- res = @list & @list2
166
- assert_instance_of(Magick::ImageList, res)
167
- assert_not_same(res, @list)
168
- assert_not_same(res, @list2)
169
- assert_equal(5, res.length)
170
- assert_equal(2, res.scene)
171
- assert_same(cur, res.cur_image)
172
- end
173
-
174
- # current scene not in the result, set result scene to last image in result
175
- @list.scene = 2
176
- assert_nothing_raised do
177
- res = @list & @list2
178
- assert_instance_of(Magick::ImageList, res)
179
- assert_equal(4, res.scene)
180
- end
181
-
182
- assert_raise(ArgumentError) { @list & 2 }
183
- end
184
-
185
- def test_at
186
- assert_nothing_raised do
187
- cur = @list.cur_image
188
- img = @list.at(7)
189
- assert_same(img, @list[7])
190
- assert_same(cur, @list.cur_image)
191
- img = @list.at(10)
192
- assert_nil(img)
193
- assert_same(cur, @list.cur_image)
194
- img = @list.at(-1)
195
- assert_same(img, @list[9])
196
- assert_same(cur, @list.cur_image)
197
- end
198
- end
199
-
200
- def test_star
201
- @list.scene = 7
202
- cur = @list.cur_image
203
- assert_nothing_raised do
204
- res = @list * 2
205
- assert_instance_of(Magick::ImageList, res)
206
- assert_equal(20, res.length)
207
- assert_not_same(res, @list)
208
- assert_same(cur, res.cur_image)
209
- end
210
-
211
- assert_raise(ArgumentError) { @list * 'x' }
212
- end
213
-
214
- def test_plus
215
- @list.scene = 7
216
- cur = @list.cur_image
217
- assert_nothing_raised do
218
- res = @list + @list2
219
- assert_instance_of(Magick::ImageList, res)
220
- assert_equal(15, res.length)
221
- assert_not_same(res, @list)
222
- assert_not_same(res, @list2)
223
- assert_same(cur, res.cur_image)
224
- end
225
-
226
- assert_raise(ArgumentError) { @list + [2] }
227
- end
228
-
229
- def test_minus
230
- @list.scene = 0
231
- cur = @list.cur_image
232
- assert_nothing_raised do
233
- res = @list - @list2
234
- assert_instance_of(Magick::ImageList, res)
235
- assert_equal(5, res.length)
236
- assert_not_same(res, @list)
237
- assert_not_same(res, @list2)
238
- assert_same(cur, res.cur_image)
239
- end
240
-
241
- # current scene not in result - set result scene to last image in result
242
- @list.scene = 7
243
- cur = @list.cur_image
244
- assert_nothing_raised do
245
- res = @list - @list2
246
- assert_instance_of(Magick::ImageList, res)
247
- assert_equal(5, res.length)
248
- assert_equal(4, res.scene)
249
- end
250
- end
251
-
252
- def test_catenate
253
- assert_nothing_raised do
254
- @list2.each { |img| @list << img }
255
- assert_equal(15, @list.length)
256
- assert_equal(14, @list.scene)
257
- end
258
-
259
- assert_raise(ArgumentError) { @list << 2 }
260
- assert_raise(ArgumentError) { @list << [2] }
261
- end
262
-
263
- def test_or
264
- assert_nothing_raised do
265
- @list.scene = 7
266
- # The or of these two lists should be the same as @list
267
- # but not be the *same* list
268
- res = @list | @list2
269
- assert_instance_of(Magick::ImageList, res)
270
- assert_not_same(res, @list)
271
- assert_not_same(res, @list2)
272
- assert_equal(res, @list)
273
- end
274
-
275
- # Try or'ing disjoint lists
276
- temp_list = Magick::ImageList.new(*FILES[10..14])
277
- res = @list | temp_list
278
- assert_instance_of(Magick::ImageList, res)
279
- assert_equal(15, res.length)
280
- assert_equal(7, res.scene)
281
-
282
- assert_raise(ArgumentError) { @list | 2 }
283
- assert_raise(ArgumentError) { @list | [2] }
284
- end
285
-
286
- def test_clear
287
- assert_nothing_raised { @list.clear }
288
- assert_instance_of(Magick::ImageList, @list)
289
- assert_equal(0, @list.length)
290
- assert_nil(@list.scene)
291
- end
292
-
293
- def test_collect
294
- assert_nothing_raised do
295
- cur = @list.cur_image
296
- scene = @list.scene
297
- res = @list.collect { |img| img.negate }
298
- assert_instance_of(Magick::ImageList, res)
299
- assert_not_same(res, @list)
300
- assert_equal(scene, res.scene)
301
- end
302
- assert_nothing_raised do
303
- scene = @list.scene
304
- @list.collect! { |img| img.negate }
305
- assert_instance_of(Magick::ImageList, @list)
306
- assert_equal(scene, @list.scene)
307
- end
308
- end
309
-
310
- def test_compact
311
- assert_nothing_raised do
312
- res = @list.compact
313
- assert_not_same(res, @list)
314
- assert_equal(res, @list)
315
- end
316
- assert_nothing_raised do
317
- res = @list
318
- @list.compact!
319
- assert_instance_of(Magick::ImageList, @list)
320
- assert_equal(res, @list)
321
- assert_same(res, @list)
322
- end
323
- end
324
-
325
- def test_concat
326
- assert_nothing_raised do
327
- res = @list.concat(@list2)
328
- assert_instance_of(Magick::ImageList, res)
329
- assert_equal(15, res.length)
330
- assert_same(res[14], res.cur_image)
331
- end
332
- assert_raise(ArgumentError) { res = @list.concat(2) }
333
- assert_raise(ArgumentError) { res = @list.concat([2]) }
334
- end
335
-
336
- def test_delete
337
- assert_nothing_raised do
338
- cur = @list.cur_image
339
- img = @list[7]
340
- assert_same(img, @list.delete(img))
341
- assert_equal(9, @list.length)
342
- assert_same(cur, @list.cur_image)
343
-
344
- # Try deleting the current image.
345
- assert_same(cur, @list.delete(cur))
346
- assert_same(@list[-1], @list.cur_image)
347
-
348
- assert_raise(ArgumentError) { @list.delete(2) }
349
- assert_raise(ArgumentError) { @list.delete([2]) }
350
-
351
- # Try deleting something that isn't in the list.
352
- # Should return the value of the block.
353
- assert_nothing_raised do
354
- img = Magick::Image.read(FILES[10]).first
355
- res = @list.delete(img) { 1 }
356
- assert_equal(1, res)
357
- end
358
- end
359
- end
360
-
361
- def test_delete_at
362
- @list.scene = 7
363
- cur = @list.cur_image
364
- assert_nothing_raised { @list.delete_at(9) }
365
- assert_same(cur, @list.cur_image)
366
- assert_nothing_raised { @list.delete_at(7) }
367
- assert_same(@list[-1], @list.cur_image)
368
- end
369
-
370
- def test_delete_if
371
- @list.scene = 7
372
- cur = @list.cur_image
373
- assert_nothing_raised do
374
- @list.delete_if { |img| img.filename =~ /5/ }
375
- assert_instance_of(Magick::ImageList, @list)
376
- assert_equal(9, @list.length)
377
- assert_same(cur, @list.cur_image)
378
- end
379
-
380
- # Delete the current image
381
- assert_nothing_raised do
382
- @list.delete_if { |img| img.filename =~ /7/ }
383
- assert_instance_of(Magick::ImageList, @list)
384
- assert_equal(8, @list.length)
385
- assert_same(@list[-1], @list.cur_image)
386
- end
387
- end
388
-
389
- # defined by Enumerable
390
- def test_enumerables
391
- assert_nothing_raised { @list.detect { true } }
7
+ class ImageList1UT < Test::Unit::TestCase
8
+ def setup
9
+ @list = Magick::ImageList.new(*FILES[0..9])
10
+ @list2 = Magick::ImageList.new # intersection is 5..9
11
+ @list2 << @list[5]
12
+ @list2 << @list[6]
13
+ @list2 << @list[7]
14
+ @list2 << @list[8]
15
+ @list2 << @list[9]
16
+ end
17
+
18
+ def test_delay
19
+ assert_nothing_raised { @list.delay }
20
+ assert_equal(0, @list.delay)
21
+ assert_nothing_raised { @list.delay = 20 }
22
+ assert_equal(20, @list.delay)
23
+ assert_raise(ArgumentError) { @list.delay = 'x' }
24
+ end
25
+
26
+ def test_ticks_per_second
27
+ assert_nothing_raised { @list.ticks_per_second }
28
+ assert_equal(100, @list.ticks_per_second)
29
+ assert_nothing_raised { @list.ticks_per_second = 1000 }
30
+ assert_equal(1000, @list.ticks_per_second)
31
+ assert_raise(ArgumentError) { @list.ticks_per_second = 'x' }
32
+ end
33
+
34
+ def test_iterations
35
+ assert_nothing_raised { @list.iterations }
36
+ assert_equal(1, @list.iterations)
37
+ assert_nothing_raised { @list.iterations = 20 }
38
+ assert_equal(20, @list.iterations)
39
+ assert_raise(ArgumentError) { @list.iterations = 'x' }
40
+ end
41
+
42
+ # also tests #size
43
+ def test_length
44
+ assert_nothing_raised { @list.length }
45
+ assert_equal(10, @list.length)
46
+ assert_raise(NoMethodError) { @list.length = 2 }
47
+ end
48
+
49
+ def test_scene
50
+ assert_nothing_raised { @list.scene }
51
+ assert_equal(9, @list.scene)
52
+ assert_nothing_raised { @list.scene = 0 }
53
+ assert_equal(0, @list.scene)
54
+ assert_nothing_raised { @list.scene = 1 }
55
+ assert_equal(1, @list.scene)
56
+ assert_raise(IndexError) { @list.scene = -1 }
57
+ assert_raise(IndexError) { @list.scene = 1000 }
58
+ assert_raise(IndexError) { @list.scene = nil }
59
+
60
+ # allow nil on empty list
61
+ empty_list = Magick::ImageList.new
62
+ assert_nothing_raised { empty_list.scene = nil }
63
+ end
64
+
65
+ def test_undef_array_methods
66
+ assert_raise(NoMethodError) { @list.assoc }
67
+ assert_raise(NoMethodError) { @list.flatten }
68
+ assert_raise(NoMethodError) { @list.flatten! }
69
+ assert_raise(NoMethodError) { @list.join }
70
+ assert_raise(NoMethodError) { @list.pack }
71
+ assert_raise(NoMethodError) { @list.rassoc }
72
+ end
73
+
74
+ def test_all
75
+ q = nil
76
+ assert_nothing_raised { q = @list.all? { |i| i.class == Magick::Image } }
77
+ assert(q)
78
+ end
79
+
80
+ def test_any
81
+ q = nil
82
+ assert_nothing_raised { q = @list.all? { |_i| false } }
83
+ assert(!q)
84
+ assert_nothing_raised { q = @list.all? { |i| i.class == Magick::Image } }
85
+ assert(q)
86
+ end
87
+
88
+ def test_aref
89
+ assert_nothing_raised { @list[0] }
90
+ assert_instance_of(Magick::Image, @list[0])
91
+ assert_instance_of(Magick::Image, @list[-1])
92
+ assert_instance_of(Magick::ImageList, @list[0, 1])
93
+ assert_instance_of(Magick::ImageList, @list[0..2])
94
+ assert_nil(@list[20])
95
+ end
96
+
97
+ def test_aset
98
+ img = Magick::Image.new(5, 5)
99
+ assert_nothing_raised do
100
+ rv = @list[0] = img
101
+ assert_same(img, rv)
102
+ assert_same(img, @list[0])
103
+ assert_equal(0, @list.scene)
104
+ end
105
+
106
+ # replace 2 images with 1
107
+ assert_nothing_raised do
108
+ img = Magick::Image.new(5, 5)
109
+ rv = @list[1, 2] = img
110
+ assert_same(img, rv)
111
+ assert_equal(9, @list.length)
112
+ assert_same(img, @list[1])
113
+ assert_equal(1, @list.scene)
114
+ end
115
+
116
+ # replace 1 image with 2
117
+ assert_nothing_raised do
118
+ img = Magick::Image.new(5, 5)
119
+ img2 = Magick::Image.new(5, 5)
120
+ ary = [img, img2]
121
+ rv = @list[3, 1] = ary
122
+ assert_same(ary, rv)
123
+ assert_equal(10, @list.length)
124
+ assert_same(img, @list[3])
125
+ assert_same(img2, @list[4])
126
+ assert_equal(4, @list.scene)
127
+ end
128
+
129
+ assert_nothing_raised do
130
+ img = Magick::Image.new(5, 5)
131
+ rv = @list[5..6] = img
132
+ assert_same(img, rv)
133
+ assert_equal(9, @list.length)
134
+ assert_same(img, @list[5])
135
+ assert_equal(5, @list.scene)
136
+ end
137
+
138
+ assert_nothing_raised do
139
+ ary = [img, img]
140
+ rv = @list[7..8] = ary
141
+ assert_same(ary, rv)
142
+ assert_equal(9, @list.length)
143
+ assert_same(img, @list[7])
144
+ assert_same(img, @list[8])
145
+ assert_equal(8, @list.scene)
146
+ end
147
+
148
+ assert_nothing_raised do
149
+ rv = @list[-1] = img
150
+ assert_same(img, rv)
151
+ assert_equal(9, @list.length)
152
+ assert_same(img, @list[8])
153
+ assert_equal(8, @list.scene)
154
+ end
155
+
156
+ assert_raise(ArgumentError) { @list[0] = 1 }
157
+ assert_raise(ArgumentError) { @list[0, 1] = [1, 2] }
158
+ assert_raise(ArgumentError) { @list[2..3] = 'x' }
159
+ end
160
+
161
+ def test_and
162
+ @list.scene = 7
163
+ cur = @list.cur_image
164
+ assert_nothing_raised do
165
+ res = @list & @list2
166
+ assert_instance_of(Magick::ImageList, res)
167
+ assert_not_same(res, @list)
168
+ assert_not_same(res, @list2)
169
+ assert_equal(5, res.length)
170
+ assert_equal(2, res.scene)
171
+ assert_same(cur, res.cur_image)
172
+ end
173
+
174
+ # current scene not in the result, set result scene to last image in result
175
+ @list.scene = 2
176
+ assert_nothing_raised do
177
+ res = @list & @list2
178
+ assert_instance_of(Magick::ImageList, res)
179
+ assert_equal(4, res.scene)
180
+ end
181
+
182
+ assert_raise(ArgumentError) { @list & 2 }
183
+ end
184
+
185
+ def test_at
186
+ assert_nothing_raised do
187
+ cur = @list.cur_image
188
+ img = @list.at(7)
189
+ assert_same(img, @list[7])
190
+ assert_same(cur, @list.cur_image)
191
+ img = @list.at(10)
192
+ assert_nil(img)
193
+ assert_same(cur, @list.cur_image)
194
+ img = @list.at(-1)
195
+ assert_same(img, @list[9])
196
+ assert_same(cur, @list.cur_image)
197
+ end
198
+ end
199
+
200
+ def test_star
201
+ @list.scene = 7
202
+ cur = @list.cur_image
203
+ assert_nothing_raised do
204
+ res = @list * 2
205
+ assert_instance_of(Magick::ImageList, res)
206
+ assert_equal(20, res.length)
207
+ assert_not_same(res, @list)
208
+ assert_same(cur, res.cur_image)
209
+ end
210
+
211
+ assert_raise(ArgumentError) { @list * 'x' }
212
+ end
213
+
214
+ def test_plus
215
+ @list.scene = 7
216
+ cur = @list.cur_image
217
+ assert_nothing_raised do
218
+ res = @list + @list2
219
+ assert_instance_of(Magick::ImageList, res)
220
+ assert_equal(15, res.length)
221
+ assert_not_same(res, @list)
222
+ assert_not_same(res, @list2)
223
+ assert_same(cur, res.cur_image)
224
+ end
225
+
226
+ assert_raise(ArgumentError) { @list + [2] }
227
+ end
228
+
229
+ def test_minus
230
+ @list.scene = 0
231
+ cur = @list.cur_image
232
+ assert_nothing_raised do
233
+ res = @list - @list2
234
+ assert_instance_of(Magick::ImageList, res)
235
+ assert_equal(5, res.length)
236
+ assert_not_same(res, @list)
237
+ assert_not_same(res, @list2)
238
+ assert_same(cur, res.cur_image)
239
+ end
240
+
241
+ # current scene not in result - set result scene to last image in result
242
+ @list.scene = 7
243
+ cur = @list.cur_image
244
+ assert_nothing_raised do
245
+ res = @list - @list2
246
+ assert_instance_of(Magick::ImageList, res)
247
+ assert_equal(5, res.length)
248
+ assert_equal(4, res.scene)
249
+ end
250
+ end
251
+
252
+ def test_catenate
253
+ assert_nothing_raised do
254
+ @list2.each { |img| @list << img }
255
+ assert_equal(15, @list.length)
256
+ assert_equal(14, @list.scene)
257
+ end
258
+
259
+ assert_raise(ArgumentError) { @list << 2 }
260
+ assert_raise(ArgumentError) { @list << [2] }
261
+ end
262
+
263
+ def test_or
264
+ assert_nothing_raised do
265
+ @list.scene = 7
266
+ # The or of these two lists should be the same as @list
267
+ # but not be the *same* list
268
+ res = @list | @list2
269
+ assert_instance_of(Magick::ImageList, res)
270
+ assert_not_same(res, @list)
271
+ assert_not_same(res, @list2)
272
+ assert_equal(res, @list)
273
+ end
274
+
275
+ # Try or'ing disjoint lists
276
+ temp_list = Magick::ImageList.new(*FILES[10..14])
277
+ res = @list | temp_list
278
+ assert_instance_of(Magick::ImageList, res)
279
+ assert_equal(15, res.length)
280
+ assert_equal(7, res.scene)
281
+
282
+ assert_raise(ArgumentError) { @list | 2 }
283
+ assert_raise(ArgumentError) { @list | [2] }
284
+ end
285
+
286
+ def test_clear
287
+ assert_nothing_raised { @list.clear }
288
+ assert_instance_of(Magick::ImageList, @list)
289
+ assert_equal(0, @list.length)
290
+ assert_nil(@list.scene)
291
+ end
292
+
293
+ def test_collect
294
+ assert_nothing_raised do
295
+ scene = @list.scene
296
+ res = @list.collect(&:negate)
297
+ assert_instance_of(Magick::ImageList, res)
298
+ assert_not_same(res, @list)
299
+ assert_equal(scene, res.scene)
300
+ end
301
+ assert_nothing_raised do
302
+ scene = @list.scene
303
+ @list.collect!(&:negate)
304
+ assert_instance_of(Magick::ImageList, @list)
305
+ assert_equal(scene, @list.scene)
306
+ end
307
+ end
308
+
309
+ def test_compact
310
+ assert_nothing_raised do
311
+ res = @list.compact
312
+ assert_not_same(res, @list)
313
+ assert_equal(res, @list)
314
+ end
315
+ assert_nothing_raised do
316
+ res = @list
317
+ @list.compact!
318
+ assert_instance_of(Magick::ImageList, @list)
319
+ assert_equal(res, @list)
320
+ assert_same(res, @list)
321
+ end
322
+ end
323
+
324
+ def test_concat
325
+ assert_nothing_raised do
326
+ res = @list.concat(@list2)
327
+ assert_instance_of(Magick::ImageList, res)
328
+ assert_equal(15, res.length)
329
+ assert_same(res[14], res.cur_image)
330
+ end
331
+ assert_raise(ArgumentError) { @list.concat(2) }
332
+ assert_raise(ArgumentError) { @list.concat([2]) }
333
+ end
334
+
335
+ def test_delete
336
+ assert_nothing_raised do
337
+ cur = @list.cur_image
338
+ img = @list[7]
339
+ assert_same(img, @list.delete(img))
340
+ assert_equal(9, @list.length)
341
+ assert_same(cur, @list.cur_image)
342
+
343
+ # Try deleting the current image.
344
+ assert_same(cur, @list.delete(cur))
345
+ assert_same(@list[-1], @list.cur_image)
346
+
347
+ assert_raise(ArgumentError) { @list.delete(2) }
348
+ assert_raise(ArgumentError) { @list.delete([2]) }
349
+
350
+ # Try deleting something that isn't in the list.
351
+ # Should return the value of the block.
392
352
  assert_nothing_raised do
393
- @list.each_with_index { |img, n| assert_instance_of(Magick::Image, img) }
394
- end
395
- assert_nothing_raised { @list.entries }
396
- assert_nothing_raised { @list.include?(@list[0]) }
397
- assert_nothing_raised { @list.inject(0) { 0 } }
398
- assert_nothing_raised { @list.max }
399
- assert_nothing_raised { @list.min }
400
- assert_nothing_raised { @list.sort }
401
- assert_nothing_raised { @list.sort_by {|img| img.signature} }
402
- assert_nothing_raised { @list.zip }
403
- end
404
-
405
- def test_eql?
406
- list2 = @list
407
- assert(@list.eql?(list2))
408
- list2 = @list.copy
409
- assert(! @list.eql?(list2))
410
- end
411
-
412
- def test_fill
413
- list = @list.copy
414
- img = list[0].copy
415
- assert_nothing_raised do
416
- assert_instance_of(Magick::ImageList, list.fill(img))
417
- end
418
- list.each {|el| assert_same(el, img) }
419
-
420
- list = @list.copy
421
- list.fill(img, 0, 3)
422
- 0.upto(2) {|i| assert_same(img, list[i]) }
423
-
424
- list = @list.copy
425
- list.fill(img, 4..7)
426
- 4.upto(7) {|i| assert_same(img, list[i]) }
427
-
428
- list = @list.copy
429
- list.fill { |i| list[i] = img }
430
- list.each {|el| assert_same(el, img) }
431
-
432
- list = @list.copy
433
- list.fill(0, 3) { |i| list[i] = img }
434
- 0.upto(2) {|i| assert_same(img, list[i]) }
435
-
436
- assert_raise(ArgumentError) { list.fill('x', 0) }
437
- end
438
-
439
- def test_find
440
- assert_nothing_raised { @list.find { true } }
441
- end
442
-
443
- def find_all
444
- assert_nothing_raised do
445
- res = @list.select { |img| img.filename =~ /Button_2/ }
446
- assert_instance_of(Magick::ImageList, res)
447
- assert_equal(1, res.length)
448
- assert_same(res[0], @list[2])
449
- end
450
- end
451
-
452
- def test_insert
453
- assert_nothing_raised do
454
- @list.scene = 7
455
- cur = @list.cur_image
456
- assert_instance_of(Magick::ImageList, @list.insert(1, @list[2]))
457
- assert_same(cur, @list.cur_image)
458
- @list.insert(1, @list[2], @list[3], @list[4])
459
- assert_same(cur, @list.cur_image)
460
- end
461
-
462
- assert_raise(ArgumentError) { @list.insert(0, 'x') }
463
- assert_raise(ArgumentError) { @list.insert(0, 'x', 'y') }
464
- end
465
-
466
- def test_last
467
- img = Magick::Image.new(5,5)
468
- @list << img
469
- img2 = nil
470
- assert_nothing_raised { img2 = @list.last }
471
- assert_instance_of(Magick::Image, img2)
472
- assert_equal(img2, img)
473
- img2 = Magick::Image.new(5,5)
474
- @list << img2
475
- ilist = nil
476
- assert_nothing_raised { ilist = @list.last(2) }
477
- assert_instance_of(Magick::ImageList, ilist)
478
- assert_equal(2, ilist.length)
479
- assert_equal(1, ilist.scene)
480
- assert_equal(img, ilist[0])
481
- assert_equal(img2, ilist[1])
482
- end
483
-
484
- def test___map__
485
- img = @list[0]
486
- assert_nothing_raised do
487
- @list.__map__ { |x| img }
488
- end
489
- assert_instance_of(Magick::ImageList, @list)
490
- assert_raise(ArgumentError) { @list.__map__ { 2 } }
491
- end
492
-
493
- def test_map!
494
- img = @list[0]
495
- assert_nothing_raised do
496
- @list.map! { img }
497
- end
498
- assert_instance_of(Magick::ImageList, @list)
499
- assert_raise(ArgumentError) { @list.map! { 2 } }
500
- end
501
-
502
- unless RUBY_VERSION[/^1\.9|^2/]
503
- def test_nitems
504
- n = nil
505
- assert_nothing_raised { n = @list.nitems }
506
- assert_equal(10, n)
507
- end
508
- end
509
-
510
- def test_partition
511
- a = nil
512
- n = -1
513
- assert_nothing_raised { a = @list.partition { n += 1; (n&1).zero? } }
514
- assert_instance_of(Array, a)
515
- assert_equal(2, a.size)
516
- assert_instance_of(Magick::ImageList, a[0])
517
- assert_instance_of(Magick::ImageList, a[1])
518
- assert_equal(4, a[0].scene)
519
- assert_equal(5, a[0].length)
520
- assert_equal(4, a[1].scene)
521
- assert_equal(5, a[1].length)
522
- end
523
-
524
- def test_pop
525
- @list.scene = 8
526
- cur = @list.cur_image
527
- last = @list[-1]
528
- assert_nothing_raised do
529
- assert_same(last, @list.pop)
530
- assert_same(cur, @list.cur_image)
531
- end
532
-
533
- assert_same(cur, @list.pop)
534
- assert_same(@list[-1], @list.cur_image)
535
- end
536
-
537
- def test_push
538
- list = @list
539
- img1 = @list[0]
540
- img2 = @list[1]
541
- assert_nothing_raised { @list.push(img1, img2) }
542
- assert_same(list, @list) # push returns self
543
- assert_same(img2, @list.cur_image)
544
- end
545
-
546
- def test_reject
547
- @list.scene = 7
548
- cur = @list.cur_image
549
- list = @list
550
- assert_nothing_raised do
551
- res = @list.reject {|img| img.filename =~ /Button_9/ }
552
- assert_equal(9, res.length)
553
- assert_instance_of(Magick::ImageList, res)
554
- assert_same(cur, res.cur_image)
555
- end
556
- assert_same(list, @list)
557
- assert_same(cur, @list.cur_image)
558
-
559
- # Omit current image from result list - result cur_image s/b last image
560
- res = @list.reject {|img| img.filename =~ /Button_7/}
561
- assert_equal(9, res.length)
562
- assert_same(res[-1], res.cur_image)
563
- assert_same(cur, @list.cur_image)
564
- end
565
-
566
- def test_reject!
567
- @list.scene = 7
568
- cur = @list.cur_image
569
- assert_nothing_raised do
570
- @list.reject! { |img| img.filename =~ /5/ }
571
- assert_instance_of(Magick::ImageList, @list)
572
- assert_equal(9, @list.length)
573
- assert_same(cur, @list.cur_image)
574
- end
575
-
576
- # Delete the current image
577
- assert_nothing_raised do
578
- @list.reject! { |img| img.filename =~ /7/ }
579
- assert_instance_of(Magick::ImageList, @list)
580
- assert_equal(8, @list.length)
581
- assert_same(@list[-1], @list.cur_image)
582
- end
583
-
584
- # returns nil if no changes are made
585
- assert_nil(@list.reject! { false })
586
- end
587
-
588
- def test_replace1
589
- # Replace with empty list
590
- assert_nothing_raised do
591
- res = @list.replace([])
592
- assert_same(res, @list)
593
- assert_equal(0, @list.length)
594
- assert_nil(@list.scene)
595
- end
596
-
597
- # Replace empty list with non-empty list
598
- temp = Magick::ImageList.new
599
- assert_nothing_raised do
600
- temp.replace(@list2)
601
- assert_equal(5, temp.length)
602
- assert_equal(4, temp.scene)
603
- end
604
-
605
- # Try to replace with illegal values
606
- assert_raise(ArgumentError) { @list.replace([1, 2, 3]) }
607
- end
608
-
609
- def test_replace2
610
- # Replace with shorter list
611
- assert_nothing_raised do
612
- @list.scene = 7
613
- cur = @list.cur_image
614
- res = @list.replace(@list2)
615
- assert_same(res, @list)
616
- assert_equal(5, @list.length)
617
- assert_equal(2, @list.scene)
618
- assert_same(cur, @list.cur_image)
619
- end
620
- end
621
-
622
- def test_replace3
623
- # Replace with longer list
624
- assert_nothing_raised do
625
- @list2.scene = 2
626
- cur = @list2.cur_image
627
- res = @list2.replace(@list)
628
- assert_same(res, @list2)
629
- assert_equal(10, @list2.length)
630
- assert_equal(7, @list2.scene)
631
- assert_same(cur, @list2.cur_image)
632
- end
633
- end
634
-
635
- def test_reverse
636
- list = nil
637
- cur = @list.cur_image
638
- assert_nothing_raised { list = @list.reverse }
639
- assert_equal(list.length, @list.length)
640
- assert_same(cur, @list.cur_image)
641
- end
642
-
643
- def test_reverse!
644
- list = @list
645
- cur = @list.cur_image
646
- assert_nothing_raised { @list.reverse! }
647
- assert_same(list, @list)
648
- assert_same(cur, @list.cur_image)
649
- end
650
-
651
- # Just validate its existence
652
- def test_reverse_each
653
- assert_nothing_raised do
654
- @list.reverse_each { |img| assert_instance_of(Magick::Image, img) }
353
+ img = Magick::Image.read(FILES[10]).first
354
+ res = @list.delete(img) { 1 }
355
+ assert_equal(1, res)
655
356
  end
656
357
  end
657
-
658
- def test_rindex
659
- img = @list.last
358
+ end
359
+
360
+ def test_delete_at
361
+ @list.scene = 7
362
+ cur = @list.cur_image
363
+ assert_nothing_raised { @list.delete_at(9) }
364
+ assert_same(cur, @list.cur_image)
365
+ assert_nothing_raised { @list.delete_at(7) }
366
+ assert_same(@list[-1], @list.cur_image)
367
+ end
368
+
369
+ def test_delete_if
370
+ @list.scene = 7
371
+ cur = @list.cur_image
372
+ assert_nothing_raised do
373
+ @list.delete_if { |img| img.filename =~ /5/ }
374
+ assert_instance_of(Magick::ImageList, @list)
375
+ assert_equal(9, @list.length)
376
+ assert_same(cur, @list.cur_image)
377
+ end
378
+
379
+ # Delete the current image
380
+ assert_nothing_raised do
381
+ @list.delete_if { |img| img.filename =~ /7/ }
382
+ assert_instance_of(Magick::ImageList, @list)
383
+ assert_equal(8, @list.length)
384
+ assert_same(@list[-1], @list.cur_image)
385
+ end
386
+ end
387
+
388
+ # defined by Enumerable
389
+ def test_enumerables
390
+ assert_nothing_raised { @list.detect { true } }
391
+ assert_nothing_raised do
392
+ @list.each_with_index { |img, _n| assert_instance_of(Magick::Image, img) }
393
+ end
394
+ assert_nothing_raised { @list.entries }
395
+ assert_nothing_raised { @list.include?(@list[0]) }
396
+ assert_nothing_raised { @list.inject(0) { 0 } }
397
+ assert_nothing_raised { @list.max }
398
+ assert_nothing_raised { @list.min }
399
+ assert_nothing_raised { @list.sort }
400
+ assert_nothing_raised { @list.sort_by(&:signature) }
401
+ assert_nothing_raised { @list.zip }
402
+ end
403
+
404
+ def test_eql?
405
+ list2 = @list
406
+ assert(@list.eql?(list2))
407
+ list2 = @list.copy
408
+ assert(!@list.eql?(list2))
409
+ end
410
+
411
+ def test_fill
412
+ list = @list.copy
413
+ img = list[0].copy
414
+ assert_nothing_raised do
415
+ assert_instance_of(Magick::ImageList, list.fill(img))
416
+ end
417
+ list.each { |el| assert_same(el, img) }
418
+
419
+ list = @list.copy
420
+ list.fill(img, 0, 3)
421
+ 0.upto(2) { |i| assert_same(img, list[i]) }
422
+
423
+ list = @list.copy
424
+ list.fill(img, 4..7)
425
+ 4.upto(7) { |i| assert_same(img, list[i]) }
426
+
427
+ list = @list.copy
428
+ list.fill { |i| list[i] = img }
429
+ list.each { |el| assert_same(el, img) }
430
+
431
+ list = @list.copy
432
+ list.fill(0, 3) { |i| list[i] = img }
433
+ 0.upto(2) { |i| assert_same(img, list[i]) }
434
+
435
+ assert_raise(ArgumentError) { list.fill('x', 0) }
436
+ end
437
+
438
+ def test_find
439
+ assert_nothing_raised { @list.find { true } }
440
+ end
441
+
442
+ def find_all
443
+ assert_nothing_raised do
444
+ res = @list.select { |img| img.filename =~ /Button_2/ }
445
+ assert_instance_of(Magick::ImageList, res)
446
+ assert_equal(1, res.length)
447
+ assert_same(res[0], @list[2])
448
+ end
449
+ end
450
+
451
+ def test_insert
452
+ assert_nothing_raised do
453
+ @list.scene = 7
454
+ cur = @list.cur_image
455
+ assert_instance_of(Magick::ImageList, @list.insert(1, @list[2]))
456
+ assert_same(cur, @list.cur_image)
457
+ @list.insert(1, @list[2], @list[3], @list[4])
458
+ assert_same(cur, @list.cur_image)
459
+ end
460
+
461
+ assert_raise(ArgumentError) { @list.insert(0, 'x') }
462
+ assert_raise(ArgumentError) { @list.insert(0, 'x', 'y') }
463
+ end
464
+
465
+ def test_last
466
+ img = Magick::Image.new(5, 5)
467
+ @list << img
468
+ img2 = nil
469
+ assert_nothing_raised { img2 = @list.last }
470
+ assert_instance_of(Magick::Image, img2)
471
+ assert_equal(img2, img)
472
+ img2 = Magick::Image.new(5, 5)
473
+ @list << img2
474
+ ilist = nil
475
+ assert_nothing_raised { ilist = @list.last(2) }
476
+ assert_instance_of(Magick::ImageList, ilist)
477
+ assert_equal(2, ilist.length)
478
+ assert_equal(1, ilist.scene)
479
+ assert_equal(img, ilist[0])
480
+ assert_equal(img2, ilist[1])
481
+ end
482
+
483
+ def test___map__
484
+ img = @list[0]
485
+ assert_nothing_raised do
486
+ @list.__map__ { |_x| img }
487
+ end
488
+ assert_instance_of(Magick::ImageList, @list)
489
+ assert_raise(ArgumentError) { @list.__map__ { 2 } }
490
+ end
491
+
492
+ def test_map!
493
+ img = @list[0]
494
+ assert_nothing_raised do
495
+ @list.map! { img }
496
+ end
497
+ assert_instance_of(Magick::ImageList, @list)
498
+ assert_raise(ArgumentError) { @list.map! { 2 } }
499
+ end
500
+
501
+ unless RUBY_VERSION[/^1\.9|^2/]
502
+ def test_nitems
660
503
  n = nil
661
- assert_nothing_raised { n = @list.rindex(img) }
662
- assert_equal(9, n)
663
- end
664
-
665
- def test_select
666
- assert_nothing_raised do
667
- res = @list.select { |img| img.filename =~ /Button_2/ }
668
- assert_instance_of(Magick::ImageList, res)
669
- assert_equal(1, res.length)
670
- assert_same(res[0], @list[2])
671
- end
672
- end
673
-
674
- def test_shift
675
- assert_nothing_raised do
676
- @list.scene = 0
677
- res = @list[0]
678
- img = @list.shift
679
- assert_same(res, img)
680
- assert_equal(8, @list.scene)
681
- end
682
- res = @list[0]
683
- img = @list.shift
684
- assert_same(res, img)
685
- assert_equal(7, @list.scene)
686
- end
687
-
688
- def test_slice
689
- assert_nothing_raised { @list.slice(0) }
690
- assert_nothing_raised { @list.slice(-1) }
691
- assert_nothing_raised { @list.slice(0,1) }
692
- assert_nothing_raised { @list.slice(0..2) }
693
- assert_nothing_raised { @list.slice(20) }
694
- end
695
-
696
- def test_slice!
697
- @list.scene = 7
698
- assert_nothing_raised do
699
- img0 = @list[0]
700
- img = @list.slice!(0)
701
- assert_same(img0, img)
702
- assert_equal(9, @list.length)
703
- assert_equal(6, @list.scene)
704
- end
705
- cur = @list.cur_image
706
- img = @list.slice!(6)
707
- assert_same(cur, img)
708
- assert_equal(8, @list.length)
709
- assert_equal(7, @list.scene)
710
- assert_nothing_raised { @list.slice!(-1) }
711
- assert_nothing_raised { @list.slice!(0,1) }
712
- assert_nothing_raised { @list.slice!(0..2) }
713
- assert_nothing_raised { @list.slice!(20) }
714
- end
715
-
716
- # simply ensure existence
717
- def test_sort
718
- assert_nothing_raised { @list.sort }
719
- assert_nothing_raised { @list.sort! }
720
- end
721
-
722
- def test_to_a
723
- a = nil
724
- assert_nothing_raised { a = @list.to_a }
725
- assert_instance_of(Array, a)
726
- assert_equal(10, a.length)
727
- end
728
-
729
- def test_uniq
730
- assert_nothing_raised { @list.uniq }
731
- assert_instance_of(Magick::ImageList, @list.uniq)
732
- @list[1] = @list[0]
733
- @list.scene = 7
734
- list = @list.uniq
735
- assert_equal(9, list.length)
736
- assert_equal(6, list.scene)
737
- assert_equal(7, @list.scene)
738
- @list[6] = @list[7]
739
- list = @list.uniq
740
- assert_equal(8, list.length)
741
- assert_equal(5, list.scene)
742
- assert_equal(7, @list.scene)
743
- end
744
-
745
- def test_uniq!
746
- assert_nothing_raised do
747
- assert_nil(@list.uniq!)
748
- end
749
- @list[1] = @list[0]
750
- @list.scene = 7
751
- cur = @list.cur_image
752
- list = @list
753
- @list.uniq!
754
- assert_same(list, @list)
755
- assert_same(cur, @list.cur_image)
756
- assert_equal(6, @list.scene)
757
- @list[5] = @list[6]
758
- @list.uniq!
759
- assert_same(cur, @list.cur_image)
760
- assert_equal(5, @list.scene)
761
- end
762
-
763
- def test_unshift
764
- img = @list[9]
765
- @list.scene = 7
766
- @list.unshift(img)
767
- assert_equal(0, @list.scene)
768
- assert_raise(ArgumentError) { @list.unshift(2) }
769
- assert_raise(ArgumentError) { @list.unshift([1,2]) }
770
- end
771
-
772
- def test_values_at
773
- ilist = nil
774
- assert_nothing_raised { ilist = @list.values_at(1,3,5) }
775
- assert_instance_of(Magick::ImageList, ilist)
776
- assert_equal(3, ilist.length)
777
- assert_equal(2, ilist.scene)
778
- end
779
-
780
- def test_spaceship
781
- list2 = @list.copy
782
- assert_equal(@list.scene, list2.scene)
783
- assert_equal(@list, list2)
784
- list2.scene = 0
785
- assert_not_equal(@list, list2)
786
- list2 = @list.copy
787
- list2[9] = list2[0]
788
- assert_not_equal(@list, list2)
789
- list2 = @list.copy
790
- list2 << @list[9]
791
- assert_not_equal(@list, list2)
792
-
793
- assert_raise(TypeError) { @list <=> 2 }
794
- list = Magick::ImageList.new
795
- list2 = Magick::ImageList.new
796
- assert_raise(TypeError) { list2 <=> @list }
797
- assert_raise(TypeError) { @list <=> list2 }
798
- assert_nothing_raised(TypeError) { list <=> list2 }
504
+ assert_nothing_raised { n = @list.nitems }
505
+ assert_equal(10, n)
506
+ end
507
+ end
508
+
509
+ def test_partition
510
+ a = nil
511
+ n = -1
512
+ assert_nothing_raised do
513
+ a = @list.partition do
514
+ n += 1
515
+ (n & 1).zero?
516
+ end
799
517
  end
518
+ assert_instance_of(Array, a)
519
+ assert_equal(2, a.size)
520
+ assert_instance_of(Magick::ImageList, a[0])
521
+ assert_instance_of(Magick::ImageList, a[1])
522
+ assert_equal(4, a[0].scene)
523
+ assert_equal(5, a[0].length)
524
+ assert_equal(4, a[1].scene)
525
+ assert_equal(5, a[1].length)
526
+ end
527
+
528
+ def test_pop
529
+ @list.scene = 8
530
+ cur = @list.cur_image
531
+ last = @list[-1]
532
+ assert_nothing_raised do
533
+ assert_same(last, @list.pop)
534
+ assert_same(cur, @list.cur_image)
535
+ end
536
+
537
+ assert_same(cur, @list.pop)
538
+ assert_same(@list[-1], @list.cur_image)
539
+ end
540
+
541
+ def test_push
542
+ list = @list
543
+ img1 = @list[0]
544
+ img2 = @list[1]
545
+ assert_nothing_raised { @list.push(img1, img2) }
546
+ assert_same(list, @list) # push returns self
547
+ assert_same(img2, @list.cur_image)
548
+ end
549
+
550
+ def test_reject
551
+ @list.scene = 7
552
+ cur = @list.cur_image
553
+ list = @list
554
+ assert_nothing_raised do
555
+ res = @list.reject { |img| img.filename =~ /Button_9/ }
556
+ assert_equal(9, res.length)
557
+ assert_instance_of(Magick::ImageList, res)
558
+ assert_same(cur, res.cur_image)
559
+ end
560
+ assert_same(list, @list)
561
+ assert_same(cur, @list.cur_image)
562
+
563
+ # Omit current image from result list - result cur_image s/b last image
564
+ res = @list.reject { |img| img.filename =~ /Button_7/ }
565
+ assert_equal(9, res.length)
566
+ assert_same(res[-1], res.cur_image)
567
+ assert_same(cur, @list.cur_image)
568
+ end
569
+
570
+ def test_reject!
571
+ @list.scene = 7
572
+ cur = @list.cur_image
573
+ assert_nothing_raised do
574
+ @list.reject! { |img| img.filename =~ /5/ }
575
+ assert_instance_of(Magick::ImageList, @list)
576
+ assert_equal(9, @list.length)
577
+ assert_same(cur, @list.cur_image)
578
+ end
579
+
580
+ # Delete the current image
581
+ assert_nothing_raised do
582
+ @list.reject! { |img| img.filename =~ /7/ }
583
+ assert_instance_of(Magick::ImageList, @list)
584
+ assert_equal(8, @list.length)
585
+ assert_same(@list[-1], @list.cur_image)
586
+ end
587
+
588
+ # returns nil if no changes are made
589
+ assert_nil(@list.reject! { false })
590
+ end
591
+
592
+ def test_replace1
593
+ # Replace with empty list
594
+ assert_nothing_raised do
595
+ res = @list.replace([])
596
+ assert_same(res, @list)
597
+ assert_equal(0, @list.length)
598
+ assert_nil(@list.scene)
599
+ end
600
+
601
+ # Replace empty list with non-empty list
602
+ temp = Magick::ImageList.new
603
+ assert_nothing_raised do
604
+ temp.replace(@list2)
605
+ assert_equal(5, temp.length)
606
+ assert_equal(4, temp.scene)
607
+ end
608
+
609
+ # Try to replace with illegal values
610
+ assert_raise(ArgumentError) { @list.replace([1, 2, 3]) }
611
+ end
612
+
613
+ def test_replace2
614
+ # Replace with shorter list
615
+ assert_nothing_raised do
616
+ @list.scene = 7
617
+ cur = @list.cur_image
618
+ res = @list.replace(@list2)
619
+ assert_same(res, @list)
620
+ assert_equal(5, @list.length)
621
+ assert_equal(2, @list.scene)
622
+ assert_same(cur, @list.cur_image)
623
+ end
624
+ end
625
+
626
+ def test_replace3
627
+ # Replace with longer list
628
+ assert_nothing_raised do
629
+ @list2.scene = 2
630
+ cur = @list2.cur_image
631
+ res = @list2.replace(@list)
632
+ assert_same(res, @list2)
633
+ assert_equal(10, @list2.length)
634
+ assert_equal(7, @list2.scene)
635
+ assert_same(cur, @list2.cur_image)
636
+ end
637
+ end
638
+
639
+ def test_reverse
640
+ list = nil
641
+ cur = @list.cur_image
642
+ assert_nothing_raised { list = @list.reverse }
643
+ assert_equal(list.length, @list.length)
644
+ assert_same(cur, @list.cur_image)
645
+ end
646
+
647
+ def test_reverse!
648
+ list = @list
649
+ cur = @list.cur_image
650
+ assert_nothing_raised { @list.reverse! }
651
+ assert_same(list, @list)
652
+ assert_same(cur, @list.cur_image)
653
+ end
654
+
655
+ # Just validate its existence
656
+ def test_reverse_each
657
+ assert_nothing_raised do
658
+ @list.reverse_each { |img| assert_instance_of(Magick::Image, img) }
659
+ end
660
+ end
661
+
662
+ def test_rindex
663
+ img = @list.last
664
+ n = nil
665
+ assert_nothing_raised { n = @list.rindex(img) }
666
+ assert_equal(9, n)
667
+ end
668
+
669
+ def test_select
670
+ assert_nothing_raised do
671
+ res = @list.select { |img| img.filename =~ /Button_2/ }
672
+ assert_instance_of(Magick::ImageList, res)
673
+ assert_equal(1, res.length)
674
+ assert_same(res[0], @list[2])
675
+ end
676
+ end
677
+
678
+ def test_shift
679
+ assert_nothing_raised do
680
+ @list.scene = 0
681
+ res = @list[0]
682
+ img = @list.shift
683
+ assert_same(res, img)
684
+ assert_equal(8, @list.scene)
685
+ end
686
+ res = @list[0]
687
+ img = @list.shift
688
+ assert_same(res, img)
689
+ assert_equal(7, @list.scene)
690
+ end
691
+
692
+ def test_slice
693
+ assert_nothing_raised { @list.slice(0) }
694
+ assert_nothing_raised { @list.slice(-1) }
695
+ assert_nothing_raised { @list.slice(0, 1) }
696
+ assert_nothing_raised { @list.slice(0..2) }
697
+ assert_nothing_raised { @list.slice(20) }
698
+ end
699
+
700
+ def test_slice!
701
+ @list.scene = 7
702
+ assert_nothing_raised do
703
+ img0 = @list[0]
704
+ img = @list.slice!(0)
705
+ assert_same(img0, img)
706
+ assert_equal(9, @list.length)
707
+ assert_equal(6, @list.scene)
708
+ end
709
+ cur = @list.cur_image
710
+ img = @list.slice!(6)
711
+ assert_same(cur, img)
712
+ assert_equal(8, @list.length)
713
+ assert_equal(7, @list.scene)
714
+ assert_nothing_raised { @list.slice!(-1) }
715
+ assert_nothing_raised { @list.slice!(0, 1) }
716
+ assert_nothing_raised { @list.slice!(0..2) }
717
+ assert_nothing_raised { @list.slice!(20) }
718
+ end
719
+
720
+ # simply ensure existence
721
+ def test_sort
722
+ assert_nothing_raised { @list.sort }
723
+ assert_nothing_raised { @list.sort! }
724
+ end
725
+
726
+ def test_to_a
727
+ a = nil
728
+ assert_nothing_raised { a = @list.to_a }
729
+ assert_instance_of(Array, a)
730
+ assert_equal(10, a.length)
731
+ end
732
+
733
+ def test_uniq
734
+ assert_nothing_raised { @list.uniq }
735
+ assert_instance_of(Magick::ImageList, @list.uniq)
736
+ @list[1] = @list[0]
737
+ @list.scene = 7
738
+ list = @list.uniq
739
+ assert_equal(9, list.length)
740
+ assert_equal(6, list.scene)
741
+ assert_equal(7, @list.scene)
742
+ @list[6] = @list[7]
743
+ list = @list.uniq
744
+ assert_equal(8, list.length)
745
+ assert_equal(5, list.scene)
746
+ assert_equal(7, @list.scene)
747
+ end
748
+
749
+ def test_uniq!
750
+ assert_nothing_raised do
751
+ assert_nil(@list.uniq!)
752
+ end
753
+ @list[1] = @list[0]
754
+ @list.scene = 7
755
+ cur = @list.cur_image
756
+ list = @list
757
+ @list.uniq!
758
+ assert_same(list, @list)
759
+ assert_same(cur, @list.cur_image)
760
+ assert_equal(6, @list.scene)
761
+ @list[5] = @list[6]
762
+ @list.uniq!
763
+ assert_same(cur, @list.cur_image)
764
+ assert_equal(5, @list.scene)
765
+ end
766
+
767
+ def test_unshift
768
+ img = @list[9]
769
+ @list.scene = 7
770
+ @list.unshift(img)
771
+ assert_equal(0, @list.scene)
772
+ assert_raise(ArgumentError) { @list.unshift(2) }
773
+ assert_raise(ArgumentError) { @list.unshift([1, 2]) }
774
+ end
775
+
776
+ def test_values_at
777
+ ilist = nil
778
+ assert_nothing_raised { ilist = @list.values_at(1, 3, 5) }
779
+ assert_instance_of(Magick::ImageList, ilist)
780
+ assert_equal(3, ilist.length)
781
+ assert_equal(2, ilist.scene)
782
+ end
783
+
784
+ def test_spaceship
785
+ list2 = @list.copy
786
+ assert_equal(@list.scene, list2.scene)
787
+ assert_equal(@list, list2)
788
+ list2.scene = 0
789
+ assert_not_equal(@list, list2)
790
+ list2 = @list.copy
791
+ list2[9] = list2[0]
792
+ assert_not_equal(@list, list2)
793
+ list2 = @list.copy
794
+ list2 << @list[9]
795
+ assert_not_equal(@list, list2)
796
+
797
+ assert_raise(TypeError) { @list <=> 2 }
798
+ list = Magick::ImageList.new
799
+ list2 = Magick::ImageList.new
800
+ assert_raise(TypeError) { list2 <=> @list }
801
+ assert_raise(TypeError) { @list <=> list2 }
802
+ assert_nothing_raised(TypeError) { list <=> list2 }
803
+ end
800
804
  end
801
805
 
802
- if __FILE__ == $PROGRAM_NAME
803
- IMAGES_DIR = '../doc/ex/images'
804
- FILES = Dir[IMAGES_DIR+'/Button_*.gif'].sort
805
- Test::Unit::UI::Console::TestRunner.run(ImageList1_UT) unless RUBY_VERSION[/^1\.9|^2/]
806
+ if $PROGRAM_NAME == __FILE__
807
+ IMAGES_DIR = '../doc/ex/images'
808
+ FILES = Dir[IMAGES_DIR + '/Button_*.gif'].sort
809
+ Test::Unit::UI::Console::TestRunner.run(ImageList1UT) unless RUBY_VERSION[/^1\.9|^2/]
806
810
  end