Skip to content

Commit

Permalink
add tests clarifying the output distribution of sprand
Browse files Browse the repository at this point in the history
  • Loading branch information
abraunst committed Jan 4, 2019
1 parent 6f04355 commit f6517ca
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions stdlib/SparseArrays/test/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2396,6 +2396,21 @@ end
@test m2.module == SparseArrays
end

@testset "sprand" begin
p=0.3; m=1000; n=2000;
for s in 1:10
# build a (dense) random matrix with randsubset + rand
Random.seed!(s);
v = randsubseq(1:m*n,p);
x = zeros(m,n);
x[v] .= rand(length(v));
# redo the same with sprand
Random.seed!(s);
a = sprand(m,n,p);
@test x == a
end
end

@testset "sprandn with type $T" for T in (Float64, Float32, Float16, ComplexF64, ComplexF32, ComplexF16)
@test sprandn(T, 5, 5, 0.5) isa AbstractSparseMatrix{T}
end
Expand Down

0 comments on commit f6517ca

Please sign in to comment.