Skip to content

Commit

Permalink
test most of the rest
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaqz committed May 16, 2024
1 parent cf541dd commit cfe3378
Show file tree
Hide file tree
Showing 10 changed files with 272 additions and 231 deletions.
17 changes: 9 additions & 8 deletions test/extensions/flexijoins.jl
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import GeometryOps as GO, GeoInterface as GI
using FlexiJoins, DataFrames

pl = GI.Polygon([GI.LinearRing([(0, 0), (1, 0), (1, 1), (0, 0)])])
pu = GI.Polygon([GI.LinearRing([(0, 0), (0, 1), (1, 1), (0, 0)])])
poly_df = DataFrame(geometry = [pl, pu], color = [:red, :blue])
@testset "Tuple-point DataDrame" begin
points = tuple.(rand(100), rand(100))
points_df = DataFrame(geometry = points)

points = tuple.(rand(100), rand(100))
points_df = DataFrame(geometry = points)
@test_nowarn joined_df = FlexiJoins.innerjoin((poly_df, points_df), by_pred(:geometry, GO.contains, :geometry))
end

@testset "Basic integration" begin
pl = GI.Polygon([GI.LinearRing([(0, 0), (1, 0), (1, 1), (0, 0)])])
pu = GI.Polygon([GI.LinearRing([(0, 0), (0, 1), (1, 1), (0, 0)])])

@test_nowarn joined_df = FlexiJoins.innerjoin((poly_df, points_df), by_pred(:geometry, GO.contains, :geometry))
@test_all_integrations "Polygon DataDrame" (pl, pu) begin
poly_df = DataFrame(geometry = [pl, pu], color = [:red, :blue])
# Test that the join happened correctly
joined_df = FlexiJoins.innerjoin((poly_df, points_df), by_pred(:geometry, GO.contains, :geometry))
@test all(GO.contains.((pl,), joined_df.geometry_1[joined_df.color .== :red]))
@test all(GO.contains.((pu,), joined_df.geometry_1[joined_df.color .== :blue]))
# Test that within also works
@test_nowarn joined_df = FlexiJoins.innerjoin((points_df, poly_df), by_pred(:geometry, GO.within, :geometry))

end

2 changes: 2 additions & 0 deletions test/methods/barycentric.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# TODO use @test_all_implementations

@testset "Mean value coordinates" begin
@testset "Preserving return type" begin
@test barycentric_coordinates(MeanValue(), Point2{BigFloat}[(0,0), (1,0), (0,1)], Point2{BigFloat}(1,1)) isa Vector{BigFloat}
Expand Down
142 changes: 76 additions & 66 deletions test/methods/equals.jl
Original file line number Diff line number Diff line change
@@ -1,50 +1,56 @@
@testset "Points/MultiPoints" begin
p1 = LG.Point([0.0, 0.0])
p2 = LG.Point([0.0, 1.0])
# Same points
@test GO.equals(p1, p1) == LG.equals(p1, p1)
@test GO.equals(p2, p2) == LG.equals(p2, p2)
# Different points
@test GO.equals(p1, p2) == LG.equals(p1, p2)

mp1 = LG.MultiPoint([[0.0, 1.0], [2.0, 2.0]])
mp2 = LG.MultiPoint([[0.0, 1.0], [2.0, 2.0], [3.0, 3.0]])
mp3 = LG.MultiPoint([p2])
# Same points
@test GO.equals(mp1, mp1) == LG.equals(mp1, mp1)
@test GO.equals(mp2, mp2) == LG.equals(mp2, mp2)
# Different points
@test GO.equals(mp1, mp2) == LG.equals(mp1, mp2)
@test GO.equals(mp1, p1) == LG.equals(mp1, p1)
# Point and multipoint
@test GO.equals(p2, mp3) == LG.equals(p2, mp3)

@test_all_integrations (p1, p2, mp1, mp2, mp3) begin
# Same points
@test GO.equals(p1, p1) == LG.equals(p1, p1)
@test GO.equals(p2, p2) == LG.equals(p2, p2)
# Different points
@test GO.equals(p1, p2) == LG.equals(p1, p2)

# Same points
@test GO.equals(mp1, mp1) == LG.equals(mp1, mp1)
@test GO.equals(mp2, mp2) == LG.equals(mp2, mp2)
# Different points
@test GO.equals(mp1, mp2) == LG.equals(mp1, mp2)
@test GO.equals(mp1, p1) == LG.equals(mp1, p1)
# Point and multipoint
@test GO.equals(p2, mp3) == LG.equals(p2, mp3)
end
end

@testset "Lines/Rings" begin
l1 = LG.LineString([[0.0, 0.0], [0.0, 10.0]])
l2 = LG.LineString([[0.0, -10.0], [0.0, 20.0]])
# Equal lines
@test GO.equals(l1, l1) == LG.equals(l1, l1)
@test GO.equals(l2, l2) == LG.equals(l2, l2)
# Different lines
@test GO.equals(l1, l2) == GO.equals(l2, l1) == LG.equals(l1, l2)

l3 = LG.LineString([[3.0, 0.0], [8.0, 5.0], [13.0, 0.0], [8.0, -5.0], [3.0, 0.0]])
r1 = LG.LinearRing([[0.0, 0.0], [5.0, 5.0], [10.0, 0.0], [5.0, -5.0], [0.0, 0.0]])
r2 = LG.LinearRing([[3.0, 0.0], [8.0, 5.0], [13.0, 0.0], [8.0, -5.0], [3.0, 0.0]])
r3 = GI.LinearRing([[3.0, 0.0], [8.0, 5.0], [13.0, 0.0], [8.0, -5.0]])
l3 = LG.LineString([[3.0, 0.0], [8.0, 5.0], [13.0, 0.0], [8.0, -5.0], [3.0, 0.0]])
# Equal rings
@test GO.equals(r1, r1) == LG.equals(r1, r1)
@test GO.equals(r2, r2) == LG.equals(r2, r2)
# Test equal rings without closing point
@test GO.equals(r2, r3)
@test GO.equals(r3, l3)
# Different rings
@test GO.equals(r1, r2) == GO.equals(r2, r1) == LG.equals(r1, r2)
# Equal linear ring and line string
@test GO.equals(r2, l3) == LG.equals(r2, l3)
# Equal line string and line
@test GO.equals(l1, GI.Line([(0.0, 0.0), (0.0, 10.0)]))
r3 = GI.LinearRing([[3.0, 0.0], [8.0, 5.0], [13.0, 0.0], [8.0, -5.0]])

@test_all_integrations (l1, l2, l3, r1, r2, r3) begin
# Equal lines
@test GO.equals(l1, l1) == LG.equals(l1, l1)
@test GO.equals(l2, l2) == LG.equals(l2, l2)
# Different lines
@test GO.equals(l1, l2) == GO.equals(l2, l1) == LG.equals(l1, l2)

# Equal rings
@test GO.equals(r1, r1) == LG.equals(r1, r1)
@test GO.equals(r2, r2) == LG.equals(r2, r2)
# Test equal rings without closing point
@test GO.equals(r2, r3)
@test GO.equals(r3, l3)
# Different rings
@test GO.equals(r1, r2) == GO.equals(r2, r1) == LG.equals(r1, r2)
# Equal linear ring and line string
@test GO.equals(r2, l3) == LG.equals(r2, l3)
# Equal line string and line
@test GO.equals(l1, GI.Line([(0.0, 0.0), (0.0, 10.0)]))
end
end

@testset "Polygons/MultiPolygons" begin
Expand Down Expand Up @@ -74,28 +80,6 @@ end
p6 = GI.Polygon([[(6, 6), (6, 1), (1, 1), (1, 6), (6, 6)]])
p7 = GI.Polygon([[(6, 6), (1, 6), (1, 1), (6, 1), (6, 6)]])
p8 = GI.Polygon([[(6, 6), (1, 6), (1, 1), (6, 1)]])
# Point and polygon aren't equal
GO.equals(pt1, p1) == LG.equals(pt1, p1)
# Linear ring and polygon aren't equal
@test GO.equals(r1, p1) == LG.equals(r1, p1)
# Equal polygon
@test GO.equals(p1, p1) == LG.equals(p1, p1)
@test GO.equals(p2, p2) == LG.equals(p2, p2)
# Equal but offset polygons
@test GO.equals(p2, p6) == LG.equals(p2, p6)
# Equal but opposite winding orders
@test GO.equals(p2, p7) == LG.equals(p2, p7)
# Equal but without closing point (implied)
@test GO.equals(p7, p8)
# Different polygons
@test GO.equals(p1, p2) == LG.equals(p1, p2)
# Equal polygons with holes
@test GO.equals(p3, p3) == LG.equals(p3, p3)
# Same exterior, different hole
@test GO.equals(p3, p4) == LG.equals(p3, p4)
# Same exterior and first hole, has an extra hole
@test GO.equals(p3, p5) == LG.equals(p3, p5)

p9 = LG.Polygon(
[[
[-53.57208251953125, 28.287451910503744],
Expand All @@ -104,9 +88,6 @@ end
[-53.57208251953125, 28.287451910503744],
]]
)
# Complex polygon
@test GO.equals(p9, p9) == LG.equals(p9, p9)

m1 = LG.MultiPolygon([
[[[0.0, 0.0], [0.0, 5.0], [5.0, 5.0], [5.0, 0.0], [0.0, 0.0]]],
[
Expand All @@ -121,11 +102,40 @@ end
],
[[[0.0, 0.0], [0.0, 5.0], [5.0, 5.0], [5.0, 0.0], [0.0, 0.0]]]
])
# Equal multipolygon
@test GO.equals(m1, m1) == LG.equals(m1, m1)
# Equal multipolygon with different order
@test GO.equals(m2, m2) == LG.equals(m2, m2)
# Equal polygon to multipolygon
m3 = LG.MultiPolygon([p3])
@test GO.equals(p1, m3) == LG.equals(p1, m3)
end

@test_all_integrations "Polygons" (pt1, r1, p1, p2, p3, p4, p5, p6, p7, p8) begin
# Point and polygon aren't equal
GO.equals(pt1, p1) == LG.equals(pt1, p1)
# Linear ring and polygon aren't equal
@test GO.equals(r1, p1) == LG.equals(r1, p1)
# Equal polygon
@test GO.equals(p1, p1) == LG.equals(p1, p1)
@test GO.equals(p2, p2) == LG.equals(p2, p2)
# Equal but offset polygons
@test GO.equals(p2, p6) == LG.equals(p2, p6)
# Equal but opposite winding orders
@test GO.equals(p2, p7) == LG.equals(p2, p7)
# Equal but without closing point (implied)
@test GO.equals(p7, p8)
# Different polygons
@test GO.equals(p1, p2) == LG.equals(p1, p2)
# Equal polygons with holes
@test GO.equals(p3, p3) == LG.equals(p3, p3)
# Same exterior, different hole
@test GO.equals(p3, p4) == LG.equals(p3, p4)
# Same exterior and first hole, has an extra hole
@test GO.equals(p3, p5) == LG.equals(p3, p5)
# Complex polygon
@test GO.equals(p9, p9) == LG.equals(p9, p9)
end

@test_all_integrations "MultiPolygons" (p1, m1, m2, m3) begin
# Equal multipolygon
@test GO.equals(m1, m1) == LG.equals(m1, m1)
# Equal multipolygon with different order
@test GO.equals(m2, m2) == LG.equals(m2, m2)
# Equal polygon to multipolygon
@test GO.equals(p1, m3) == LG.equals(p1, m3)
end
end
Loading

0 comments on commit cfe3378

Please sign in to comment.