Skip to content

Commit

Permalink
mostly passing
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaqz committed May 15, 2024
1 parent 72c4e21 commit 887dfcf
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
16 changes: 9 additions & 7 deletions test/helpers.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Test, GeoInterface, ArchGDAL, GeometryBasics, LibGEOS

const TEST_MODULES = [GeoInterface, ArchGDAL, GeometryBasics, LibGEOS]

# Macro to run a block of `code` for multiple modules,
# using GeoInterface.convert for each var in `args`
macro test_all_implementations(args, code)
Expand All @@ -10,24 +12,24 @@ macro test_all_implementations(title::String, args, code)
end

function _test_all_implementations_inner(title, args, code)
args = esc(args)
code = esc(code)
args1 = esc(args)
code1 = esc(code)

let_expr = if args isa Symbol # Handle a single variable name
quote
let $args = GeoInterface.convert(mod, args)
$code
let $args1 = GeoInterface.convert(mod, $args1)
$code1
end
end
else # Handle a tuple of variable names
quote
let ($args = map(g -> GeoInterface.convert(mod, g), $args))
$code
let ($args1 = map(g -> GeoInterface.convert(mod, g), $args1))
$code1
end
end
end
quote
for mod in (GeoInterface, ArchGDAL, GeometryBasics, LibGEOS)
for mod in TEST_MODULES
@testset "$($(isempty(title) ? "" : "$title : " ))$mod" begin
$let_expr
end
Expand Down
8 changes: 4 additions & 4 deletions test/methods/centroid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

#
l2 = LG.LineString([[0.0, 0.0], [2.5, -2.5], [-5.0, -3.0], [-4.0, 6.0], [10.0, 10.0], [12.0, -14.56]])
c2, len2 = GO.centroid_and_length(l2)
c2_from_LG = LG.centroid(l2)
@test_all_implementations "Spiral line string" c2 begin
@test_all_implementations "Spiral line string" l2 begin
c2, len2 = GO.centroid_and_length(l2)
@test c2[1] GI.x(c2_from_LG)
@test c2[2] GI.y(c2_from_LG)
@test len2 59.3090856788928
Expand All @@ -24,10 +24,10 @@

# Basic linear ring - note that this still uses weighting by length
r1 = LG.LinearRing([[0.0, 0.0], [3456.0, 7894.0], [6291.0, 1954.0], [0.0, 0.0]])
c3 = GO.centroid(r1)
c3_from_LG = LG.centroid(r1)

@test_all_implementations "Basic linear ring" c3 begin
@test_all_implementations "Basic linear ring" r1 begin
c3 = GO.centroid(r1)
@test c3[1] GI.x(c3_from_LG)
@test c3[2] GI.y(c3_from_LG)
end
Expand Down
8 changes: 4 additions & 4 deletions test/methods/distance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ mp1 = LG.MultiPolygon([p1, p2])

c1 = LG.GeometryCollection([pt1, r1, p1])

@test_all_implementations (pt1, pt2, pt3, pt4, pt5, pt6, pt7, pt8, pt9, pt10, pt11, mpt1, l1, r1, r2, r3, r4, r5, p1, p2, mp1, c1) begin
@test_all_implementations (pt1, pt2, pt3, pt4, pt5, pt6, pt7, pt8, pt9, pt10, pt11, mpt1, l1, r1, r2, r3, r4, r5, p1, p2, mp1#=, c1 =#) begin
# Point and Point

# Distance from point to same point
Expand Down Expand Up @@ -106,7 +106,7 @@ c1 = LG.GeometryCollection([pt1, r1, p1])
@test GO.distance(pt11, mp1) == LG.distance(pt11, mp1)
@test GO.signed_distance(pt11, mp1)
-(min(LG.distance(pt11, r2), LG.distance(pt11, r3), LG.distance(pt11, r4), LG.distance(pt11, r5)))

# Point and Geometry Collection
@test GO.distance(pt1, c1) == LG.distance(pt1, c1)
end

# Point and Geometry Collection: convert doesn't work yet
@test GO.distance(pt1, c1) == LG.distance(pt1, c1)
2 changes: 1 addition & 1 deletion test/transformations/flip.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import GeometryOps as GO

geom = GI.Polygon([GI.LinearRing([(1, 2), (3, 4), (5, 6), (1, 2)]),
GI.LinearRing([(3, 4), (5, 6), (6, 7), (3, 4)])])
@test_all_implementation "flip" geom begin
@test_all_implementations "flip" geom begin
@test GO.flip(geom) == GI.Polygon([GI.LinearRing([(2, 1), (4, 3), (6, 5), (2, 1)]),
GI.LinearRing([(4, 3), (6, 5), (7, 6), (4, 3)])])
end

0 comments on commit 887dfcf

Please sign in to comment.