Skip to content

Commit 8aacd2b

Browse files
authored
Merge pull request #319 from JuliaArrays/seed-unit-tests
Make unit tests deterministic by seeding the RNG
2 parents b0c971b + 7af4a69 commit 8aacd2b

File tree

6 files changed

+23
-16
lines changed

6 files changed

+23
-16
lines changed

test/abstractarray.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,14 @@
8686
end
8787

8888
@testset "full" begin
89-
m_a = randn(2,2)
89+
m_a = [0.831333 -1.91207; 0.200986 -0.69399]
9090
m_a = m_a*m_a.'
9191
m = SMatrix{2,2}(m_a)
9292
@test @inferred(full(Symmetric(m))) == m_a
9393
@test @inferred(full(Symmetric(m, :L))) == m_a
9494

95-
m_a = randn(2,2) + im*randn(2,2)
95+
m_a = [0.34911-2.08735im -0.438891-0.446692im;
96+
-0.666533-0.652323im 0.834871-2.10413im]
9697
m_a = m_a*m_a'
9798
m = SMatrix{2,2}(m_a)
9899
@test @inferred(full(Hermitian(m))) == m_a

test/det.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
@test det(eye(SMatrix{3,3})*im) == det(eye(3,3)*im)
77

88
@test det(@SMatrix [0 1 0; 1 0 0; 0 0 1]) == -1
9-
m = randn(Float64, 4,4)
9+
m = [0.570085 0.667147 0.264427 0.561446
10+
0.115197 0.141744 0.83314 0.0457302
11+
0.249238 0.841643 0.809544 0.908978
12+
0.72068 0.6155 0.210278 0.607331]
1013
@test det(SMatrix{4,4}(m)) det(m)
1114
#triu/tril
1215
@test det(@SMatrix [1 2; 0 3]) == 3

test/indexing.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
end
146146

147147
@testset "Indexing with empty vectors" begin
148-
a = randn(2,2)
148+
a = [1.0 2.0; 3.0 4.0]
149149
@test a[SVector{0,Int}()] == SVector{0,Float64}(())
150150
@test a[SVector{0,Int}(),SVector{0,Int}()] == SMatrix{0,0,Float64,0}(())
151151
b = copy(a)

test/linalg.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ using StaticArrays, Base.Test
155155

156156
@testset "trace" begin
157157
@test trace(@SMatrix [1.0 2.0; 3.0 4.0]) === 5.0
158-
@test_throws DimensionMismatch trace(@SMatrix rand(5,4))
158+
@test_throws DimensionMismatch trace(@SMatrix ones(5,4))
159159
end
160160

161161
@testset "size zero" begin

test/runtests.jl

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
using StaticArrays
22
using Base.Test
33

4+
# We generate a lot of matrices using rand(), but unit tests should be
5+
# deterministic. Therefore seed the RNG here (and further down, to avoid test
6+
# file order dependence)
7+
srand(42)
8+
49
include("testutil.jl")
510
include("SVector.jl")
611
include("MVector.jl")
@@ -18,23 +23,23 @@ include("custom_types.jl")
1823
include("core.jl")
1924
include("abstractarray.jl")
2025
include("indexing.jl")
21-
include("mapreduce.jl")
22-
include("arraymath.jl")
26+
srand(42); include("mapreduce.jl")
27+
srand(42); include("arraymath.jl")
2328
include("broadcast.jl")
2429
include("linalg.jl")
25-
include("matrix_multiply.jl")
26-
include("triangular.jl")
30+
srand(42); include("matrix_multiply.jl")
31+
srand(42); include("triangular.jl")
2732
include("det.jl")
2833
include("inv.jl")
29-
include("solve.jl")
30-
include("eigen.jl")
34+
srand(42); include("solve.jl")
35+
srand(44); include("eigen.jl")
3136
include("expm.jl")
3237
include("sqrtm.jl")
3338
include("lyap.jl")
3439
include("lu.jl")
35-
include("qr.jl")
36-
include("chol.jl")
40+
srand(42); include("qr.jl")
41+
srand(42); include("chol.jl")
3742
include("deque.jl")
3843
include("io.jl")
3944
include("svd.jl")
40-
include("fixed_size_arrays.jl")
45+
srand(42); include("fixed_size_arrays.jl")

test/triangular.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
srand()
2-
31
@testset "Triangular-matrix multiplication" begin
42
for n in (1, 2, 3, 4),
53
eltyA in (Float64, Complex128, Int),

0 commit comments

Comments
 (0)