From 93c9ae488d48d14214873d683d8f039313bdbd4d Mon Sep 17 00:00:00 2001 From: Katharine Hyatt Date: Thu, 25 Apr 2019 16:46:20 -0400 Subject: [PATCH] A few missing indices tests (#31706) * Missing IndexStyle tests * promote_shape for Tuples/Dims --- test/abstractarray.jl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/abstractarray.jl b/test/abstractarray.jl index 1ff08c36383ac..f801d9982176d 100644 --- a/test/abstractarray.jl +++ b/test/abstractarray.jl @@ -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