Skip to content

Commit

Permalink
Add more test
Browse files Browse the repository at this point in the history
test `SHermitianCompact(1,2,3,4)`
  • Loading branch information
N5N3 committed Mar 23, 2022
1 parent 2f3d9b5 commit 294f2ef
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 3 deletions.
18 changes: 18 additions & 0 deletions test/MArray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
end

@testset "Outer constructors and macro" begin
@test_throws Exception MArray(1,2,3,4) # unknown constructor

@test MArray{Tuple{1},Int,1}((1,)).data === (1,)
@test MArray{Tuple{1},Int}((1,)).data === (1,)
@test MArray{Tuple{1}}((1,)).data === (1,)
Expand Down Expand Up @@ -189,3 +191,19 @@
@test v[] == 2
end
end

@testset "some special case" begin
@test_throws Exception MVector{1}(1, 2)
@test (@inferred(MVector{1}((1, 2)))::MVector{1,NTuple{2,Int}}).data === ((1,2),)
@test (@inferred(MVector{2}((1, 2)))::MVector{2,Int}).data === (1,2)
@test (@inferred(MVector(1, 2))::MVector{2,Int}).data === (1,2)
@test (@inferred(MVector((1, 2)))::MVector{2,Int}).data === (1,2)

@test_throws Exception MMatrix{1,1}(1, 2)
@test (@inferred(MMatrix{1,1}((1, 2)))::MMatrix{1,1,NTuple{2,Int}}).data === ((1,2),)
@test (@inferred(MMatrix{1,2}((1, 2)))::MMatrix{1,2,Int}).data === (1,2)
@test (@inferred(MMatrix{1}((1, 2)))::MMatrix{1,2,Int}).data === (1,2)
@test (@inferred(MMatrix{1}(1, 2))::MMatrix{1,2,Int}).data === (1,2)
@test (@inferred(MMatrix{2}((1, 2)))::MMatrix{2,1,Int}).data === (1,2)
@test (@inferred(MMatrix{2}(1, 2))::MMatrix{2,1,Int}).data === (1,2)
end
3 changes: 3 additions & 0 deletions test/MMatrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
end

@testset "Outer constructors and macro" begin
@test_throws Exception MMatrix(1,2,3,4) # unknown constructor

@test MMatrix{1,1,Int}((1,)).data === (1,)
@test MMatrix{1,1}((1,)).data === (1,)
@test MMatrix{1}((1,)).data === (1,)
Expand Down Expand Up @@ -52,6 +54,7 @@
test_expand_error(:(@MMatrix sin(1:5)))
test_expand_error(:(@MMatrix [1; 2; 3; 4]...))

@test ((@MMatrix [1 2.;3 4])::MMatrix{2, 2, Float64}).data === (1., 3., 2., 4.) #issue #911
@test ((@MMatrix zeros(2,2))::MMatrix{2, 2, Float64}).data === (0.0, 0.0, 0.0, 0.0)
@test ((@MMatrix fill(3.4, 2,2))::MMatrix{2, 2, Float64}).data === (3.4, 3.4, 3.4, 3.4)
@test ((@MMatrix ones(2,2))::MMatrix{2, 2, Float64}).data === (1.0, 1.0, 1.0, 1.0)
Expand Down
20 changes: 20 additions & 0 deletions test/SArray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
end

@testset "Outer constructors and macro" begin
@test_throws Exception SArray(1,2,3,4) # unknown constructor

@test SArray{Tuple{1},Int,1}((1,)).data === (1,)
@test SArray{Tuple{1},Int}((1,)).data === (1,)
@test SArray{Tuple{1}}((1,)).data === (1,)
Expand Down Expand Up @@ -175,3 +177,21 @@
@test @inferred(promote_type(SMatrix{2,3,Float32,6}, SMatrix{2,3,Complex{Float64},6})) === SMatrix{2,3,Complex{Float64},6}
end
end

@testset "some special case" begin
@test_throws Exception (SArray{Tuple{2,M,N}} where {M,N})(SArray{Tuple{3,2,1}}(1,2,3,4,5,6))

@test_throws Exception SVector{1}(1, 2)
@test (@inferred(SVector{1}((1, 2)))::SVector{1,NTuple{2,Int}}).data === ((1,2),)
@test (@inferred(SVector{2}((1, 2)))::SVector{2,Int}).data === (1,2)
@test (@inferred(SVector(1, 2))::SVector{2,Int}).data === (1,2)
@test (@inferred(SVector((1, 2)))::SVector{2,Int}).data === (1,2)

@test_throws Exception SMatrix{1,1}(1, 2)
@test (@inferred(SMatrix{1,1}((1, 2)))::SMatrix{1,1,NTuple{2,Int}}).data === ((1,2),)
@test (@inferred(SMatrix{1,2}((1, 2)))::SMatrix{1,2,Int}).data === (1,2)
@test (@inferred(SMatrix{1}((1, 2)))::SMatrix{1,2,Int}).data === (1,2)
@test (@inferred(SMatrix{1}(1, 2))::SMatrix{1,2,Int}).data === (1,2)
@test (@inferred(SMatrix{2}((1, 2)))::SMatrix{2,1,Int}).data === (1,2)
@test (@inferred(SMatrix{2}(1, 2))::SMatrix{2,1,Int}).data === (1,2)
end
5 changes: 5 additions & 0 deletions test/SHermitianCompact.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ fill3(x) = fill(3, x)
end

@testset "Outer Constructors" begin
@test @inferred(SHermitianCompact(MVector(1,2,3))) === SHermitianCompact(SVector(1,2,3))
@test_throws Exception SHermitianCompact(1,2,3)
@test_throws Exception SHermitianCompact(1,2,3,4,5)
@test @inferred(SHermitianCompact(1,2,3,4)) === SHermitianCompact(SVector(1,2,4))

for (N, L) in ((3, 6), (4, 10), (6, 21))
for T in (Int32, Int64)
@eval begin
Expand Down
2 changes: 2 additions & 0 deletions test/SMatrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
end

@testset "Outer constructors and macro" begin
@test_throws Exception SMatrix(1,2,3,4) # unknown constructor

@test SMatrix{1,1,Int}((1,)).data === (1,)
@test SMatrix{1,1}((1,)).data === (1,)
@test SMatrix{1}((1,)).data === (1,)
Expand Down
6 changes: 6 additions & 0 deletions test/Scalar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@
@test Scalar(a)[] == 2
s = Scalar(a)
@test convert(typeof(s), s) === s
@test Scalar(SVector(1,2,3))[] === SVector(1,2,3)
@test Scalar(MArray{Tuple{}}(1)) === Scalar(1)
end

@testset "issue #809" begin
@test_throws DimensionMismatch Scalar(1, 2)
end
19 changes: 19 additions & 0 deletions test/SizedArray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
end

@testset "Outer Constructors" begin
@test_throws DimensionMismatch SizedArray([3, 4])
@test SizedArray{Tuple{2},Int,1}([3, 4]).data == [3, 4]
@test SizedArray{Tuple{2},Int,1,1}([3, 4]).data == [3, 4]

Expand Down Expand Up @@ -252,3 +253,21 @@ struct OVector <: AbstractVector{Int} end
Base.length(::OVector) = 10
Base.axes(::OVector) = (0:9,)
@test_throws ArgumentError SizedVector{10}(OVector())

@testset "some special case" begin
@test_throws Exception SizedVector{1}(1, 2)
@test (@inferred(SizedVector{1}((1, 2)))::SizedVector{1,NTuple{2,Int}}) == [(1, 2)]
@test (@inferred(SizedVector{2}((1, 2)))::SizedVector{2,Int}) == [1, 2]
@test (@inferred(SizedVector(1, 2))::SizedVector{2,Int}) == [1, 2]
@test (@inferred(SizedVector((1, 2)))::SizedVector{2,Int}) == [1, 2]

@test_throws Exception SizedMatrix{1,1}(1, 2)
@test (@inferred(SizedMatrix{1,1}((1, 2)))::SizedMatrix{1,1,NTuple{2,Int}}) == fill((1, 2),1,1)
@test (@inferred(SizedMatrix{1,2}((1, 2)))::SizedMatrix{1,2,Int}) == reshape(1:2, 1, 2)
@test (@inferred(SizedMatrix{1}((1, 2)))::SizedMatrix{1,2,Int}) == reshape(1:2, 1, 2)
@test (@inferred(SizedMatrix{1}(1, 2))::SizedMatrix{1,2,Int}) == reshape(1:2, 1, 2)
@test (@inferred(SizedMatrix{2}((1, 2)))::SizedMatrix{2,1,Int}) == reshape(1:2, 2, 1)
@test (@inferred(SizedMatrix{2}(1, 2))::SizedMatrix{2,1,Int}) == reshape(1:2, 2, 1)


end
4 changes: 2 additions & 2 deletions test/ambiguities.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Allow no new ambiguities (see #18), unless you fix some old ones first!

const allowable_ambiguities = VERSION v"1.7" ? 60 :
VERSION v"1.6" ? 61 : error("version must be ≥1.6")
const allowable_ambiguities = VERSION v"1.7" ? 10 :
VERSION v"1.6" ? 11 : error("version must be ≥1.6")

# TODO: Revisit and fix. See
# https://github.com/JuliaLang/julia/pull/36962
Expand Down
20 changes: 19 additions & 1 deletion test/convert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,22 @@ end
end
mInt = SA[Int16(1) Int16(2) Int16(3); Int16(4) Int16(5) Int16(6)] # SMatrix{3,2,Int16}
@test float(typeof(mInt)) === SMatrix{2, 3, float(Int16), 6}
end
end

struct BugSArray{S<:Tuple,T,N,L} <: StaticArray{S,T,N}
data::NTuple{L,T}
BugSArray{S,T,N,L}(x::NTuple{L,Any}) where {S<:Tuple,T,N,L} = new{S,T,N,L}(map(T,x))
end
(::Type{BS})(x::Tuple) where {BS<:BugSArray} = StaticArrays.construct_type(BS, x)(x)
BugSVector{N,T,L} = BugSArray{Tuple{N},T,1,L}
@testset "missing constructor" begin
@test_throws DimensionMismatch BugSArray(1,2,3)
@test_throws ErrorException BugSVector(1,2,3) # we catch a missing constructor here.
@test BugSVector{<:Any,<:Any,3}(1,2,3) isa BugSVector{3,Int,3}
end

@testset "convert with missing/wrong size" begin
@test convert(SVector, MVector(1,2,3)) === SVector(1,2,3)
@test convert(SMatrix{3}, MVector(1,2,3)) === SMatrix{3,1}(1,2,3)
@test_throws Exception convert(SVector{1}, MVector(1,2,3))
end

0 comments on commit 294f2ef

Please sign in to comment.