Skip to content

Commit

Permalink
skip inferred test for old Julia version
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnychen94 committed May 2, 2022
1 parent fbc4565 commit 87e6383
Showing 1 changed file with 45 additions and 13 deletions.
58 changes: 45 additions & 13 deletions test/structuring_element.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,41 +21,65 @@
@test se_mask == Bool[0 0 0; 0 0 0; 0 1 0; 1 1 1; 1 1 1]

se = @inferred strel(Bool, CartesianIndex{2}[])
@test se == Bool[1;;]
@test se == reshape(Bool[1], (1, 1)) # v1.7: Bool[1;;]

# invalid cases
se = [CartesianIndex(1), CartesianIndex(1, 1)]
@test_throws MethodError strel(se)
@test_throws ErrorException strel(se)
end

@testset "mask to offset" begin
se = Bool[1, 0, 1]
se_offsets = @inferred strel(CartesianIndex, se)
se_offsets = if VERSION >= v"1.6"
@inferred strel(CartesianIndex, se)
else
strel(CartesianIndex, se)
end
@test se_offsets == [CartesianIndex(-1,), CartesianIndex(1,)]
@test se_offsets == strel(CartesianIndex, Bool[1, 1, 1])

se = Bool[1 0 0; 0 1 0; 0 0 1]
se_offsets = @inferred strel(CartesianIndex, se)
se_offsets = if VERSION >= v"1.6"
@inferred strel(CartesianIndex, se)
else
strel(CartesianIndex, se)
end
@test se_offsets == [CartesianIndex(-1, -1), CartesianIndex(1, 1)]
# internally, CartesianIndex is converted to SEOffsets
se_offsets = @inferred strel(ImageMorphology.SEOffsets{2}(), se)
se_offsets = if VERSION >= v"1.6"
@inferred strel(ImageMorphology.SEOffsets{2}(), se)
else
strel(ImageMorphology.SEOffsets{2}(), se)
end
@test se_offsets == [CartesianIndex(-1, -1), CartesianIndex(1, 1)]

se = trues((3, 3))
se_offsets = @inferred strel(CartesianIndex, se)
se_offsets = if VERSION >= v"1.6"
@inferred strel(CartesianIndex, se)
else
strel(CartesianIndex, se)
end
@test se_offsets == filter(x -> !iszero(x), vec(CartesianIndices((-1:1, -1:1))))

se = @inferred strel(CartesianIndex, falses(3, 3))
se = if VERSION >= v"1.6"
@inferred strel(CartesianIndex, falses(3, 3))
else
strel(CartesianIndex, falses(3, 3))
end
@test isempty(se)
end

@testset "center point" begin
for se in [Bool[1 0 0; 0 1 0; 0 0 1], Bool[1 0 0; 0 0 0; 0 0 1]]
# center point is always excluded in offsets
se_offset = @inferred strel(CartesianIndex, se)
@test se_offset == [CartesianIndex(-1, -1), CartesianIndex(1, 1)]
se_offsets = if VERSION >= v"1.6"
@inferred strel(CartesianIndex, se)
else
strel(CartesianIndex, se)
end
@test se_offsets == [CartesianIndex(-1, -1), CartesianIndex(1, 1)]
# but included in mask
se_mask = @inferred strel(Bool, se_offset)
se_mask = @inferred strel(Bool, se_offsets)
@test se_mask == Bool[1 0 0; 0 1 0; 0 0 1]
end
end
Expand Down Expand Up @@ -113,7 +137,11 @@ end

@testset "strel conversion" begin
se = strel_diamond((3, 3))
se_offsets = @inferred strel(CartesianIndex, se)
se_offsets = if VERSION >= v"1.6"
@inferred strel(CartesianIndex, se)
else
strel(CartesianIndex, se)
end
@test se_offsets == [CartesianIndex(0, -1), CartesianIndex(-1, 0), CartesianIndex(1, 0), CartesianIndex(0, 1)]
se_mask = @inferred strel(Bool, se)
# not BitMatrix as SEDiamondArray provides more information of what the SE is
Expand Down Expand Up @@ -185,7 +213,11 @@ end

@testset "strel conversion" begin
se = strel_window((3, 3))
se_offsets = @inferred strel(CartesianIndex, se)
se_offsets = if VERSION >= v"1.6"
@inferred strel(CartesianIndex, se)
else
strel(CartesianIndex, se)
end
@test se_offsets == filter(i->!iszero(i), vec(CartesianIndices((-1:1, -1:1))))
se_mask = @inferred strel(Bool, se)
# not BitMatrix as SEWindowArray provides more information of what the SE is
Expand All @@ -212,7 +244,7 @@ end
@test strel_type(CartesianIndices((-1:1, -1:1))) isa ImageMorphology.SEOffsets
@test strel_type(trues(3, 3)) isa ImageMorphology.SEMask

msg = "invalid structuring element data type: Vector{CartesianIndex}"
msg = "invalid structuring element data type: $(Vector{CartesianIndex})"
@test_throws ErrorException(msg) strel_type(CartesianIndex[])
end

Expand Down

0 comments on commit 87e6383

Please sign in to comment.