Skip to content

Commit

Permalink
Mask test
Browse files Browse the repository at this point in the history
  • Loading branch information
albert-de-montserrat committed Nov 18, 2024
1 parent 7fe21df commit 38016b6
Showing 1 changed file with 34 additions and 29 deletions.
63 changes: 34 additions & 29 deletions test/test_mask.jl
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

0 comments on commit 38016b6

Please sign in to comment.