Skip to content

Commit

Permalink
Update common tests from rgeo
Browse files Browse the repository at this point in the history
cp ../rgeo/test/common/* test/common/
  • Loading branch information
teeparham committed Dec 8, 2018
1 parent fe64d8c commit 880e3f0
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 70 deletions.
30 changes: 15 additions & 15 deletions test/common/factory_tests.rb
Expand Up @@ -10,44 +10,44 @@ module RGeo
module Tests # :nodoc:
module Common # :nodoc:
module FactoryTests # :nodoc:
def _srid
defined?(@srid) ? @srid : 0
def srid
@srid || 0
end

def test_srid_preserved_through_factory
geom = @factory.point(-10, 20)
assert_equal(_srid, geom.srid)
assert_equal(srid, geom.srid)
factory = geom.factory
assert_equal(_srid, factory.srid)
assert_equal(srid, factory.srid)
geom2 = factory.point(-20, 25)
assert_equal(_srid, geom2.srid)
assert_equal(srid, geom2.srid)
end

def test_srid_preserved_through_geom_operations
geom1 = @factory.point(-10, 20)
geom2 = @factory.point(-20, 25)
geom3 = geom1.union(geom2)
assert_equal(_srid, geom3.srid)
assert_equal(_srid, geom3.geometry_n(0).srid)
assert_equal(_srid, geom3.geometry_n(1).srid)
assert_equal(srid, geom3.srid)
assert_equal(srid, geom3.geometry_n(0).srid)
assert_equal(srid, geom3.geometry_n(1).srid)
end

def test_srid_preserved_through_geom_functions
geom1 = @factory.point(-10, 20)
geom2 = geom1.boundary
assert_equal(_srid, geom2.srid)
assert_equal(srid, geom2.srid)
end

def test_srid_preserved_through_geometry_dup
geom1 = @factory.point(-10, 20)
geom2 = geom1.clone
assert_equal(_srid, geom2.srid)
assert_equal(srid, geom2.srid)
end

def test_dup_factoryresults_in_equal_factories
dup_factory = @factory.dup
assert_equal(@factory, dup_factory)
assert_equal(_srid, dup_factory.srid)
assert_equal(srid, dup_factory.srid)
end

def test_dup_factoryresults_in_equal_hashes
Expand All @@ -56,17 +56,17 @@ def test_dup_factoryresults_in_equal_hashes
end

def test_marshal_dump_load_factory
data = ::Marshal.dump(@factory)
factory2 = ::Marshal.load(data)
data = Marshal.dump(@factory)
factory2 = Marshal.load(data)
assert_equal(@factory, factory2)
assert_equal(_srid, factory2.srid)
assert_equal(srid, factory2.srid)
end

def test_psych_dump_load_factory
data = Psych.dump(@factory)
factory2 = Psych.load(data)
assert_equal(@factory, factory2)
assert_equal(_srid, factory2.srid)
assert_equal(srid, factory2.srid)
end
end
end
Expand Down
10 changes: 2 additions & 8 deletions test/common/geometry_collection_tests.rb
Expand Up @@ -23,7 +23,6 @@ def setup

def test_creation_simple
geom = @factory.collection([@point1, @line1])
assert_not_nil(geom)
assert(RGeo::Feature::GeometryCollection === geom)
assert_equal(RGeo::Feature::GeometryCollection, geom.geometry_type)
assert_equal(2, geom.num_geometries)
Expand All @@ -33,7 +32,6 @@ def test_creation_simple

def test_creation_empty
geom = @factory.collection([])
assert_not_nil(geom)
assert(RGeo::Feature::GeometryCollection === geom)
assert_equal(RGeo::Feature::GeometryCollection, geom.geometry_type)
assert_equal(0, geom.num_geometries)
Expand All @@ -49,7 +47,6 @@ def test_bounds_check

def test_creation_save_klass
geom = @factory.collection([@point1, @line3])
assert_not_nil(geom)
assert(RGeo::Feature::GeometryCollection === geom)
assert_equal(RGeo::Feature::GeometryCollection, geom.geometry_type)
assert_equal(2, geom.num_geometries)
Expand All @@ -59,7 +56,6 @@ def test_creation_save_klass
def test_creation_compound
geom1 = @factory.collection([@point1, @line1])
geom2 = @factory.collection([@point2, geom1])
assert_not_nil(geom2)
assert(RGeo::Feature::GeometryCollection === geom2)
assert_equal(RGeo::Feature::GeometryCollection, geom2.geometry_type)
assert_equal(2, geom2.num_geometries)
Expand All @@ -69,8 +65,6 @@ def test_creation_compound
def test_creation_compound_save_klass
geom1 = @factory.collection([@point1, @line3])
geom2 = @factory.collection([@point2, geom1])
::GC.start
assert_not_nil(geom2)
assert(RGeo::Feature::GeometryCollection === geom2)
assert_equal(RGeo::Feature::GeometryCollection, geom2.geometry_type)
assert_equal(2, geom2.num_geometries)
Expand Down Expand Up @@ -129,7 +123,7 @@ def test_out_of_order_is_not_equal
geom1 = @factory.collection([@line1, @point2])
geom2 = @factory.collection([@point2, @line1])
assert(!geom1.rep_equals?(geom2))
assert_not_equal(geom1.hash, geom2.hash)
refute_equal(geom1.hash, geom2.hash)
end

def test_wkt_creation_simple
Expand Down Expand Up @@ -227,7 +221,7 @@ def test_each_enumerator
enum = geom1.each
assert_equal(@point1, enum.next)
assert_equal(@line1, enum.next)
assert_raise(::StopIteration) do
assert_raises(::StopIteration) do
enum.next
end
end
Expand Down
18 changes: 6 additions & 12 deletions test/common/line_string_tests.rb
Expand Up @@ -29,7 +29,6 @@ def test_creation_points3
point2 = @factory.point(0, 1)
point3 = @factory.point(1, 0)
line2 = @factory.line_string([point1, point2, point3])
assert_not_nil(line2)
assert_equal(RGeo::Feature::LineString, line2.geometry_type)
assert_equal(3, line2.num_points)
assert_equal(point1, line2.point_n(0))
Expand All @@ -43,7 +42,6 @@ def test_creation_points3
def test_creation_points2_degenerate
point1 = @factory.point(0, 0)
line3 = @factory.line_string([point1, point1])
assert_not_nil(line3)
assert_equal(RGeo::Feature::LineString, line3.geometry_type)
assert_equal(2, line3.num_points)
assert_equal(point1, line3.point_n(0))
Expand All @@ -54,7 +52,6 @@ def test_creation_points2_degenerate

def test_creation_points_empty
line4 = @factory.line_string([])
assert_not_nil(line4)
assert_equal(RGeo::Feature::LineString, line4.geometry_type)
assert_equal(0, line4.num_points)
assert_nil(line4.start_point)
Expand All @@ -66,7 +63,6 @@ def test_creation_line_string
point2 = @factory.point(0, 1)
point3 = @factory.point(1, 1)
line1 = @factory.line_string([point1, point2, point3])
assert_not_nil(line1)
assert(RGeo::Feature::LineString === line1)
assert(!(RGeo::Feature::LinearRing === line1))
assert(!(RGeo::Feature::Line === line1))
Expand All @@ -78,12 +74,11 @@ def test_creation_linear_ring
point2 = @factory.point(0, 1)
point3 = @factory.point(1, 0)
line1 = @factory.linear_ring([point1, point2, point3, point1])
assert_not_nil(line1)
assert(line1.is_ring?)
assert(RGeo::Feature::LinearRing === line1)
assert_equal(RGeo::Feature::LinearRing, line1.geometry_type)
line2 = @factory.linear_ring([point1, point2, point3])
assert_not_nil(line2)
assert(line2)
assert(line2.is_ring?)
assert(RGeo::Feature::LinearRing === line2)
assert_equal(4, line2.num_points)
Expand All @@ -94,18 +89,17 @@ def test_creation_line
point1 = @factory.point(0, 0)
point2 = @factory.point(0, 1)
line1 = @factory.line(point1, point2)
assert_not_nil(line1)
assert(RGeo::Feature::Line === line1)
assert_equal(RGeo::Feature::Line, line1.geometry_type)
end

def test_creation_errors
point1 = @factory.point(0, 0)
collection = point1.boundary
assert_raise(RGeo::Error::InvalidGeometry) do
assert_raises(RGeo::Error::InvalidGeometry) do
@factory.line_string([point1])
end
assert_raise(RGeo::Error::InvalidGeometry) do
assert_raises(RGeo::Error::InvalidGeometry) do
@factory.line_string([point1, collection])
end
end
Expand Down Expand Up @@ -212,7 +206,7 @@ def test_out_of_order_is_not_equal
point5 = @factory.point(0, 0)
line2 = @factory.line_string([point4, point5])
assert(!line1.rep_equals?(line2))
assert_not_equal(line1.hash, line2.hash)
refute_equal(line1.hash, line2.hash)
end

def test_wkt_creation
Expand Down Expand Up @@ -303,8 +297,8 @@ def test_marshal_roundtrip
point1 = @factory.point(0, 0)
point2 = @factory.point(0, 1)
line1 = @factory.line_string([point1, point2])
data = ::Marshal.dump(line1)
line2 = ::Marshal.load(data)
data = Marshal.dump(line1)
line2 = Marshal.load(data)
assert_equal(line1, line2)
end

Expand Down
5 changes: 1 addition & 4 deletions test/common/multi_line_string_tests.rb
Expand Up @@ -25,7 +25,7 @@ def setup

def test_creation_simple
geom = @factory.multi_line_string([@linestring1, @linestring2])
assert_not_nil(geom)
assert(geom)
assert(RGeo::Feature::MultiLineString === geom)
assert_equal(RGeo::Feature::MultiLineString, geom.geometry_type)
assert_equal(2, geom.num_geometries)
Expand All @@ -35,7 +35,6 @@ def test_creation_simple

def test_creation_empty
geom = @factory.multi_line_string([])
assert_not_nil(geom)
assert(RGeo::Feature::MultiLineString === geom)
assert_equal(RGeo::Feature::MultiLineString, geom.geometry_type)
assert_equal(0, geom.num_geometries)
Expand All @@ -44,7 +43,6 @@ def test_creation_empty

def test_creation_save_types
geom = @factory.multi_line_string([@linestring1, @linearring1, @line1])
assert_not_nil(geom)
assert(RGeo::Feature::MultiLineString === geom)
assert_equal(RGeo::Feature::MultiLineString, geom.geometry_type)
assert_equal(3, geom.num_geometries)
Expand All @@ -56,7 +54,6 @@ def test_creation_casting
mls1 = @factory.collection([@line1])
mls2 = @factory.multi_line_string([@linearring1])
geom = @factory.multi_line_string([@linestring1, @linestring2, mls1, mls2])
assert_not_nil(geom)
assert_equal(RGeo::Feature::MultiLineString, geom.geometry_type)
assert_equal(4, geom.num_geometries)
assert(@linestring1.eql?(geom[0]))
Expand Down
6 changes: 2 additions & 4 deletions test/common/multi_point_tests.rb
Expand Up @@ -21,7 +21,6 @@ def setup

def test_creation_simple
geom = @factory.multi_point([@point1, @point2])
assert_not_nil(geom)
assert(RGeo::Feature::MultiPoint === geom)
assert_equal(RGeo::Feature::MultiPoint, geom.geometry_type)
assert_equal(2, geom.num_geometries)
Expand All @@ -31,7 +30,6 @@ def test_creation_simple

def test_creation_empty
geom = @factory.multi_point([])
assert_not_nil(geom)
assert(RGeo::Feature::MultiPoint === geom)
assert_equal(RGeo::Feature::MultiPoint, geom.geometry_type)
assert_equal(0, geom.num_geometries)
Expand All @@ -42,7 +40,7 @@ def test_creation_casting
mp1 = @factory.collection([@point3])
mp2 = @factory.multi_point([@point4])
geom = @factory.multi_point([@point1, @point2, mp1, mp2])
assert_not_nil(geom)
assert(geom)
assert_equal(RGeo::Feature::MultiPoint, geom.geometry_type)
assert_equal(4, geom.num_geometries)
assert(@point1.eql?(geom[0]))
Expand All @@ -53,7 +51,7 @@ def test_creation_casting

def test_creation_wrong_type
line = @factory.line_string([@point1, @point2])
assert_raise(RGeo::Error::InvalidGeometry) do
assert_raises(RGeo::Error::InvalidGeometry) do
@factory.multi_point([@point3, line])
end
end
Expand Down
8 changes: 3 additions & 5 deletions test/common/multi_polygon_tests.rb
Expand Up @@ -35,7 +35,6 @@ def setup

def test_creation_simple
geom = @factory.multi_polygon([@poly1, @poly2])
assert_not_nil(geom)
assert(RGeo::Feature::MultiPolygon === geom)
assert_equal(RGeo::Feature::MultiPolygon, geom.geometry_type)
assert_equal(2, geom.num_geometries)
Expand All @@ -45,29 +44,28 @@ def test_creation_simple

def test_creation_empty
geom = @factory.multi_polygon([])
assert_not_nil(geom)
assert(RGeo::Feature::MultiPolygon === geom)
assert_equal(RGeo::Feature::MultiPolygon, geom.geometry_type)
assert_equal(0, geom.num_geometries)
assert_equal([], geom.to_a)
end

def test_creation_wrong_type
assert_raise(RGeo::Error::InvalidGeometry) do
assert_raises(RGeo::Error::InvalidGeometry) do
@factory.multi_polygon([@poly1, @line1])
end
end

def test_creation_overlapping
assert_raise(RGeo::Error::InvalidGeometry) do
assert_raises(RGeo::Error::InvalidGeometry) do
@factory.multi_polygon([@poly1, @poly1])
end
geom = @lenient_factory.multi_polygon([@poly1, @poly1])
assert_equal RGeo::Feature::MultiPolygon, geom.geometry_type
end

def test_creation_connected
assert_raise(RGeo::Error::InvalidGeometry) do
assert_raises(RGeo::Error::InvalidGeometry) do
@factory.multi_polygon([@poly3, @poly4])
end
geom = @lenient_factory.multi_polygon([@poly3, @poly4])
Expand Down

0 comments on commit 880e3f0

Please sign in to comment.