-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7fe21df
commit 38016b6
Showing
1 changed file
with
34 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,46 @@ | ||
using Test | ||
using JustRelax, JustRelax.JustRelax2D | ||
import JustRelax: Mask, apply_mask, apply_mask! | ||
import JustRelax.JustRelax2D as JR2 | ||
|
||
ni = 10, 10 | ||
@testset "Mask" begin | ||
ni = 10, 10 | ||
|
||
# Test basics | ||
m = Mask(ni...) | ||
# Test basics | ||
m = Mask(ni...) | ||
|
||
@test size(m) == ni | ||
@test length(m) == prod(ni) | ||
@test axes(m) == Base.OneTo(ni), Base.OneTo(ni) | ||
@test eachindex(m) == Base.OneTo(prod(ni)) | ||
@test similar(m) isa Mask{Matrix{Float64}} | ||
@test !all(m) | ||
@test size(m) == ni | ||
@test length(m) == prod(ni) | ||
@test axes(m) == (Base.OneTo(ni[1]), Base.OneTo(ni[2])) | ||
@test eachindex(m) == Base.OneTo(prod(ni)) | ||
@test similar(m) isa Mask{Matrix{Float64}} | ||
@test !all(m) | ||
|
||
m = Mask(ni..., 4:7, 4:7) | ||
@test all(isone, m[4:7, 4:7]) | ||
m = JR2.Mask(ni..., 4:7, 4:7) | ||
@test all(isone, m[4:7, 4:7]) | ||
|
||
# test masking | ||
A = rand(ni...) | ||
B = zeros(ni...) | ||
B[4:7, 4:7] .= 5 | ||
m = Mask(ni..., 4:7, 4:7) | ||
# test masking | ||
A = rand(ni...) | ||
B = zeros(ni...) | ||
B[4:7, 4:7] .= 5 | ||
m = JR2.Mask(ni..., 4:7, 4:7) | ||
|
||
C = apply_mask(A, B, m) | ||
@test all(C[4:7, 4:7] .== 5) | ||
C = apply_mask(A, B, m) | ||
@test all(C[4:7, 4:7] .== 5) | ||
|
||
apply_mask!(A, B, m) | ||
@test all(A[4:7, 4:7] .== 5) | ||
apply_mask!(A, B, m) | ||
@test all(A[4:7, 4:7] .== 5) | ||
|
||
A = rand(ni...) | ||
@test apply_mask(A, B, m, 1, 1) == A[1, 1] | ||
@test apply_mask(A, B, m, 5, 5) == 5 | ||
A = rand(ni...) | ||
@test apply_mask(A, B, m, 1, 1) == A[1, 1] | ||
@test apply_mask(A, B, m, 5, 5) == 5 | ||
|
||
apply_mask!(A, B, m, 1, 1) | ||
apply_mask!(A, B, m, 5, 5) | ||
apply_mask!(A, B, m, 1, 1) | ||
apply_mask!(A, B, m, 5, 5) | ||
|
||
@test A[1, 1] != 5 | ||
@test A[5, 5] == 5 | ||
@test A[1, 1] != 5 | ||
@test A[5, 5] == 5 | ||
|
||
@test isone(inv(m, 1, 1)) | ||
@test iszero(inv(m, 5, 5)) | ||
@test isone(inv(m, 1, 1)) | ||
@test iszero(inv(m, 5, 5)) | ||
end |