Skip to content

Commit 2c64220

Browse files
kshyattandreasnoack
authored andcommitted
Two missing tests for sprand (#30551)
1 parent c154215 commit 2c64220

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

stdlib/SparseArrays/test/sparsevector.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,22 @@ end
170170
@test sprandn(r1, 100, .9) == sprandn(r2, 100, .9)
171171
@test sprand(r1, Bool, 100, .9) == sprand(r2, Bool, 100, .9)
172172
end
173+
174+
# test sprand with function inputs
175+
let xr = sprand(1000, 0.9, rand)
176+
@test isa(xr, SparseVector{Float64,Int})
177+
@test length(xr) == 1000
178+
if !isempty(nonzeros(xr))
179+
@test all(nonzeros(xr) .> 0.0)
180+
end
181+
end
182+
let xr = sprand(1000, 0.9, rand, Float32)
183+
@test isa(xr, SparseVector{Float32,Int})
184+
@test length(xr) == 1000
185+
if !isempty(nonzeros(xr))
186+
@test all(nonzeros(xr) .> 0.0)
187+
end
188+
end
173189
end
174190
end
175191
### Element access

0 commit comments

Comments
 (0)