Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0b7e17f

Browse files
committedSep 24, 2016
More broadcast tests
1 parent 23325fe commit 0b7e17f

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed
 

‎test/broadcast.jl

+16-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ end
311311
let f17314 = x -> x < 0 ? false : x
312312
@test eltype(broadcast(f17314, 1:3)) === Int
313313
@test eltype(broadcast(f17314, -1:1)) === Integer
314-
@test eltype(broadcast(f17314, Int[])) === Any
314+
@test eltype(broadcast(f17314, Int[])) === Union{Bool,Int}
315315
end
316316
let io = IOBuffer()
317317
broadcast(x->print(io,x), 1:5) # broadcast with side effects
@@ -336,3 +336,18 @@ end
336336
@test broadcast(+, 1.0, (0, -2.0)) == (1.0,-1.0)
337337
@test broadcast(+, 1.0, (0, -2.0), [1]) == [2.0, 0.0]
338338
@test broadcast(*, ["Hello"], ", ", ["World"], "!") == ["Hello, World!"]
339+
340+
# Ensure that even strange constructors that break `T(x)::T` work with broadcast
341+
immutable StrangeType18623 end
342+
StrangeType18623(x) = x
343+
StrangeType18623(x,y) = (x,y)
344+
@test @inferred broadcast(StrangeType18623, 1:3) == [1,2,3]
345+
@test @inferred broadcast(StrangeType18623, 1:3, 4:6) == [(1,4),(2,5),(3,6)]
346+
347+
@test typeof(Int.(Number[1, 2, 3])) === typeof((x->Int(x)).(Number[1, 2, 3]))
348+
349+
@test @inferred broadcast(CartesianIndex, 1:2) == [CartesianIndex(1), CartesianIndex(2)]
350+
@test @inferred broadcast(CartesianIndex, 1:2, 3:4) == [CartesianIndex(1,3), CartesianIndex(2,4)]
351+
352+
# Issue 18622
353+
@test @inferred tuple.(1:3, 4:6, 7:9)::Vector{Tuple{Int,Int,Int}} == [(1,4,7), (2,5,8), (3,6,9)]

‎test/numbers.jl

+6-6
Original file line numberDiff line numberDiff line change
@@ -2805,42 +2805,42 @@ let types = (Base.BitInteger_types..., BigInt, Bool,
28052805
Complex{Int}, Complex{UInt}, Complex32, Complex64, Complex128)
28062806
for S in types
28072807
for op in (+, -)
2808-
T = @inferred Base._promote_op(op, S)
2808+
T = @inferred Base.promote_op(op, S)
28092809
t = @inferred op(one(S))
28102810
@test T === typeof(t)
28112811
end
28122812

28132813
for R in types
28142814
for op in (+, -, *, /, ^)
2815-
T = @inferred Base._promote_op(op, S, R)
2815+
T = @inferred Base.promote_op(op, S, R)
28162816
t = @inferred op(one(S), one(R))
28172817
@test T === typeof(t)
28182818
end
28192819
end
28202820
end
28212821

2822-
@test @inferred(Base._promote_op(!, Bool)) === Bool
2822+
@test @inferred(Base.promote_op(!, Bool)) === Bool
28232823
end
28242824

28252825
let types = (Base.BitInteger_types..., BigInt, Bool,
28262826
Rational{Int}, Rational{BigInt},
28272827
Float16, Float32, Float64, BigFloat)
28282828
for S in types, T in types
28292829
for op in (<, >, <=, >=, (==))
2830-
@test @inferred(Base._promote_op(op, S, T)) === Bool
2830+
@test @inferred(Base.promote_op(op, S, T)) === Bool
28312831
end
28322832
end
28332833
end
28342834

28352835
let types = (Base.BitInteger_types..., BigInt, Bool)
28362836
for S in types
2837-
T = @inferred Base._promote_op(~, S)
2837+
T = @inferred Base.promote_op(~, S)
28382838
t = @inferred ~one(S)
28392839
@test T === typeof(t)
28402840

28412841
for R in types
28422842
for op in (&, |, <<, >>, (>>>), %, ÷)
2843-
T = @inferred Base._promote_op(op, S, R)
2843+
T = @inferred Base.promote_op(op, S, R)
28442844
t = @inferred op(one(S), one(R))
28452845
@test T === typeof(t)
28462846
end

0 commit comments

Comments
 (0)
Please sign in to comment.