Skip to content

Commit

Permalink
Use function noncallable end
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Jun 8, 2020
1 parent ea2cc8b commit 32d7f93
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions test/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,18 +176,17 @@ end
@test typeof(sum(Int8[])) == typeof(sum(Int8[1])) == typeof(sum(Int8[1 7]))

@testset "`sum` of empty collections with `init`" begin
function noncallable end # should not be called
@testset for init in [0, 0.0]
@test sum([]; init = init) === init
@test sum((x for x in [123] if false); init = init) === init
@test sum(nothing, []; init = init) === init
@test sum(nothing, (x for x in [123] if false); init = init) === init
@test sum(noncallable, []; init = init) === init
@test sum(noncallable, (x for x in [123] if false); init = init) === init
@test sum(Array{Any,3}(undef, 3, 2, 0); dims = 1, init = init) ==
zeros(typeof(init), 1, 2, 0)
@test sum(nothing, Array{Any,3}(undef, 3, 2, 0); dims = 1, init = init) ==
@test sum(noncallable, Array{Any,3}(undef, 3, 2, 0); dims = 1, init = init) ==
zeros(typeof(init), 1, 2, 0)
end
# Note: We are using `nothing` in place of the callable to make
# sure that it's not actually called.
end

# check sum(abs, ...) for support of empty collections
Expand Down Expand Up @@ -218,18 +217,17 @@ end
@test typeof(prod(Array(trues(10)))) == Bool

@testset "`prod` of empty collections with `init`" begin
function noncallable end # should not be called
@testset for init in [1, 1.0, ""]
@test prod([]; init = init) === init
@test prod((x for x in [123] if false); init = init) === init
@test prod(nothing, []; init = init) === init
@test prod(nothing, (x for x in [123] if false); init = init) === init
@test prod(noncallable, []; init = init) === init
@test prod(noncallable, (x for x in [123] if false); init = init) === init
@test prod(Array{Any,3}(undef, 3, 2, 0); dims = 1, init = init) ==
ones(typeof(init), 1, 2, 0)
@test prod(nothing, Array{Any,3}(undef, 3, 2, 0); dims = 1, init = init) ==
@test prod(noncallable, Array{Any,3}(undef, 3, 2, 0); dims = 1, init = init) ==
ones(typeof(init), 1, 2, 0)
end
# Note: We are using `nothing` in place of the callable to make
# sure that it's not actually called.
end

# check type-stability
Expand Down

0 comments on commit 32d7f93

Please sign in to comment.