Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add missing test for ones and zeros #34948

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 27 additions & 20 deletions test/arrayops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2477,27 +2477,34 @@ Float64(x::F21666) = Float64(x.x)
end

@testset "zeros and ones" begin
@test ones(2) == ones(Int, 2) == [1,1]
@test isa(ones(2), Vector{Float64})
@test isa(ones(Int, 2), Vector{Int})

function test_zeros(arr, T, s)
@test all(arr .== 0)
@test isa(arr, T)
@test size(arr) == s
for (fname, felt) in ((zeros, zero), (ones, one))
for T in (Bool, Int, Float64, ComplexF64)
A0 = fname(T)
@test A0 == fname(Int) == fill(felt(T))
@test typeof(A0) === Array{T, 0}
@test size(A0) === ()
@test isempty(fname(T, 0))

A1 = fname(T, 2)
@test A1 == fname(Int, 2) == [felt(Int), felt(Int)]
@test A1 == fname(T, Base.OneTo(2))
@test A1 == fname(T, (Base.OneTo(2), ))
@test typeof(A1) === Array{T, 1}
@test size(A1) === (2, )

A2 = fname(T, 2, 3)
@test A2 == fname(T, (2, 3))
@test A2 == fname(T, Base.OneTo(2), Base.OneTo(3))
@test A2 == fname(T, (Base.OneTo(2), Base.OneTo(3)))
@test typeof(A2) === Array{T, 2}
@test size(A2) === (2, 3)

@test isempty(fname(T, 0, 0))
@test_throws MethodError fname(T, 1.)
@test_throws MethodError fname(T, [1.]) # issue #19265
@test_throws MethodError fname(T, [1, 1]) # issue #19265
end
end
test_zeros(zeros(), Array{Float64, 0}, ())
test_zeros(zeros(2), Vector{Float64}, (2,))
test_zeros(zeros(2,3), Matrix{Float64}, (2,3))
test_zeros(zeros((2,3)), Matrix{Float64}, (2,3))

test_zeros(zeros(Int, 6), Vector{Int}, (6,))
test_zeros(zeros(Int, 2, 3), Matrix{Int}, (2,3))
test_zeros(zeros(Int, (2, 3)), Matrix{Int}, (2,3))

# #19265"
@test_throws MethodError zeros(Float64, [1.])
@test_throws MethodError ones(Float64, [0, 0])
end

# issue #11053
Expand Down