Skip to content

Commit

Permalink
A few missing indices tests (#31706)
Browse files Browse the repository at this point in the history
* Missing IndexStyle tests

* promote_shape for Tuples/Dims
  • Loading branch information
kshyatt authored and mbauman committed Apr 25, 2019
1 parent e753c67 commit 93c9ae4
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -970,3 +970,20 @@ end
@test get(11:15, CartesianIndex(6), nothing) === nothing
@test get(11:15, CartesianIndex(5), nothing) === 15
end

@testset "IndexStyle for various types" begin
@test Base.IndexStyle(UpperTriangular) == IndexCartesian() # subtype of AbstractArray, not of Array
@test Base.IndexStyle(Vector) == IndexLinear()
@test Base.IndexStyle(UnitRange) == IndexLinear()
@test Base.IndexStyle(UpperTriangular(rand(3, 3)), [1; 2; 3]) == IndexCartesian()
@test Base.IndexStyle(UpperTriangular(rand(3, 3)), rand(3, 3), [1; 2; 3]) == IndexCartesian()
@test Base.IndexStyle(rand(3, 3), [1; 2; 3]) == IndexLinear()
end

@testset "promote_shape for Tuples and Dims" begin
@test promote_shape((2, 1), (2,)) == (2, 1)
@test_throws DimensionMismatch promote_shape((2, 3), (2,))
@test promote_shape(Dims((2, 1)), Dims((2,))) == (2, 1)
@test_throws DimensionMismatch promote_shape(Dims((2, 2)), Dims((2,)))
@test_throws DimensionMismatch promote_shape(Dims((2, 3, 1)), Dims((2,2)))
end

0 comments on commit 93c9ae4

Please sign in to comment.