Skip to content

Commit d71119b

Browse files
authored
Merge pull request #42 from Sov-trotter/rect-tests
Improve tests coverage
2 parents 3b7784c + f2041a8 commit d71119b

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

test/geometrytypes.jl

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,4 +238,90 @@ end
238238
@test origin(split2) == Vec(0, 1)
239239
@test in(split1, rect1)
240240
@test !in(rect1, split1)
241+
242+
prim = Rect(0.0, 0.0, 1.0, 1.0)
243+
@test length(prim) == 2
244+
245+
@test width(prim) == 1.0
246+
@test height(prim) == 1.0
247+
248+
b1 = Rect2D(0.0, 0.0, 2.0, 2.0)
249+
b2 = Rect2D(0, 0, 2, 2)
250+
@test isequal(b1, b2)
251+
252+
pt = Point(1.0, 1.0)
253+
b1 = Rect(0.0, 0.0, 1.0, 1.0)
254+
@test in(pt, b1)
255+
256+
rect = Rect(0.0, 0.0, 1.0, 1.0)
257+
@test GeometryBasics.positive_widths(rect) isa GeometryBasics.HyperRectangle{2,Float64}
258+
259+
h1 = Rect(0.0, 0.0, 1.0, 1.0)
260+
h2 = Rect(1.0, 1.0, 2.0, 2.0)
261+
@test union(h1, h2) isa GeometryBasics.HyperRectangle{2,Float64}
262+
@test GeometryBasics.diff(h1, h2) == h1
263+
@test GeometryBasics.intersect(h1, h2) isa GeometryBasics.HyperRectangle{2,Float64}
264+
265+
b = Rect(0.0, 0.0, 1.0, 1.0)
266+
v = Vec(1, 2)
267+
@test update(b, v) isa GeometryBasics.HyperRectangle{2,Float64}
268+
v = Vec(1.0, 2.0)
269+
@test update(b, v) isa GeometryBasics.HyperRectangle{2,Float64}
270+
271+
p = Vec(5.0, 4.0)
272+
rect = Rect(0.0, 0.0, 1.0, 1.0)
273+
@test min_dist_dim(rect, p, 1) == 4.0
274+
@test min_dist_dim(rect, p, 2) == 3.0
275+
@test max_dist_dim(rect, p ,1) == 5.0
276+
@test max_dist_dim(rect, p ,2) == 4.0
277+
278+
rect1 = Rect(0.0, 0.0, 1.0, 1.0)
279+
rect2 = Rect(3.0, 1.0, 4.0, 2.0)
280+
@test min_dist_dim(rect1, rect2, 1) == 2.0
281+
@test min_dist_dim(rect1, rect2, 2) == 0.0
282+
@test max_dist_dim(rect1, rect2, 1) == 7.0
283+
@test max_dist_dim(rect1, rect2, 2) == 3.0
284+
285+
@test !before(rect1, rect2)
286+
rect1 = Rect(0.0, 0.0, 1.0, 1.0)
287+
rect2 = Rect(3.0, 2.0, 4.0, 2.0)
288+
@test before(rect1, rect2)
289+
290+
@test !meets(rect1, rect2)
291+
rect2 = Rect(1.0, 1.0, 4.0, 2.0)
292+
@test meets(rect1, rect2)
293+
294+
rect1 = Rect(1.0, 1.0, 2.0, 2.0)
295+
rect2 = Rect(0.0, 0.0, 2.0, 1.0)
296+
@test !overlaps(rect1, rect2)
297+
rect1 = Rect(1.0, 1.0, 2.0, 2.0)
298+
rect2 = Rect(1.0, 1.0, 2.0, 2.0)
299+
@test !overlaps(rect1, rect2)
300+
301+
302+
rect1 = Rect(1.0, 1.0, 2.0, 2.0)
303+
rect2 = Rect(0.0, 0.0, 2.0, 1.0)
304+
@test !GeometryBasics.starts(rect1, rect2)
305+
rect2 = Rect(1.0, 1.0, 1.5, 1.5)
306+
@test !GeometryBasics.starts(rect1, rect2)
307+
rect2 = Rect(1.0, 1.0, 3.0, 3.0)
308+
@test GeometryBasics.starts(rect1, rect2)
309+
310+
rect1 = Rect(1.0, 1.0, 2.0, 2.0)
311+
rect2 = Rect(0.0, 0.0, 4.0, 4.0)
312+
@test during(rect1, rect2)
313+
rect1 = Rect(0.0, 0.0, 2.0, 3.0)
314+
rect2 = Rect(1.0, 1.0, 4.0, 2.0)
315+
@test !during(rect1, rect2)
316+
317+
rect1 = Rect(1.0, 1.0, 2.0, 2.0)
318+
rect2 = Rect(0.0, 0.0, 4.0, 4.0)
319+
@test !finishes(rect1, rect2)
320+
rect1 = Rect(1.0, 0.0, 1.0, 1.0)
321+
rect2 = Rect(0.0, 0.0, 2.0, 1.0)
322+
@test !finishes(rect1, rect2)
323+
rect1 = Rect(1.0, 1.0, 1.0, 2.0)
324+
rect2 = Rect(0.0, 0.0, 2.0, 3.0)
325+
@test finishes(rect1, rect2)
326+
241327
end

test/runtests.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ using LinearAlgebra
8181
p = Point(1.1, 2.2)
8282
@test p isa AbstractVector{Float64}
8383
pm = GeometryBasics.PointMeta(1.1, 2.2; a=1, b=2)
84+
p1 = Point(2.2, 3.6)
85+
p2 = [p, p1]
86+
@test coordinates(p2) == p2
8487
@test meta(pm) === (a=1, b=2)
8588
@test metafree(pm) === p
8689
@test propertynames(pm) == (:position, :a, :b)
@@ -311,6 +314,10 @@ end
311314
@test normals(m_normals) isa Vector{Vec3f0}
312315

313316
@test texturecoordinates(m) == nothing
317+
r2 = Rect2D(0.0, 0.0, 1.0, 1.0)
318+
@test iterate(texturecoordinates(r2)) == ((0.0, 1.0), ((0.0, 2), (1.0, 2)))
319+
r3 = Rect3D(0.0, 0.0, 1.0, 1.0, 2.0, 2.0)
320+
@test iterate(texturecoordinates(r3)) == ([0, 0, 0], 2)
314321
uv = decompose_uv(m)
315322
@test Rect(Point.(uv)) == Rect(0, 0, 1, 1)
316323

0 commit comments

Comments
 (0)