Skip to content

Commit ab04f58

Browse files
kshyattandyferris
authored andcommitted
Add error tests (#269)
* Add error tests, test_broken failing test * Add tests for rand! * Get rand for ranges working too * A few more SDiag and linalg tests * Fix lost Size
1 parent 79ac5f1 commit ab04f58

File tree

10 files changed

+48
-11
lines changed

10 files changed

+48
-11
lines changed

src/arraymath.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ end
5858

5959
@inline rand(rng::AbstractRNG, range::AbstractArray, ::SA) where {SA <: StaticArray} = rand(rng, range, SA)
6060
@inline rand(rng::AbstractRNG, range::AbstractArray, ::Type{SA}) where {SA <: StaticArray} = _rand(rng, range, Size(SA), SA)
61+
@inline rand(range::AbstractArray, ::SA) where {SA <: StaticArray} = rand(Base.GLOBAL_RNG, range, SA)
62+
@inline rand(range::AbstractArray, ::Type{SA}) where {SA <: StaticArray} = _rand(Base.GLOBAL_RNG, range, Size(SA), SA)
6163
@generated function _rand(rng::AbstractRNG, range::AbstractArray, ::Size{s}, ::Type{SA}) where {s, SA <: StaticArray}
6264
v = [:(rand(rng, range)) for i = 1:prod(s)]
6365
return quote
@@ -66,6 +68,9 @@ end
6668
end
6769
end
6870

71+
#@inline rand(rng::MersenneTwister, range::AbstractArray, ::SA) where {SA <: StaticArray} = rand(rng, range, SA)
72+
#@inline rand(rng::MersenneTwister, range::AbstractArray, ::Type{SA}) where {SA <: StaticArray} = _rand(rng, range, Size(SA), SA)
73+
6974
@inline randn(rng::AbstractRNG, ::SA) where {SA <: StaticArray} = randn(rng, SA)
7075
@inline randn(rng::AbstractRNG, ::Type{SA}) where {SA <: StaticArray} = _randn(rng, Size(SA), SA)
7176
@generated function _randn(rng::AbstractRNG, ::Size{s}, ::Type{SA}) where {s, SA <: StaticArray}
@@ -123,6 +128,7 @@ end
123128

124129
# ambiguity with AbstractRNG and non-Float64... possibly an optimized form in Base?
125130
@inline rand!(rng::MersenneTwister, a::SA) where {SA <: StaticArray{<:Any, Float64}} = _rand!(rng, Size(SA), a)
131+
@inline rand!(rng::MersenneTwister, a::SA) where {SA <: StaticArray{<:Tuple, Float64, <:Any}} = _rand!(rng, Size(SA), a)
126132

127133
@inline randn!(rng::AbstractRNG, a::SA) where {SA <: StaticArray} = _randn!(rng, Size(SA), a)
128134
@generated function _randn!(rng::AbstractRNG, ::Size{s}, a::SA) where {s, SA <: StaticArray}

test/MArray.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
@test (ex = macroexpand(:(@MArray ones())); isa(ex, Expr) && ex.head == :error)
6666
@test (ex = macroexpand(:(@MArray fill(1))); isa(ex, Expr) && ex.head == :error)
6767
@test (ex = macroexpand(:(@MArray eye(5,6,7,8,9))); isa(ex, Expr) && ex.head == :error)
68+
@test (ex = macroexpand(:(@MArray [1; 2; 3; 4]...)); isa(ex, Expr) && ex.head == :error)
6869

6970
@test ((@MArray fill(3.,2,2,1))::MArray{Tuple{2,2,1}, Float64}).data === (3.0, 3.0, 3.0, 3.0)
7071
@test ((@MArray zeros(2,2,1))::MArray{Tuple{2,2,1}, Float64}).data === (0.0, 0.0, 0.0, 0.0)

test/MMatrix.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
@test (ex = macroexpand(:(@MMatrix ones)); isa(ex, Expr) && ex.head == :error)
4949
@test (ex = macroexpand(:(@MMatrix sin(1:5))); isa(ex, Expr) && ex.head == :error)
5050
@test (ex = macroexpand(:(@MMatrix eye(4, 5, 6, 7))); isa(ex, Expr) && ex.head == :error)
51+
@test (ex = macroexpand(:(@MMatrix [1; 2; 3; 4]...)); isa(ex, Expr) && ex.head == :error)
5152

5253
@test ((@MMatrix zeros(2,2))::MMatrix{2, 2, Float64}).data === (0.0, 0.0, 0.0, 0.0)
5354
@test ((@MMatrix fill(3.4, 2,2))::MMatrix{2, 2, Float64}).data === (3.4, 3.4, 3.4, 3.4)

test/MVector.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
@test (ex = macroexpand(:(@MVector sin(1:5))); isa(ex, Expr) && ex.head == :error)
4040
@test (ex = macroexpand(:(@MVector [i*j for i in 1:2, j in 2:3])); isa(ex, Expr) && ex.head == :error)
4141
@test (ex = macroexpand(:(@MVector Float32[i*j for i in 1:2, j in 2:3])); isa(ex, Expr) && ex.head == :error)
42+
@test (ex = macroexpand(:(@MVector [1; 2; 3]...)); isa(ex, Expr) && ex.head == :error)
4243
end
4344

4445
@testset "Methods" begin

test/SArray.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
@test (ex = macroexpand(:(@SArray fill())); isa(ex, Expr) && ex.head == :error)
6464
@test (ex = macroexpand(:(@SArray fill(1))); isa(ex, Expr) && ex.head == :error)
6565
@test (ex = macroexpand(:(@SArray eye(5,6,7,8,9))); isa(ex, Expr) && ex.head == :error)
66+
@test (ex = macroexpand(:(@SArray [1; 2; 3; 4]...)); isa(ex, Expr) && ex.head == :error)
6667

6768
@test ((@SArray fill(3.,2,2,1))::SArray{Tuple{2,2,1}, Float64}).data === (3.0, 3.0, 3.0, 3.0)
6869
@test ((@SArray zeros(2,2,1))::SArray{Tuple{2,2,1}, Float64}).data === (0.0, 0.0, 0.0, 0.0)

test/SDiagonal.jl

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,25 +80,30 @@
8080
@test (b'*m)' == @SVector [22,-12,26,14]
8181

8282
@test m\b == m2\b
83-
83+
8484
@test b'/m == b'/m2
8585
@test_throws Exception b/m
8686
@test m*m == m2*m
87-
87+
8888
@test ishermitian(m) == ishermitian(m2)
8989
@test ishermitian(m/2)
90-
90+
m_ireal = SDiagonal(@SVector [11+0im, 12+0im, 13+0im, 14+0im])
91+
@test ishermitian(m_ireal)
92+
9193
@test isposdef(m) == isposdef(m2)
9294
@test issymmetric(m) == issymmetric(m2)
93-
95+
9496
@test (2*m/2)' == m
9597
@test 2m == m + m
98+
@test -(-m) == m
9699
@test m*0 == m - m
97-
100+
98101
@test m*inv(m) == m/m == m\m == eye(SDiagonal{4,Float64})
99-
100-
101-
102-
102+
103+
@test factorize(m) == m
104+
@test m*[1; 1; 1; 1] == [11; 12; 13; 14]
105+
@test m\[1; 1; 1; 1] == [11; 12; 13; 14].\[1; 1; 1; 1]
106+
@test SMatrix{4,4}(eye(4))*m == m
107+
@test m*SMatrix{4,4}(eye(4)) == m
103108
end
104-
end
109+
end

test/SMatrix.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
@test (ex = macroexpand(:(@SMatrix ones)); isa(ex, Expr) && ex.head == :error)
4848
@test (ex = macroexpand(:(@SMatrix sin(1:5))); isa(ex, Expr) && ex.head == :error)
4949
@test (ex = macroexpand(:(@SMatrix eye(2, 3, 4, 5))); isa(ex, Expr) && ex.head == :error)
50+
@test (ex = macroexpand(:(@SMatrix [1; 2; 3; 4]...)); isa(ex, Expr) && ex.head == :error)
5051

5152
@test ((@SMatrix fill(1.3, 2,2))::SMatrix{2, 2, Float64}).data === (1.3, 1.3, 1.3, 1.3)
5253
@test ((@SMatrix zeros(2,2))::SMatrix{2, 2, Float64}).data === (0.0, 0.0, 0.0, 0.0)

test/SVector.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
@test (ex = macroexpand(:(@SVector sin(1:5))); isa(ex, Expr) && ex.head == :error)
4444
@test (ex = macroexpand(:(@SVector [i*j for i in 1:2, j in 2:3])); isa(ex, Expr) && ex.head == :error)
4545
@test (ex = macroexpand(:(@SVector Float32[i*j for i in 1:2, j in 2:3])); isa(ex, Expr) && ex.head == :error)
46+
@test (ex = macroexpand(:(@SVector [1; 2; 3]...)); isa(ex, Expr) && ex.head == :error)
4647
end
4748

4849
@testset "Methods" begin

test/arraymath.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,24 @@
3535
fill!(m, 3)
3636
@test all(m .== 3.)
3737
end
38+
39+
@testset "rand()" begin
40+
m = rand(1:2, SVector{3})
41+
check = ((m .>= 1) .& (m .<= 2))
42+
@test all(check)
43+
m = rand(1:2, SMatrix{4, 4})
44+
check = ((m .>= 1) .& (m .<= 2))
45+
@test all(check)
46+
end
47+
48+
@testset "rand!()" begin
49+
m = @MMatrix [0. 0.; 0. 0.]
50+
rand!(m)
51+
check = ((m .< 1.) .& (m .> 0.))
52+
@test all(check)
53+
m = @MMatrix [0. 0.; 0. 0.]
54+
rand!(m, 1:2)
55+
check = ((m .>= 1) .& (m .<= 2))
56+
@test all(check)
57+
end
3858
end

test/linalg.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ using StaticArrays, Base.Test
8383
@test @inferred(cross(SVector(1,2,3), SVector(4,5,6))) === SVector(-3, 6, -3)
8484
@test @inferred(cross(SVector(1,2), SVector(4,5))) === -3
8585
@test @inferred(cross(SVector(UInt(1),UInt(2)), SVector(UInt(4),UInt(5)))) === -3
86-
86+
@test @inferred(cross(SVector(UInt(1),UInt(2),UInt(3)), SVector(UInt(4),UInt(5),UInt(6)))) === SVector(-3, 6, -3)
8787
end
8888

8989
@testset "transpose() and conj()" begin

0 commit comments

Comments
 (0)