From 2c6422041c8b903b7efb843db881434bb2bc43c4 Mon Sep 17 00:00:00 2001 From: Katharine Hyatt Date: Wed, 2 Jan 2019 07:07:01 -0500 Subject: [PATCH] Two missing tests for sprand (#30551) --- stdlib/SparseArrays/test/sparsevector.jl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/stdlib/SparseArrays/test/sparsevector.jl b/stdlib/SparseArrays/test/sparsevector.jl index 92245be9fb1c3..ceee49d2940a7 100644 --- a/stdlib/SparseArrays/test/sparsevector.jl +++ b/stdlib/SparseArrays/test/sparsevector.jl @@ -170,6 +170,22 @@ end @test sprandn(r1, 100, .9) == sprandn(r2, 100, .9) @test sprand(r1, Bool, 100, .9) == sprand(r2, Bool, 100, .9) end + + # test sprand with function inputs + let xr = sprand(1000, 0.9, rand) + @test isa(xr, SparseVector{Float64,Int}) + @test length(xr) == 1000 + if !isempty(nonzeros(xr)) + @test all(nonzeros(xr) .> 0.0) + end + end + let xr = sprand(1000, 0.9, rand, Float32) + @test isa(xr, SparseVector{Float32,Int}) + @test length(xr) == 1000 + if !isempty(nonzeros(xr)) + @test all(nonzeros(xr) .> 0.0) + end + end end end ### Element access