Skip to content

Commit 98d5c6a

Browse files
committed
Make random tests reproducible
1 parent 71b8a31 commit 98d5c6a

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

test/Project.toml

+1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
99
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1010
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
1111
SparseArraysBase = "0d5efcca-f356-4864-8770-e1ed8d78f208"
12+
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
1213
Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb"
1314
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

test/basics/test_linalg.jl

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
using SparseArraysBase: SparseArrayDOK
22
using LinearAlgebra: mul!
3-
using Random
3+
using Random: Random
4+
using StableRNGs: StableRNG
5+
6+
const rng = StableRNG(123)
47

58
# TODO: add this to main package
6-
function sprand(::Type{T}, sz::Base.Dims; p::Real=0.5) where {T}
9+
function sprand(rng::Random.AbstractRNG, ::Type{T}, sz::Base.Dims; p::Real=0.5) where {T}
710
A = SparseArrayDOK{T}(undef, sz)
811
for I in eachindex(A)
9-
if rand() < p
10-
A[I] = rand(T)
12+
if rand(rng) < p
13+
A[I] = rand(rng, T)
1114
end
1215
end
1316
return A
@@ -20,15 +23,15 @@ end
2023
szC = (szA[1], szB[2])
2124

2225
for p in 0.0:0.25:1
23-
C = sprand(T, szC; p)
24-
A = sprand(T, szA; p)
25-
B = sprand(T, szB; p)
26+
C = sprand(rng, T, szC; p)
27+
A = sprand(rng, T, szA; p)
28+
B = sprand(rng, T, szB; p)
2629

2730
check1 = mul!(Array(C), Array(A), Array(B))
2831
@test mul!(copy(C), A, B) check1
2932

30-
α = rand()
31-
β = rand()
33+
α = rand(rng, T)
34+
β = rand(rng, T)
3235
check2 = mul!(Array(C), Array(A), Array(B), α, β)
3336
@test mul!(copy(C), A, B, α, β) check2
3437
end

0 commit comments

Comments
 (0)