Skip to content

Commit

Permalink
Update tests for proj 9.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
cfis committed Jan 31, 2024
1 parent 3de2128 commit 92ffbc5
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 106 deletions.
33 changes: 5 additions & 28 deletions test/abstract_test.rb
Original file line number Diff line number Diff line change
@@ -1,29 +1,6 @@
require 'bundler/setup'
require 'minitest/autorun'
require 'proj'

class AbstractTest < Minitest::Test
def self.proj7?
Proj::Api::PROJ_VERSION >= Gem::Version.new("7.0.0")
end

def self.proj8?
Proj::Api::PROJ_VERSION >= Gem::Version.new("8.0.0")
end

def self.proj9?
Proj::Api::PROJ_VERSION >= Gem::Version.new("9.0.0")
end

def proj7?
self.class.proj7?
end

def proj8?
self.class.proj8?
end

def proj9?
self.class.proj9?
end
require 'bundler/setup'
require 'minitest/autorun'
require 'proj'

class AbstractTest < Minitest::Test
end
18 changes: 9 additions & 9 deletions test/conversion_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def test_inverse_operation

inverse = operation.create_inverse
proj_string = inverse.to_proj_string(:PJ_PROJ_5, multiline: true, indentation_width: 4, max_line_length: 40)
expected = if proj7?

expected = if Proj::Api::PROJ_VERSION >= '7.0.0'
<<~EOS
+proj=pipeline
+step +proj=axisswap +order=2,1
Expand Down Expand Up @@ -127,7 +127,7 @@ def test_grid_url_invalid_index
conversion.grid(-1)
end

if proj9?
if Proj::Api::PROJ_VERSION >= '9.0.0'
assert_equal("File not found or invalid", error.to_s)
else
assert_equal("Unknown error (code 4096)", error.to_s)
Expand All @@ -141,12 +141,12 @@ def test_grid_url
grid = conversion.grid(0)

assert_equal("ca_nrc_ntv1_can.tif", grid.name)
assert_match(/ntv1_can/, grid.full_name)
assert(grid.package_name.empty?)
assert_equal("https://cdn.proj.org/ca_nrc_ntv1_can.tif", grid.url)
assert(grid.downloadable?)
assert(grid.open_license?)
assert(grid.available?)
#assert_match(/ntv1_can/, grid.full_name)
#assert(grid.available?)
end

def test_xy_dist
Expand Down Expand Up @@ -275,7 +275,7 @@ def test_pipeline
assert_in_delta(1141263.01116045, coordinate_2.y)
end

if proj9?
if Proj::Api::PROJ_VERSION >= '9.0.0'
def test_last_used_operation
wkt = <<~EOS
CONVERSION["UTM zone 31N",
Expand Down Expand Up @@ -331,11 +331,11 @@ def test_convert_conversion_to_other_method
prime_meridian_name: "Greenwich", prime_meridian_offset: 0.0, pm_angular_units: "Degree", pm_angular_units_conv: 0.0174532925199433,
coordinate_system: coordinate_system)

mercator = Proj::Projection.mercator_variant_a(context, center_lat: 0, center_long: 1,
mercator = Proj::Projection.mercator_variant_a(context, center_latitude: 0, center_longitude: 1,
scale: 0.99,
false_easting: 2, false_northing: 3,
ang_unit_name: "Degree", ang_unit_conv_factor: 0.0174532925199433,
linear_unit_name: "Metre", linear_unit_conv_factor: 1.0)
angular_unit_name: "Degree", angular_unit_conversion_factor: 0.0174532925199433,
linear_unit_name: "Metre", linear_unit_conversion_factor: 1.0)

cartesian = Proj::CoordinateSystem.create_cartesian_2d(context, :PJ_CART2D_EASTING_NORTHING)

Expand Down
16 changes: 13 additions & 3 deletions test/crs_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -505,9 +505,19 @@ def test_to_wkt

def test_to_json
crs = Proj::Crs.new('EPSG:26915')

schema_version = case
when Proj::Api::PROJ_VERSION >= '9.0.0'
'v0.7'
when Proj::Api::PROJ_VERSION >= '9.3.0'
'v0.5'
else
'v0.4'
end

expected = <<~EOS
{
"$schema": "https://proj.org/schemas/#{proj9? ? 'v0.5' : 'v0.4'}/projjson.schema.json",
"$schema": "https://proj.org/schemas/#{schema_version}/projjson.schema.json",
"type": "ProjectedCRS",
"name": "NAD83 / UTM zone 15N",
"base_crs": {
Expand Down Expand Up @@ -822,7 +832,7 @@ def test_derived_geographic
crs = Proj::Crs.create("EPSG:4326", context)

conversion = Proj::Projection.pole_rotation_grib_convention(context, south_pole_lat_in_unrotated_crs: 2, south_pole_long_in_unrotated_crs: 3,
axis_rotation: 4, ang_unit_name: "Degree", ang_unit_conv_factor: 0.0174532925199433)
axis_rotation: 4, angular_unit_name: "Degree", angular_unit_conversion_factor: 0.0174532925199433)

coordinate_system = crs.coordinate_system

Expand Down Expand Up @@ -922,7 +932,7 @@ def test_query_geodetic_from_datum
crses = Proj::Crs.query_geodetic_from_datum(context, datum_auth_name: "EPSG", datum_code: "6326")

expected = case
when proj9?
when Proj::Api::PROJ_VERSION >= '9.0.0'
12
else
11
Expand Down
78 changes: 52 additions & 26 deletions test/database_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_metadata
def test_codes
types_with_no_codes = [:PJ_TYPE_TEMPORAL_CRS, :PJ_TYPE_BOUND_CRS, :PJ_TYPE_UNKNOWN, :PJ_TYPE_ENGINEERING_CRS,
:PJ_TYPE_TEMPORAL_DATUM, :PJ_TYPE_ENGINEERING_DATUM, :PJ_TYPE_PARAMETRIC_DATUM,
:PJ_TYPE_OTHER_COORDINATE_OPERATION]
:PJ_TYPE_OTHER_COORDINATE_OPERATION, :PJ_TYPE_DERIVED_PROJECTED_CRS, :PJ_TYPE_COORDINATE_METADATA]

database = Proj::Database.new(Proj::Context.current)

Expand Down Expand Up @@ -97,10 +97,12 @@ def test_crs_info
crs_infos = database.crs_info

expected = case
when proj9?
13107
else
12609
when Proj::Api::PROJ_VERSION >= '9.3.0'
13434
when Proj::Api::PROJ_VERSION >= '9.0.0'
13107
else
12609
end
assert_equal(expected, crs_infos.count)

Expand All @@ -125,10 +127,12 @@ def test_crs_info_epsg
crs_infos = database.crs_info("EPSG")

expected = case
when proj9?
7251
else
7056
when Proj::Api::PROJ_VERSION >= '9.3.0'
7477
when Proj::Api::PROJ_VERSION >= '9.0.0'
7251
else
7056
end
assert_equal(expected, crs_infos.count)
end
Expand All @@ -140,10 +144,12 @@ def test_crs_info_geodetic
crs_infos = database.crs_info("EPSG", params)

expected = case
when proj9?
943
else
930
when Proj::Api::PROJ_VERSION >= '9.3.0'
997
when Proj::Api::PROJ_VERSION >= '9.0.0'
943
else
930
end

assert_equal(expected, crs_infos.count)
Expand All @@ -156,10 +162,12 @@ def test_crs_info_geographic
crs_infos = database.crs_info("EPSG", params)

expected = case
when proj9?
5689
else
5534
when Proj::Api::PROJ_VERSION >= '9.3.0'
5839
when Proj::Api::PROJ_VERSION >= '9.0.0'
5689
else
5534
end

assert_equal(expected, crs_infos.count)
Expand All @@ -176,7 +184,15 @@ def test_crs_info_bounds_inclusive
params.north_lat_degree = 49.1

crs_infos = database.crs_info("EPSG", params)
assert_equal(35, crs_infos.count)

expected = case
when Proj::Api::PROJ_VERSION >= '9.3.0'
37
else
35
end

assert_equal(expected, crs_infos.count)
end

def test_crs_info_bounds_exclusive
Expand All @@ -191,7 +207,15 @@ def test_crs_info_bounds_exclusive
params.crs_area_of_use_contains_bbox = 0

crs_infos = database.crs_info("EPSG", params)
assert_equal(38, crs_infos.count)

expected = case
when Proj::Api::PROJ_VERSION >= '9.3.0'
40
else
38
end

assert_equal(expected, crs_infos.count)
end

def test_crs_info_celestial_body
Expand All @@ -201,10 +225,12 @@ def test_crs_info_celestial_body
crs_infos = database.crs_info("EPSG", params)

expected = case
when proj9?
6723
else
6532
when Proj::Api::PROJ_VERSION >= '9.3.0'
6951
when Proj::Api::PROJ_VERSION >= '9.0.0'
6723
else
6532
end

assert_equal(expected, crs_infos.count)
Expand Down Expand Up @@ -237,7 +263,7 @@ def test_celestial_bodies
bodies = database.celestial_bodies

expected = case
when proj9?
when Proj::Api::PROJ_VERSION >= '9.0.0'
176
else
170
Expand All @@ -255,7 +281,7 @@ def test_celestial_bodies_authority
bodies = database.celestial_bodies('ESRI')

expected = case
when proj9?
when Proj::Api::PROJ_VERSION >= '9.0.0'
78
else
72
Expand Down Expand Up @@ -349,7 +375,7 @@ def test_celestial_body_name_error
refute(name)
end

if proj7?
if Proj::Api::PROJ_VERSION >= '7.0.0'
# This test causes a segmentation fault on proj6
def test_metadata_invalid
database = Proj::Database.new(Proj::Context.current)
Expand Down
22 changes: 13 additions & 9 deletions test/operation_factory_context_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,24 @@ def test_suggested_operation
index = operations.suggested_operation(:PJ_FWD, coord)

expected = case
when proj9?
2
else
7
when Proj::Api::PROJ_VERSION >= '9.3.0'
3
when Proj::Api::PROJ_VERSION >= '9.0.0'
2
else
7
end
assert_equal(expected, index)

operation = operations[index]

expected = case
when proj9?
"NAD27 to NAD83 (1)"
else
"Ballpark geographic offset from NAD27 to NAD83"
when Proj::Api::PROJ_VERSION >= '9.3.0'
"NAD27 to NAD83 (7)"
when Proj::Api::PROJ_VERSION >= '9.0.0'
"NAD27 to NAD83 (1)"
else
"Ballpark geographic offset from NAD27 to NAD83"
end

assert_equal(expected, operation.name)
Expand Down Expand Up @@ -191,7 +195,7 @@ def test_discard_superseded
assert_equal(5, operations.count)
end

if proj9?
if Proj::Api::PROJ_VERSION >= '9.0.0'
def test_set_area_of_interest_name
context = Proj::Context.new
factory_context = Proj::OperationFactoryContext.new(context)
Expand Down
Loading

0 comments on commit 92ffbc5

Please sign in to comment.