ffi-geos 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/test/utils_tests.rb CHANGED
@@ -6,31 +6,29 @@ require 'test_helper'
6
6
  class UtilsTests < MiniTest::Unit::TestCase
7
7
  include TestHelper
8
8
 
9
- if defined?(Geos::Utils)
10
- if Geos::Utils.respond_to?(:orientation_index)
11
- def test_orientation_index
12
- assert_equal(0, Geos::Utils.orientation_index(0, 0, 10, 0, 5, 0))
13
- assert_equal(0, Geos::Utils.orientation_index(0, 0, 10, 0, 10, 0))
14
- assert_equal(0, Geos::Utils.orientation_index(0, 0, 10, 0, 0, 0))
15
- assert_equal(0, Geos::Utils.orientation_index(0, 0, 10, 0, -5, 0))
16
- assert_equal(0, Geos::Utils.orientation_index(0, 0, 10, 0, 20, 0))
17
- assert_equal(1, Geos::Utils.orientation_index(0, 0, 10, 10, 5, 6))
18
- assert_equal(1, Geos::Utils.orientation_index(0, 0, 10, 10, 5, 20))
19
- assert_equal(-1, Geos::Utils.orientation_index(0, 0, 10, 10, 5, 3))
20
- assert_equal(-1, Geos::Utils.orientation_index(0, 0, 10, 10, 5, -2))
21
- assert_equal(1, Geos::Utils.orientation_index(0, 0, 10, 10, 1000000, 1000001))
22
- assert_equal(-1, Geos::Utils.orientation_index(0, 0, 10, 10, 1000000, 999999))
23
- end
24
- end
9
+ def test_orientation_index
10
+ skip unless ENV['FORCE_TESTS'] || (defined?(Geos::Utils) && Geos::Utils.respond_to?(:orientation_index))
11
+
12
+ assert_equal(0, Geos::Utils.orientation_index(0, 0, 10, 0, 5, 0))
13
+ assert_equal(0, Geos::Utils.orientation_index(0, 0, 10, 0, 10, 0))
14
+ assert_equal(0, Geos::Utils.orientation_index(0, 0, 10, 0, 0, 0))
15
+ assert_equal(0, Geos::Utils.orientation_index(0, 0, 10, 0, -5, 0))
16
+ assert_equal(0, Geos::Utils.orientation_index(0, 0, 10, 0, 20, 0))
17
+ assert_equal(1, Geos::Utils.orientation_index(0, 0, 10, 10, 5, 6))
18
+ assert_equal(1, Geos::Utils.orientation_index(0, 0, 10, 10, 5, 20))
19
+ assert_equal(-1, Geos::Utils.orientation_index(0, 0, 10, 10, 5, 3))
20
+ assert_equal(-1, Geos::Utils.orientation_index(0, 0, 10, 10, 5, -2))
21
+ assert_equal(1, Geos::Utils.orientation_index(0, 0, 10, 10, 1000000, 1000001))
22
+ assert_equal(-1, Geos::Utils.orientation_index(0, 0, 10, 10, 1000000, 999999))
23
+ end
25
24
 
26
- if Geos::Utils.respond_to?(:relate_match)
27
- def test_relate_match
28
- assert(Geos::Utils.relate_match('0FFFFFFF2', '0FFFFFFF2'), "'0FFFFFFF2' and '0FFFFFFF2' patterns match")
29
- assert(Geos::Utils.relate_match('0FFFFFFF2', '0FFFFFFF*'), "'0FFFFFFF2' and '0FFFFFFF*' patterns match")
30
- assert(Geos::Utils.relate_match('0FFFFFFF2', 'TFFFFFFF2'), "'0FFFFFFF2' and 'TFFFFFFF2' patterns match")
31
- assert(!Geos::Utils.relate_match('0FFFFFFF2', '0FFFFFFFF'), "'0FFFFFFF2' and '0FFFFFFFF' patterns match")
32
- end
33
- end
25
+ def test_relate_match
26
+ skip unless ENV['FORCE_TESTS'] || (defined?(Geos::Utils) && Geos::Utils.respond_to?(:relate_match))
27
+
28
+ assert(Geos::Utils.relate_match('0FFFFFFF2', '0FFFFFFF2'), "'0FFFFFFF2' and '0FFFFFFF2' patterns match")
29
+ assert(Geos::Utils.relate_match('0FFFFFFF2', '0FFFFFFF*'), "'0FFFFFFF2' and '0FFFFFFF*' patterns match")
30
+ assert(Geos::Utils.relate_match('0FFFFFFF2', 'TFFFFFFF2'), "'0FFFFFFF2' and 'TFFFFFFF2' patterns match")
31
+ assert(!Geos::Utils.relate_match('0FFFFFFF2', '0FFFFFFFF'), "'0FFFFFFF2' and '0FFFFFFFF' patterns match")
34
32
  end
35
33
 
36
34
  def create_method_tester(expected, method, cs, type_id, klass)
@@ -264,147 +262,159 @@ class UtilsTests < MiniTest::Unit::TestCase
264
262
  assert_equal(1, geom.num_geometries)
265
263
  end
266
264
 
267
- if ENV['FORCE_TESTS'] || Geos.respond_to?(:create_multi_point)
268
- def test_create_multi_point
269
- writer.rounding_precision = 0
270
- assert_equal('MULTIPOINT EMPTY', write(Geos.create_multi_point))
271
- assert_equal('MULTIPOINT (0 0, 10 10)', write(Geos.create_multi_point(
265
+ def test_create_multi_point
266
+ skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_multi_point)
267
+
268
+ writer.rounding_precision = 0
269
+ assert_equal('MULTIPOINT EMPTY', write(Geos.create_multi_point))
270
+ assert_equal('MULTIPOINT (0 0, 10 10)', write(Geos.create_multi_point(
271
+ read('POINT(0 0)'),
272
+ read('POINT(10 10)')
273
+ )))
274
+ end
275
+
276
+ def test_create_bad_multi_point
277
+ skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_multi_point)
278
+
279
+ assert_raises(TypeError) do
280
+ Geos.create_multi_point(
272
281
  read('POINT(0 0)'),
273
- read('POINT(10 10)')
274
- )))
282
+ read('POLYGON((10 10, 10 15, 15 15, 15 10, 10 10))')
283
+ )
275
284
  end
285
+ end
276
286
 
277
- def test_create_bad_multi_point
278
- assert_raises(TypeError) do
279
- Geos.create_multi_point(
280
- read('POINT(0 0)'),
281
- read('POLYGON((10 10, 10 15, 15 15, 15 10, 10 10))')
282
- )
283
- end
284
- end
287
+ def test_create_multi_line_string
288
+ skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_multi_line_string)
289
+
290
+ writer.rounding_precision = 0
291
+ assert_equal('MULTILINESTRING EMPTY', write(Geos.create_multi_line_string))
292
+ assert_equal('MULTILINESTRING ((0 0, 10 10), (10 10, 20 20))', write(Geos.create_multi_line_string(
293
+ read('LINESTRING(0 0, 10 10)'),
294
+ read('LINESTRING(10 10, 20 20)')
295
+ )))
285
296
  end
286
297
 
287
- if ENV['FORCE_TESTS'] || Geos.respond_to?(:create_multi_line_string)
288
- def test_create_multi_line_string
289
- writer.rounding_precision = 0
290
- assert_equal('MULTILINESTRING EMPTY', write(Geos.create_multi_line_string))
291
- assert_equal('MULTILINESTRING ((0 0, 10 10), (10 10, 20 20))', write(Geos.create_multi_line_string(
292
- read('LINESTRING(0 0, 10 10)'),
293
- read('LINESTRING(10 10, 20 20)')
294
- )))
298
+ def test_create_bad_multi_line_string
299
+ skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_multi_line_string)
300
+
301
+ assert_raises(TypeError) do
302
+ Geos.create_multi_point(
303
+ read('POINT(0 0)'),
304
+ read('LINESTRING(0 0, 10 0)')
305
+ )
295
306
  end
307
+ end
308
+
309
+ def test_create_multi_polygon
310
+ skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_multi_polygon)
311
+
312
+ writer.rounding_precision = 0
313
+ assert_equal('MULTIPOLYGON EMPTY', write(Geos.create_multi_polygon))
314
+ assert_equal('MULTIPOLYGON (((0 0, 0 5, 5 5, 5 0, 0 0)), ((10 10, 10 15, 15 15, 15 10, 10 10)))', write(Geos.create_multi_polygon(
315
+ read('POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))'),
316
+ read('POLYGON((10 10, 10 15, 15 15, 15 10, 10 10))')
317
+ )))
318
+ end
319
+
320
+ def test_create_bad_multi_polygon
321
+ skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_multi_polygon)
296
322
 
297
- def test_create_bad_multi_line_string
298
- assert_raises(TypeError) do
299
- Geos.create_multi_point(
300
- read('POINT(0 0)'),
301
- read('LINESTRING(0 0, 10 0)')
302
- )
303
- end
323
+ assert_raises(TypeError) do
324
+ Geos.create_multi_polygon(
325
+ read('POINT(0 0)'),
326
+ read('POLYGON((10 10, 10 15, 15 15, 15 10, 10 10))')
327
+ )
304
328
  end
305
329
  end
306
330
 
307
- if ENV['FORCE_TESTS'] || Geos.respond_to?(:create_multi_polygon)
308
- def test_create_multi_polygon
309
- writer.rounding_precision = 0
310
- assert_equal('MULTIPOLYGON EMPTY', write(Geos.create_multi_polygon))
311
- assert_equal('MULTIPOLYGON (((0 0, 0 5, 5 5, 5 0, 0 0)), ((10 10, 10 15, 15 15, 15 10, 10 10)))', write(Geos.create_multi_polygon(
331
+ def test_create_geometry_collection
332
+ skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_geometry_collection)
333
+
334
+ writer.rounding_precision = 0
335
+ assert_equal('GEOMETRYCOLLECTION EMPTY', write(Geos.create_geometry_collection))
336
+ assert_equal('GEOMETRYCOLLECTION (POLYGON ((0 0, 0 5, 5 5, 5 0, 0 0)), POLYGON ((10 10, 10 15, 15 15, 15 10, 10 10)))',
337
+ write(Geos.create_geometry_collection(
312
338
  read('POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))'),
313
339
  read('POLYGON((10 10, 10 15, 15 15, 15 10, 10 10))')
314
- )))
315
- end
340
+ ))
341
+ )
342
+ end
316
343
 
317
- def test_create_bad_multi_polygon
318
- assert_raises(TypeError) do
319
- Geos.create_multi_polygon(
320
- read('POINT(0 0)'),
321
- read('POLYGON((10 10, 10 15, 15 15, 15 10, 10 10))')
322
- )
323
- end
324
- end
344
+ def test_create_geometry_collection_with_constants_and_symbols
345
+ skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_geometry_collection)
346
+
347
+ assert_kind_of(Geos::MultiLineString, Geos.create_collection(Geos::GeomTypes::GEOS_MULTILINESTRING))
348
+ assert_kind_of(Geos::MultiLineString, Geos.create_collection(:multi_line_string))
325
349
  end
326
350
 
327
- if ENV['FORCE_TESTS'] || Geos.respond_to?(:create_geometry_collection)
328
- def test_create_geometry_collection
329
- writer.rounding_precision = 0
330
- assert_equal('GEOMETRYCOLLECTION EMPTY', write(Geos.create_geometry_collection))
331
- assert_equal('GEOMETRYCOLLECTION (POLYGON ((0 0, 0 5, 5 5, 5 0, 0 0)), POLYGON ((10 10, 10 15, 15 15, 15 10, 10 10)))',
332
- write(Geos.create_geometry_collection(
333
- read('POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))'),
334
- read('POLYGON((10 10, 10 15, 15 15, 15 10, 10 10))')
335
- ))
336
- )
337
- end
351
+ def test_create_bad_geometry_collection
352
+ skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_geometry_collection)
338
353
 
339
- def test_create_geometry_collection_with_constants_and_symbols
340
- assert_kind_of(Geos::MultiLineString, Geos.create_collection(Geos::GeomTypes::GEOS_MULTILINESTRING))
341
- assert_kind_of(Geos::MultiLineString, Geos.create_collection(:multi_line_string))
354
+ assert_raises(TypeError) do
355
+ Geos.create_geometry_collection(
356
+ read('POINT(0 0)'),
357
+ read('POLYGON((10 10, 10 15, 15 15, 15 10, 10 10))'),
358
+ 'gibberish'
359
+ )
342
360
  end
361
+ end
343
362
 
344
- def test_create_bad_geometry_collection
345
- assert_raises(TypeError) do
346
- Geos.create_geometry_collection(
347
- read('POINT(0 0)'),
348
- read('POLYGON((10 10, 10 15, 15 15, 15 10, 10 10))'),
349
- 'gibberish'
350
- )
351
- end
352
- end
363
+ def test_create_geometry_collection_with_options
364
+ skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_geometry_collection)
353
365
 
354
- def test_create_geometry_collection_with_options
355
- geom = Geos.create_collection(:multi_line_string, :srid => 4326)
366
+ geom = Geos.create_collection(:multi_line_string, :srid => 4326)
356
367
 
357
- assert_kind_of(Geos::MultiLineString, geom)
358
- assert_equal(4326, geom.srid)
359
- end
368
+ assert_kind_of(Geos::MultiLineString, geom)
369
+ assert_equal(4326, geom.srid)
360
370
  end
361
371
 
362
- if ENV['FORCE_TESTS'] || Geos.respond_to?(:create_empty_point)
363
- def test_create_empty_point
364
- assert_equal('POINT EMPTY', write(Geos.create_empty_point))
365
- end
372
+ def test_create_empty_point
373
+ skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_empty_point)
374
+
375
+ assert_equal('POINT EMPTY', write(Geos.create_empty_point))
366
376
  end
367
377
 
368
- if ENV['FORCE_TESTS'] || Geos.respond_to?(:create_empty_line_string)
369
- def test_create_empty_line_string
370
- assert_equal('LINESTRING EMPTY', write(Geos.create_empty_line_string))
371
- end
378
+ def test_create_empty_line_string
379
+ skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_empty_line_string)
380
+
381
+ assert_equal('LINESTRING EMPTY', write(Geos.create_empty_line_string))
372
382
  end
373
383
 
374
- if ENV['FORCE_TESTS'] || Geos.respond_to?(:create_empty_polygon)
375
- def test_create_empty_polygon
376
- assert_equal('POLYGON EMPTY', write(Geos.create_empty_polygon))
377
- end
384
+ def test_create_empty_polygon
385
+ skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_empty_polygon)
386
+
387
+ assert_equal('POLYGON EMPTY', write(Geos.create_empty_polygon))
378
388
  end
379
389
 
380
- if ENV['FORCE_TESTS'] || Geos.respond_to?(:create_empty_multi_point)
381
- def test_create_empty_multi_point
382
- assert_equal('MULTIPOINT EMPTY', write(Geos.create_empty_multi_point))
383
- end
390
+ def test_create_empty_multi_point
391
+ skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_multi_point)
392
+
393
+ assert_equal('MULTIPOINT EMPTY', write(Geos.create_empty_multi_point))
384
394
  end
385
395
 
386
- if ENV['FORCE_TESTS'] || Geos.respond_to?(:create_empty_multi_line_string)
387
- def test_create_empty_multi_line_string
388
- assert_equal('MULTILINESTRING EMPTY', write(Geos.create_empty_multi_line_string))
389
- end
396
+ def test_create_empty_multi_line_string
397
+ skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_empty_multi_line_string)
398
+
399
+ assert_equal('MULTILINESTRING EMPTY', write(Geos.create_empty_multi_line_string))
390
400
  end
391
401
 
392
- if ENV['FORCE_TESTS'] || Geos.respond_to?(:create_empty_multi_polygon)
393
- def test_create_empty_multi_polygon
394
- assert_equal('MULTIPOLYGON EMPTY', write(Geos.create_empty_multi_polygon))
395
- end
402
+ def test_create_empty_multi_polygon
403
+ skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_empty_multi_polygon)
404
+
405
+ assert_equal('MULTIPOLYGON EMPTY', write(Geos.create_empty_multi_polygon))
396
406
  end
397
407
 
398
- if ENV['FORCE_TESTS'] || Geos.respond_to?(:create_empty_geometry_collection)
399
- def test_create_empty_geometry_collection
400
- assert_equal('GEOMETRYCOLLECTION EMPTY', write(Geos.create_empty_geometry_collection))
401
- end
408
+ def test_create_empty_geometry_collection
409
+ skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_empty_geometry_collection)
410
+
411
+ assert_equal('GEOMETRYCOLLECTION EMPTY', write(Geos.create_empty_geometry_collection))
402
412
  end
403
413
 
404
- if ENV['FORCE_TESTS'] || Geos.respond_to?(:create_empty_linear_ring)
405
- def test_create_empty_linear_ring
406
- assert_equal('LINEARRING EMPTY', write(Geos.create_empty_linear_ring))
407
- end
414
+ def test_create_empty_linear_ring
415
+ skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_empty_linear_ring)
416
+
417
+ assert_equal('LINEARRING EMPTY', write(Geos.create_empty_linear_ring))
408
418
  end
409
419
 
410
420
  def test_create_geometry_segfault
@@ -426,18 +426,17 @@ class WkbWriterTests < MiniTest::Unit::TestCase
426
426
  end
427
427
  end
428
428
 
429
- if ENV['FORCE_TESTS'] || defined?(Geos::FFIGeos)
430
- def test_write_with_options
431
- geom = read('POINT(1 2 3)')
432
- geom.srid = 4326
429
+ def test_write_with_options
430
+ skip unless ENV['FORCE_TESTS'] || defined?(Geos::FFIGeos)
433
431
 
432
+ geom = read('POINT(1 2 3)')
433
+ geom.srid = 4326
434
434
 
435
- assert_equal('0101000020E6100000000000000000F03F0000000000000040', @wkb_writer.write_hex(geom, {
436
- :include_srid => true
437
- }))
435
+ assert_equal('0101000020E6100000000000000000F03F0000000000000040', @wkb_writer.write_hex(geom, {
436
+ :include_srid => true
437
+ }))
438
438
 
439
- assert_equal('0101000000000000000000F03F0000000000000040', @wkb_writer.write_hex(geom))
440
- end
439
+ assert_equal('0101000000000000000000F03F0000000000000040', @wkb_writer.write_hex(geom))
441
440
  end
442
441
 
443
442
  def test_illegal_output_dimensions
@@ -18,139 +18,143 @@ class WktWriterTests < MiniTest::Unit::TestCase
18
18
  assert_in_delta(98.7654321, y, TOLERANCE)
19
19
  end
20
20
 
21
- if ENV['FORCE_TESTS'] || Geos::WktWriter.method_defined?(:trim=)
22
- def test_trim
23
- geom = read('POINT(6 7)')
21
+ def test_trim
22
+ skip unless ENV['FORCE_TESTS'] || Geos::WktWriter.method_defined?(:trim=)
24
23
 
25
- writer.trim = true
26
- assert_equal('POINT (6 7)', write(geom))
24
+ geom = read('POINT(6 7)')
27
25
 
28
- writer.trim = false
29
- assert_equal('POINT (6.0000000000000000 7.0000000000000000)', write(geom))
30
- end
26
+ writer.trim = true
27
+ assert_equal('POINT (6 7)', write(geom))
28
+
29
+ writer.trim = false
30
+ assert_equal('POINT (6.0000000000000000 7.0000000000000000)', write(geom))
31
+ end
31
32
 
32
- def test_round_trip
33
- writer.trim = true
34
-
35
- [
36
- 'POINT (0 0)',
37
- 'POINT EMPTY',
38
- 'MULTIPOINT (0 1, 2 3)',
39
- 'MULTIPOINT EMPTY',
40
- 'LINESTRING (0 0, 2 3)',
41
- 'LINESTRING EMPTY',
42
- 'MULTILINESTRING ((0 1, 2 3), (10 10, 3 4))',
43
- 'MULTILINESTRING EMPTY',
44
- 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))',
45
- 'POLYGON EMPTY',
46
- 'MULTIPOLYGON (((0 0, 1 0, 1 1, 0 1, 0 0)), ((10 10, 10 14, 14 14, 14 10, 10 10), (11 11, 11 12, 12 12, 12 11, 11 11)))',
47
- 'MULTIPOLYGON EMPTY',
48
- 'GEOMETRYCOLLECTION (MULTIPOLYGON (((0 0, 1 0, 1 1, 0 1, 0 0)), ((10 10, 10 14, 14 14, 14 10, 10 10), (11 11, 11 12, 12 12, 12 11, 11 11))), POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)), MULTILINESTRING ((0 0, 2 3), (10 10, 3 4)), LINESTRING (0 0, 2 3), MULTIPOINT (0 0, 2 3), POINT (9 0))',
49
- 'GEOMETRYCOLLECTION EMPTY'
50
- ].each do |g|
51
- assert_equal(g, write(read(g)))
52
- end
33
+ def test_round_trip
34
+ skip unless ENV['FORCE_TESTS'] || Geos::WktWriter.method_defined?(:trim=)
35
+
36
+ writer.trim = true
37
+
38
+ [
39
+ 'POINT (0 0)',
40
+ 'POINT EMPTY',
41
+ 'MULTIPOINT (0 1, 2 3)',
42
+ 'MULTIPOINT EMPTY',
43
+ 'LINESTRING (0 0, 2 3)',
44
+ 'LINESTRING EMPTY',
45
+ 'MULTILINESTRING ((0 1, 2 3), (10 10, 3 4))',
46
+ 'MULTILINESTRING EMPTY',
47
+ 'POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))',
48
+ 'POLYGON EMPTY',
49
+ 'MULTIPOLYGON (((0 0, 1 0, 1 1, 0 1, 0 0)), ((10 10, 10 14, 14 14, 14 10, 10 10), (11 11, 11 12, 12 12, 12 11, 11 11)))',
50
+ 'MULTIPOLYGON EMPTY',
51
+ 'GEOMETRYCOLLECTION (MULTIPOLYGON (((0 0, 1 0, 1 1, 0 1, 0 0)), ((10 10, 10 14, 14 14, 14 10, 10 10), (11 11, 11 12, 12 12, 12 11, 11 11))), POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0)), MULTILINESTRING ((0 0, 2 3), (10 10, 3 4)), LINESTRING (0 0, 2 3), MULTIPOINT (0 0, 2 3), POINT (9 0))',
52
+ 'GEOMETRYCOLLECTION EMPTY'
53
+ ].each do |g|
54
+ assert_equal(g, write(read(g)))
53
55
  end
54
56
  end
55
57
 
56
- if ENV['FORCE_TESTS'] || Geos::WktWriter.method_defined?(:rounding_precision=)
57
- def test_rounding_precision
58
- geom = read('POINT(6.123456 7.123456)')
58
+ def test_rounding_precision
59
+ skip unless ENV['FORCE_TESTS'] || Geos::WktWriter.method_defined?(:rounding_precision=)
59
60
 
60
- tester = lambda { |expected, precision|
61
- writer.rounding_precision = precision if precision
62
- assert_equal(expected, write(geom))
63
- }
61
+ geom = read('POINT(6.123456 7.123456)')
64
62
 
65
- tester['POINT (6.1234560000000000 7.1234560000000000)', nil]
66
- tester['POINT (6.12 7.12)', 2]
67
- tester['POINT (6.12346 7.12346)', 5]
68
- tester['POINT (6.1 7.1)', 1]
69
- tester['POINT (6 7)', 0]
70
- end
63
+ tester = lambda { |expected, precision|
64
+ writer.rounding_precision = precision if precision
65
+ assert_equal(expected, write(geom))
66
+ }
71
67
 
72
- def test_rounding_precision_too_high
73
- assert_raises(RuntimeError) do
74
- @writer.rounding_precision = 1000
75
- end
76
- end
68
+ tester['POINT (6.1234560000000000 7.1234560000000000)', nil]
69
+ tester['POINT (6.12 7.12)', 2]
70
+ tester['POINT (6.12346 7.12346)', 5]
71
+ tester['POINT (6.1 7.1)', 1]
72
+ tester['POINT (6 7)', 0]
77
73
  end
78
74
 
79
- if ENV['FORCE_TESTS'] || Geos::WktWriter.method_defined?(:output_dimensions)
80
- def test_output_dimensions
81
- assert_equal(2, writer.output_dimensions)
75
+ def test_rounding_precision_too_high
76
+ assert_raises(RuntimeError) do
77
+ @writer.rounding_precision = 1000
82
78
  end
83
79
  end
84
80
 
85
- if ENV['FORCE_TESTS'] || Geos::WktWriter.method_defined?(:output_dimensions=)
86
- def test_output_dimensions_set
87
- geom_3d = read('POINT(1 2 3)')
88
- geom_2d = read('POINT(3 2)')
81
+ def test_output_dimensions
82
+ skip unless ENV['FORCE_TESTS'] || Geos::WktWriter.method_defined?(:output_dimensions)
83
+
84
+ assert_equal(2, writer.output_dimensions)
85
+ end
86
+
87
+ def test_output_dimensions_set
88
+ skip unless ENV['FORCE_TESTS'] || Geos::WktWriter.method_defined?(:output_dimensions=)
89
89
 
90
- writer.trim = true
90
+ geom_3d = read('POINT(1 2 3)')
91
+ geom_2d = read('POINT(3 2)')
91
92
 
92
- # Only 2d by default
93
- assert_equal('POINT (1 2)', write(geom_3d))
93
+ writer.trim = true
94
94
 
95
- # 3d if requested _and_ available
96
- writer.output_dimensions = 3
97
- assert_equal('POINT Z (1 2 3)', write(geom_3d))
98
- assert_equal('POINT (3 2)', write(geom_2d))
95
+ # Only 2d by default
96
+ assert_equal('POINT (1 2)', write(geom_3d))
99
97
 
100
- # 1 is invalid
101
- assert_raises(RuntimeError) do
102
- writer.output_dimensions = 1
103
- end
98
+ # 3d if requested _and_ available
99
+ writer.output_dimensions = 3
100
+ assert_equal('POINT Z (1 2 3)', write(geom_3d))
101
+ assert_equal('POINT (3 2)', write(geom_2d))
104
102
 
105
- # 4 is invalid
106
- assert_raises(RuntimeError) do
107
- writer.output_dimensions = 4
108
- end
103
+ # 1 is invalid
104
+ assert_raises(RuntimeError) do
105
+ writer.output_dimensions = 1
109
106
  end
110
107
 
111
- def test_write_with_options
112
- @writer.rounding_precision = 2
108
+ # 4 is invalid
109
+ assert_raises(RuntimeError) do
110
+ writer.output_dimensions = 4
111
+ end
112
+ end
113
113
 
114
- geom = read('POINT(1 2 3)')
115
- assert_equal('POINT (1 2)', write(geom, {
116
- :trim => true
117
- }))
114
+ def test_write_with_options
115
+ skip unless ENV['FORCE_TESTS'] || defined?(Geos::FFIGeos)
118
116
 
119
- assert_equal('POINT (1.0000 2.0000)', write(geom, {
120
- :rounding_precision => 4
121
- }))
117
+ @writer.rounding_precision = 2
122
118
 
123
- assert_equal('POINT Z (1 2 3)', write(geom, {
124
- :output_dimensions => 3,
125
- :trim => true
126
- }))
119
+ geom = read('POINT(1 2 3)')
120
+ assert_equal('POINT (1 2)', write(geom, {
121
+ :trim => true
122
+ }))
127
123
 
128
- assert_equal('POINT (1.00 2.00)', write(geom))
129
- end
124
+ assert_equal('POINT (1.0000 2.0000)', write(geom, {
125
+ :rounding_precision => 4
126
+ }))
127
+
128
+ assert_equal('POINT Z (1 2 3)', write(geom, {
129
+ :output_dimensions => 3,
130
+ :trim => true
131
+ }))
132
+
133
+ assert_equal('POINT (1.00 2.00)', write(geom))
130
134
  end
131
135
 
132
- if ENV['FORCE_TESTS'] || Geos::WktWriter.method_defined?(:old_3d=)
133
- def test_old_3d_set
134
- geom_3d = read('POINT(1 2 3)')
135
- writer.trim = true
136
+ def test_old_3d_set
137
+ skip unless ENV['FORCE_TESTS'] || Geos::WktWriter.method_defined?(:old_3d=)
136
138
 
137
- # New 3d WKT by default
138
- writer.output_dimensions = 3
139
- assert_equal('POINT Z (1 2 3)', write(geom_3d))
139
+ geom_3d = read('POINT(1 2 3)')
140
+ writer.trim = true
140
141
 
141
- # Switch to old
142
- writer.old_3d = true
143
- assert_equal('POINT (1 2 3)', write(geom_3d))
142
+ # New 3d WKT by default
143
+ writer.output_dimensions = 3
144
+ assert_equal('POINT Z (1 2 3)', write(geom_3d))
144
145
 
145
- # Old3d flag is not reset when changing dimensions
146
- writer.output_dimensions = 2
147
- assert_equal('POINT (1 2)', write(geom_3d))
148
- writer.output_dimensions = 3
149
- assert_equal('POINT (1 2 3)', write(geom_3d))
146
+ # Switch to old
147
+ writer.old_3d = true
148
+ assert_equal('POINT (1 2 3)', write(geom_3d))
150
149
 
151
- # Likewise, dimensions spec is not reset when changing old3d flag
152
- writer.old_3d = false
153
- assert_equal('POINT Z (1 2 3)', write(geom_3d))
154
- end
150
+ # Old3d flag is not reset when changing dimensions
151
+ writer.output_dimensions = 2
152
+ assert_equal('POINT (1 2)', write(geom_3d))
153
+ writer.output_dimensions = 3
154
+ assert_equal('POINT (1 2 3)', write(geom_3d))
155
+
156
+ # Likewise, dimensions spec is not reset when changing old3d flag
157
+ writer.old_3d = false
158
+ assert_equal('POINT Z (1 2 3)', write(geom_3d))
155
159
  end
156
160
  end