Skip to content

Commit

Permalink
🟩 tests with the expand keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
tpoisot committed Feb 18, 2023
1 parent a1f04a8 commit 8f45557
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions SimpleSDMLayers/test/operations/clip.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,29 @@ using Test
M = rand(Bool, (10, 10))
S = SimpleSDMPredictor(M, 0.0, 1.0, 0.0, 1.0)

cl1 = clip(S; left=0.2, right=0.6, bottom=0.5, top=1.0)
cl1 = clip(S; left = 0.2, right = 0.6, bottom = 0.5, top = 1.0)
@test typeof(cl1) == typeof(S)
@test cl1.top β‰ˆ 1.0
@test cl1.bottom β‰ˆ 0.5
@test cl1.right β‰ˆ 0.6
@test cl1.left β‰ˆ 0.2
@test clip(S; left=0.19).left <= 0.2
@test clip(S; left = 0.19).left <= 0.2

cl2 = clip(S; left=0.2, bottom=0.5)
cl2 = clip(S; left = 0.2, bottom = 0.5)
@test typeof(cl2) == typeof(S)
@test cl2.top β‰ˆ 1.0
@test cl2.bottom β‰ˆ 0.5
@test cl2.right β‰ˆ 1.0
@test cl2.left β‰ˆ 0.2

# Test the expand keyword to include points that fall on the limit between two cells
M2 = rand(Bool, (1080, 2160))
S2 = SimpleSDMPredictor(M2, -180.0, 180.0, -90.0, 90.0)
exact_lats = (S2.bottom+1.0):1.0:(S2.top-1.0)
exact_lons = (S2.left+1.0):1.0:(S2.right-1.0)
@test all([isequal(l, clip(S2; top=l).top) for l in exact_lats])
@test all([isequal(l, clip(S2; bottom=l).bottom) for l in exact_lats])
@test all([isequal(l, clip(S2; left=l).left) for l in exact_lons])
@test all([isequal(l, clip(S2; right=l).right) for l in exact_lons])

# Test that expand works, including at the edges of the layer
@test clip(S2; left = 0.0).left == 0.0
@test clip(S2; left = 0.0, expand = [:left]).left < 0.0
@test clip(S2; left = -180.0).left == -180.0
@test clip(S2; left = -180.0, expand = [:left]).left == -180.0

end

0 comments on commit 8f45557

Please sign in to comment.