Skip to content

Commit ef380c3

Browse files
committed
Add tests
1 parent cc400b7 commit ef380c3

File tree

1 file changed

+31
-19
lines changed

1 file changed

+31
-19
lines changed

test/runtests.jl

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,38 +56,32 @@ using GeometryBasics: attributes
5656
end
5757

5858
end
59+
5960
@testset "polygon with metadata" begin
6061
polys = [Polygon(rand(Point{2, Float32}, 20)) for i in 1:10]
6162
pnames = [randstring(4) for i in 1:10]
6263
numbers = LinRange(0.0, 1.0, 10)
6364
bin = rand(Bool, 10)
64-
# create just an array
65-
plain = meta(polys, name = pnames, value = numbers, category = bin)
65+
# create a polygon
66+
poly = PolygonMeta(polys[1], name = pnames[1], value = numbers[1], category = bin[1])
6667
# create a MultiPolygon with the right type & meta information!
67-
multipoly = MultiPolygon(polys; name = pnames, value = numbers, category = bin)
68-
for x in (plain, multipoly)
69-
for (mp, p, n, num, b) in zip(x, polys, pnames, numbers, bin)
70-
@test mp.polygon == p
71-
@test mp.name == n
72-
@test mp.value == num
73-
@test mp.category == b
74-
end
75-
76-
filtered = filter(i -> i.value < 0.7, x)
77-
@test length(filtered) == 7
78-
end
79-
@test GeometryBasics.getcolumn(plain, :name) == pnames
80-
@test GeometryBasics.MetaType(Polygon) == PolygonMeta
81-
@test_throws ErrorException GeometryBasics.meta(plain)
68+
multipoly = MultiPolygonMeta(polys, name = pnames, value = numbers, category = bin)
69+
@test multipoly isa AbstractVector
70+
@test poly isa GeometryBasics.AbstractPolygon
71+
72+
@test GeometryBasics.getcolumn(poly, :name) == pnames[1]
8273
@test GeometryBasics.MetaFree(PolygonMeta) == Polygon
8374

75+
@test GeometryBasics.getcolumn(multipoly, :name) == pnames
76+
@test GeometryBasics.MetaFree(MultiPolygonMeta) == MultiPolygon
77+
8478
meta_p = meta(polys[1], boundingbox=Rect(0, 0, 2, 2))
8579
@test meta_p.boundingbox === Rect(0, 0, 2, 2)
8680
@test metafree(meta_p) === polys[1]
8781
attributes(meta_p) == Dict{Symbol, Any}(:boundingbox => meta_p.boundingbox,
8882
:polygon => polys[1])
8983
end
90-
84+
9185
@testset "point with metadata" begin
9286
p = Point(1.1, 2.2)
9387
@test p isa AbstractVector{Float64}
@@ -99,8 +93,26 @@ using GeometryBasics: attributes
9993
@test metafree(pm) === p
10094
@test propertynames(pm) == (:position, :a, :b)
10195
end
96+
97+
@testset "MultiPoint with metadata" begin
98+
p = collect(Point{2, Float64}(x, x+1) for x in 1:5)
99+
@test p isa AbstractVector
100+
mpm = MultiPointMeta(p, a=1, b=2)
101+
@test coordinates(mpm) == mpm
102+
@test meta(mpm) === (a=1, b=2)
103+
@test metafree(mpm) == p
104+
@test propertynames(mpm) == (:points, :a, :b)
105+
end
106+
107+
@testset "LineString with metadata" begin
108+
linestring = LineStringMeta(Point{2, Int}[(10, 10), (20, 20), (10, 40)], a = 1, b = 2)
109+
@test linestring isa AbstractVector
110+
@test meta(linestring) === (a = 1, b = 2)
111+
@test metafree(linestring) == linestring
112+
@test propertynames(linestring) == (:lines, :a, :b)
113+
end
102114

103-
@testset "MultiLineString with metadata" begin
115+
@testset "MultiLineString with metadata" begin
104116
linestring1 = LineString(Point{2, Int}[(10, 10), (20, 20), (10, 40)])
105117
linestring2 = LineString(Point{2, Int}[(40, 40), (30, 30), (40, 20), (30, 10)])
106118
multilinestring = MultiLineString([linestring1, linestring2])

0 commit comments

Comments
 (0)