Skip to content

Commit

Permalink
Fix tests for GEOS 3.12+.
Browse files Browse the repository at this point in the history
  • Loading branch information
dark-panda committed Sep 22, 2023
1 parent 9854a54 commit e98c1d2
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 28 deletions.
6 changes: 5 additions & 1 deletion test/geojson_reader_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ def test_polygon_with_inner_ring

def test_multi_point
geojson_tester(
'MULTIPOINT (10.000 40.000, 40.000 30.000, 20.000 20.000, 30.000 10.000)',
if Geos::GEOS_NICE_VERSION >= '031200'
'MULTIPOINT ((10.000 40.000), (40.000 30.000), (20.000 20.000), (30.000 10.000))'
else
'MULTIPOINT (10.000 40.000, 40.000 30.000, 20.000 20.000, 30.000 10.000)'
end,
'{"type":"MultiPoint","coordinates":[[10, 40], [40, 30], [20, 20], [30, 10]]}'
)
end
Expand Down
74 changes: 55 additions & 19 deletions test/geometry_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,11 @@ def test_sym_difference

comparison_tester(
method,
'MULTIPOINT (0 0, 1 0)',
if Geos::GEOS_NICE_VERSION >= '031200'
'MULTIPOINT ((0 0), (1 0))'
else
'MULTIPOINT (0 0, 1 0)'
end,
'POINT(0 0)',
'POINT(1 0)'
)
Expand Down Expand Up @@ -365,7 +369,11 @@ def test_boundary

simple_tester(
:boundary,
'MULTIPOINT (0 0, 10 10)',
if Geos::GEOS_NICE_VERSION >= '031200'
'MULTIPOINT ((0 0), (10 10))'
else
'MULTIPOINT (0 0, 10 10)'
end,
'LINESTRING(0 0, 10 10)'
)

Expand All @@ -386,7 +394,11 @@ def test_union

comparison_tester(
:union,
'MULTIPOINT (0 0, 1 0)',
if Geos::GEOS_NICE_VERSION >= '031200'
'MULTIPOINT ((0 0), (1 0))'
else
'MULTIPOINT (0 0, 1 0)'
end,
'POINT(0 0)',
'POINT(1 0)'
)
Expand Down Expand Up @@ -468,7 +480,14 @@ def test_union_with_precision

result = geom_a.union(geom_b, precision: 2)

assert_equal('MULTIPOINT (2 8, 4 10)', write(result))
assert_equal(
if Geos::GEOS_NICE_VERSION >= '031200'
'MULTIPOINT ((2 8), (4 10))'
else
'MULTIPOINT (2 8, 4 10)'
end,
write(result)
)
end

def test_union_cascaded
Expand All @@ -486,7 +505,7 @@ def test_union_cascaded
((10 10, 10 14, 14 14, 14 10, 10 10),
(11 11, 11 12, 12 12, 12 11, 11 11)),
((0 0, 11 0, 11 11, 0 11, 0 0))
))'
)'
)
end

Expand All @@ -503,7 +522,7 @@ def test_coverage_union
'MULTIPOLYGON(
((0 0, 0 1, 1 1, 1 0, 0 0)),
((1 0, 1 1, 2 1, 2 0, 1 0))
))'
)'
)
end

Expand All @@ -522,7 +541,7 @@ def test_unary_union
((10 10, 10 14, 14 14, 14 10, 10 10),
(11 11, 11 12, 12 12, 12 11, 11 11)),
((0 0, 11 0, 11 11, 0 11, 0 0))
))'
)'
)
end

Expand All @@ -537,7 +556,7 @@ def test_unary_union_with_precision
((10 10, 10 14, 14 14, 14 10, 10 10),
(11 11, 11 12, 12 12, 12 11, 11 11)),
((0 0, 11 0, 11 11, 0 11, 0 0))
))',
)',
3
)
end
Expand Down Expand Up @@ -565,7 +584,7 @@ def test_union_without_arguments
((10 10, 10 14, 14 14, 14 10, 10 10),
(11 11, 11 12, 12 12, 12 11, 11 11)),
((0 0, 11 0, 11 11, 0 11, 0 0))
))'
)'
)
end

Expand Down Expand Up @@ -792,13 +811,17 @@ def test_extract_unique_points
LINESTRING (0 0, 2 3),
MULTIPOINT (0 0, 2 3),
POINT (9 0),
POINT(1 0)),
POINT (1 0),
LINESTRING EMPTY
')
)')

simple_tester(
:extract_unique_points,
'MULTIPOINT (0 0, 1 0, 1 1, 0 1, 10 10, 10 14, 14 14, 14 10, 11 11, 11 12, 12 12, 12 11, 2 3, 3 4, 9 0)',
if Geos::GEOS_NICE_VERSION >= '031200'
'MULTIPOINT ((0 0), (1 0), (1 1), (0 1), (10 10), (10 14), (14 14), (14 10), (11 11), (11 12), (12 12), (12 11), (2 3), (3 4), (9 0))'
else
'MULTIPOINT (0 0, 1 0, 1 1, 0 1, 10 10, 10 14, 14 14, 14 10, 11 11, 11 12, 12 12, 12 11, 2 3, 3 4, 9 0)'
end,
geom.extract_unique_points
)
end
Expand Down Expand Up @@ -972,10 +995,10 @@ def test_valid_detail

tester['Self-intersection', 'POINT (2.5 5)', 'POLYGON((0 0, 0 5, 5 5, 5 10, 0 0))', 0]

tester['Ring Self-intersection', 'POINT (0 0)', 'POLYGON((0 0, -10 10, 10 10, 0 0, 4 5, -4 5, 0 0)))', 0]
tester['Ring Self-intersection', 'POINT (0 0)', 'POLYGON((0 0, -10 10, 10 10, 0 0, 4 5, -4 5, 0 0))', 0]

assert_nil(
read('POLYGON((0 0, -10 10, 10 10, 0 0, 4 5, -4 5, 0 0)))').valid_detail(
read('POLYGON((0 0, -10 10, 10 10, 0 0, 4 5, -4 5, 0 0))').valid_detail(
:allow_selftouching_ring_forming_hole
)
)
Expand Down Expand Up @@ -1635,7 +1658,7 @@ def test_dup_srid
end

def test_line_string_enumerator
geom = read('LINESTRING(0 0, 10 10))')
geom = read('LINESTRING(0 0, 10 10)')
assert_kind_of(Enumerable, geom.each)
assert_kind_of(Enumerable, geom.to_enum)
assert_equal(geom, geom.each(&EMPTY_BLOCK))
Expand Down Expand Up @@ -1827,13 +1850,13 @@ def test_delaunay_triangulation
'GEOMETRYCOLLECTION (POLYGON ((8 2, 10 10, 8.5 1, 8 2)), POLYGON ((7 8, 10 10, 8 2, 7 8)), POLYGON ((3 8, 10 10, 7 8, 3 8)), ' \
'POLYGON ((2 2, 8 2, 8.5 1, 2 2)), POLYGON ((2 2, 7 8, 8 2, 2 2)), POLYGON ((2 2, 3 8, 7 8, 2 2)), POLYGON ((0.5 9, 10 10, 3 8, 0.5 9)), ' \
'POLYGON ((0.5 9, 3 8, 2 2, 0.5 9)), POLYGON ((0 0, 2 2, 8.5 1, 0 0)), POLYGON ((0 0, 0.5 9, 2 2, 0 0)))',
'POLYGON((0 0, 8.5 1, 10 10, 0.5 9, 0 0),(2 2, 3 8, 7 8, 8 2, 2 2)))',
'POLYGON((0 0, 8.5 1, 10 10, 0.5 9, 0 0),(2 2, 3 8, 7 8, 8 2, 2 2))',
0
]

tester[
'MULTILINESTRING ((8.5 1, 10 10), (8 2, 10 10), (8 2, 8.5 1), (7 8, 10 10), (7 8, 8 2), (3 8, 10 10), (3 8, 7 8), (2 2, 8.5 1), (2 2, 8 2), (2 2, 7 8), (2 2, 3 8), (0.5 9, 10 10), (0.5 9, 3 8), (0.5 9, 2 2), (0 0, 8.5 1), (0 0, 2 2), (0 0, 0.5 9))',
'POLYGON((0 0, 8.5 1, 10 10, 0.5 9, 0 0),(2 2, 3 8, 7 8, 8 2, 2 2)))',
'POLYGON((0 0, 8.5 1, 10 10, 0.5 9, 0 0),(2 2, 3 8, 7 8, 8 2, 2 2))',
0,
only_edges: true
]
Expand Down Expand Up @@ -1945,7 +1968,14 @@ def test_minimum_rotated_rectangle
geom = read('POLYGON ((1 6, 6 11, 11 6, 6 1, 1 6))')
minimum_rotated_rectangle = geom.minimum_rotated_rectangle

assert_equal('POLYGON ((6 1, 11 6, 6 11, 1 6, 6 1))', write(minimum_rotated_rectangle))
assert_equal(
if Geos::GEOS_NICE_VERSION >= '031200'
'POLYGON ((6 1, 1 6, 6 11, 11 6, 6 1))'
else
'POLYGON ((6 1, 11 6, 6 11, 1 6, 6 1))'
end,
write(minimum_rotated_rectangle)
)
end

def test_minimum_clearance
Expand Down Expand Up @@ -2078,7 +2108,13 @@ def test_reverse
skip unless ENV['FORCE_TESTS'] || Geos::Geometry.method_defined?(:reverse)

simple_tester(:reverse, 'POINT (3 5)', 'POINT (3 5)')
simple_tester(:reverse, 'MULTIPOINT (100 100, 10 100, 30 100)', 'MULTIPOINT (100 100, 10 100, 30 100)')

if Geos::GEOS_NICE_VERSION >= '031200'
simple_tester(:reverse, 'MULTIPOINT ((100 100), (10 100), (30 100))', 'MULTIPOINT (100 100, 10 100, 30 100)')
else
simple_tester(:reverse, 'MULTIPOINT (100 100, 10 100, 30 100)', 'MULTIPOINT (100 100, 10 100, 30 100)')
end

simple_tester(:reverse, 'LINESTRING (200 200, 200 100)', 'LINESTRING (200 100, 200 200)')

if Geos::GEOS_NICE_VERSION >= '030801'
Expand Down
6 changes: 5 additions & 1 deletion test/line_string_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ def test_offset_curve
# outside curve
simple_tester(
:offset_curve,
if Geos::GEOS_NICE_VERSION >= '031100'
if Geos::GEOS_NICE_VERSION >= '031200'
'LINESTRING (0 -2, 10 -2, 10.390180644032256 -1.9615705608064609, 10.76536686473018 -1.8477590650225735, ' \
'11.111140466039204 -1.6629392246050902, 11.414213562373096 -1.414213562373095, 11.66293922460509 -1.1111404660392044, '\
'11.847759065022574 -0.7653668647301796, 11.96157056080646 -0.3901806440322565, 12 0, 12 10)'
elsif Geos::GEOS_NICE_VERSION >= '031100'
'LINESTRING (0 -2, 10 -2, 12 0, 12 10)'
else
'LINESTRING (12 10, 12 0, 10 -2, 0 -2)'
Expand Down
8 changes: 7 additions & 1 deletion test/utils_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,13 @@ def test_create_multi_point
skip unless ENV['FORCE_TESTS'] || Geos.respond_to?(:create_multi_point)

assert_equal('MULTIPOINT EMPTY', write(Geos.create_multi_point))
assert_equal('MULTIPOINT (0 0, 10 10)',

assert_equal(
if Geos::GEOS_NICE_VERSION >= '031200'
'MULTIPOINT ((0 0), (10 10))'
else
'MULTIPOINT (0 0, 10 10)'
end,
write(
Geos.create_multi_point(
read('POINT(0 0)'),
Expand Down
28 changes: 24 additions & 4 deletions test/wkb_writer_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -433,12 +433,20 @@ def test_write_with_options
}

tester[
[1, 1, 0, 0, 32, 230, 16, 0, 0, 0, 0, 0, 0, 0, 0, 240, 63, 0, 0, 0, 0, 0, 0, 0, 64].pack('C*'),
if Geos::GEOS_NICE_VERSION >= '031200'
[1, 1, 0, 0, 160, 230, 16, 0, 0, 0, 0, 0, 0, 0, 0, 240, 63, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 8, 64].pack('C*')
else
[1, 1, 0, 0, 32, 230, 16, 0, 0, 0, 0, 0, 0, 0, 0, 240, 63, 0, 0, 0, 0, 0, 0, 0, 64].pack('C*')
end,
include_srid: true
]

tester[
[1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 240, 63, 0, 0, 0, 0, 0, 0, 0, 64].pack('C*')
if Geos::GEOS_NICE_VERSION >= '031200'
[1, 1, 0, 0, 128, 0, 0, 0, 0, 0, 0, 240, 63, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 8, 64].pack('C*')
else
[1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 240, 63, 0, 0, 0, 0, 0, 0, 0, 64].pack('C*')
end
]
end

Expand All @@ -448,13 +456,25 @@ def test_write_hex_with_options
geom = read('POINT(1 2 3)')
geom.srid = 4326

assert_equal('0101000020E6100000000000000000F03F0000000000000040',
assert_equal(
if Geos::GEOS_NICE_VERSION >= '031200'
'01010000A0E6100000000000000000F03F00000000000000400000000000000840'
else
'0101000020E6100000000000000000F03F0000000000000040'
end,
@wkb_writer.write_hex(
geom,
include_srid: true
))

assert_equal('0101000000000000000000F03F0000000000000040', @wkb_writer.write_hex(geom))
assert_equal(
if Geos::GEOS_NICE_VERSION >= '031200'
'0101000080000000000000F03F00000000000000400000000000000840'
else
'0101000000000000000000F03F0000000000000040'
end,
@wkb_writer.write_hex(geom)
)
end

def test_illegal_output_dimensions
Expand Down
12 changes: 10 additions & 2 deletions test/wkt_writer_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ def test_round_trip
[
'POINT (0 0)',
'POINT EMPTY',
'MULTIPOINT (0 1, 2 3)',
if Geos::GEOS_NICE_VERSION >= '031200'
'MULTIPOINT ((0 1), (2 3))'
else
'MULTIPOINT (0 1, 2 3)'
end,
'MULTIPOINT EMPTY',
'LINESTRING (0 0, 2 3)',
'LINESTRING EMPTY',
Expand All @@ -45,7 +49,11 @@ def test_round_trip
'POLYGON EMPTY',
'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)))',
'MULTIPOLYGON EMPTY',
'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))',
if Geos::GEOS_NICE_VERSION >= '031200'
'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))'
else
'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))'
end,
'GEOMETRYCOLLECTION EMPTY'
].each do |g|
assert_equal(g, write(read(g)))
Expand Down

0 comments on commit e98c1d2

Please sign in to comment.