Repository: JuliaLang/julia
File: test/arrayops.jl (Julia)

Code before:
    @test setindex!(fill(0.0), fill(1.0), CI0) == fill(1.0)
    @test setindex!(fill(0.0), fill(1.0), CI0, CI0) == fill(1.0)
    @test setindex!(fill(0.0), fill(1.0), :, CI0) == fill(1.0)
    @test setindex!(fill(0.0), fill(1.0), CI0, :) == fill(1.0)
    @test setindex!(fill(0.0), fill(1.0), :, CI0, CI0) == fill(1.0)
    @test setindex!(fill(0.0), fill(1.0), CI0, :, CI0) == fill(1.0)
    @test setindex!(fill(0.0), fill(1.0), CI0, CI0, :) == fill(1.0)
    @test setindex!(fill(fill(0.0)), fill(fill(1.0)), CI0) == fill(fill(1.0))
    # 1-dimensional
    @test setindex!(zeros(2), ones(2), :, CI0) == ones(2)
    @test setindex!(zeros(2), ones(2), CI0, :) == ones(2)
    @test setindex!(zeros(2), ones(2), :, CI0, CI0) == ones(2)
    @test setindex!(zeros(2), ones(2), CI0, :, CI0) == ones(2)
    @test setindex!(zeros(2), ones(2), CI0, CI0, :) == ones(2)
    @test setindex!([fill(0.0)], fill(1.0), 1) == [fill(1.0)]
    # 0-dimensional assignment into ≥1-dimensional arrays
    @test setindex!(zeros(2), fill(1.0), 1, CI0) == [1.0, 0.0]
    @test setindex!(zeros(2), fill(1.0), CI0, 1) == [1.0, 0.0]
    @test setindex!(zeros(2,2), fill(1.0), 1, 1, CI0) == [1.0 0.0; 0.0 0.0]
    @test setindex!(zeros(2,2), fill(1.0), 1, CI0, 1) == [1.0 0.0; 0.0 0.0]
    @test setindex!(zeros(2,2), fill(1.0), CI0, 1, 1) == [1.0 0.0; 0.0 0.0]
end

@testset "conditionally-throwing version of `checkbounds` should return `nothing` if it returns" begin
    for typ in (AbstractString, DenseArray, Base.AbstractBroadcasted)
        @test Base.infer_return_type(checkbounds, Tuple{typ, Any}) <: Nothing
    end
end

# Throws ArgumentError for negative dimensions in Array
@test_throws ArgumentError fill('a', -10)

@testset "Issue 33919" begin
    A = Array[rand(2, 3), rand(3, 1)]
    B = Array[rand(2, 2), rand(1, 4)]
    C = hcat(A, B)
    @test typeof(C) == Array{Array{Float64,2},2}
end

# issue #33974
let n = 12000000, k = 257000000
    # tests skipped since they use a lot of memory
    @test_skip filter(x -> x[2] < 1.0, collect(enumerate(vcat(fill(0.5, n), fill(NaN, k)))))[end] == (n, 0.5)
    @test_skip let v = collect(enumerate(vcat(fill(0.5, n), fill(NaN, k))))
        resize!(v, n)
        sizehint!(v, n)
        v[end] == (n, 0.5)
    end
end

@testset "BoundsError printing" begin

Review comment (suggestion):
fix: make the test more strict:

```suggestion
        @test Base.infer_return_type(checkbounds, Tuple{typ, Vararg}) <: Nothing
```

Code after:
    @test setindex!(fill(0.0), fill(1.0), CI0) == fill(1.0)
    @test setindex!(fill(0.0), fill(1.0), CI0, CI0) == fill(1.0)
    @test setindex!(fill(0.0), fill(1.0), :, CI0) == fill(1.0)
    @test setindex!(fill(0.0), fill(1.0), CI0, :) == fill(1.0)
    @test setindex!(fill(0.0), fill(1.0), :, CI0, CI0) == fill(1.0)
    @test setindex!(fill(0.0), fill(1.0), CI0, :, CI0) == fill(1.0)
    @test setindex!(fill(0.0), fill(1.0), CI0, CI0, :) == fill(1.0)
    @test setindex!(fill(fill(0.0)), fill(fill(1.0)), CI0) == fill(fill(1.0))
    # 1-dimensional
    @test setindex!(zeros(2), ones(2), :, CI0) == ones(2)
    @test setindex!(zeros(2), ones(2), CI0, :) == ones(2)
    @test setindex!(zeros(2), ones(2), :, CI0, CI0) == ones(2)
    @test setindex!(zeros(2), ones(2), CI0, :, CI0) == ones(2)
    @test setindex!(zeros(2), ones(2), CI0, CI0, :) == ones(2)
    @test setindex!([fill(0.0)], fill(1.0), 1) == [fill(1.0)]
    # 0-dimensional assignment into ≥1-dimensional arrays
    @test setindex!(zeros(2), fill(1.0), 1, CI0) == [1.0, 0.0]
    @test setindex!(zeros(2), fill(1.0), CI0, 1) == [1.0, 0.0]
    @test setindex!(zeros(2,2), fill(1.0), 1, 1, CI0) == [1.0 0.0; 0.0 0.0]
    @test setindex!(zeros(2,2), fill(1.0), 1, CI0, 1) == [1.0 0.0; 0.0 0.0]
    @test setindex!(zeros(2,2), fill(1.0), CI0, 1, 1) == [1.0 0.0; 0.0 0.0]
end

@testset "conditionally-throwing version of `checkbounds` should return `nothing` if it returns" begin
    # can not just set `typ = Any` because that would include the predicate (non-throwing) methods of `checkbounds`, because `Type{Bool} <: Any`
    for typ in (AbstractString, AbstractArray, Base.AbstractBroadcasted)
        @test Base.infer_return_type(checkbounds, Tuple{typ, Vararg}) <: Nothing
    end
end

# Throws ArgumentError for negative dimensions in Array
@test_throws ArgumentError fill('a', -10)

@testset "Issue 33919" begin
    A = Array[rand(2, 3), rand(3, 1)]
    B = Array[rand(2, 2), rand(1, 4)]
    C = hcat(A, B)
    @test typeof(C) == Array{Array{Float64,2},2}
end

# issue #33974
let n = 12000000, k = 257000000
    # tests skipped since they use a lot of memory
    @test_skip filter(x -> x[2] < 1.0, collect(enumerate(vcat(fill(0.5, n), fill(NaN, k)))))[end] == (n, 0.5)
    @test_skip let v = collect(enumerate(vcat(fill(0.5, n), fill(NaN, k))))
        resize!(v, n)
        sizehint!(v, n)
        v[end] == (n, 0.5)
    end
end