Skip to content

Commit 129b904

Browse files
committed
Skip redundant test
when we call `a .+ b .- c` and the style priority of `a,b,c`'s is clear defined. Then the result style should not be order dependent.
1 parent 10e6442 commit 129b904

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

test/runtests.jl

+22-19
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,7 @@ Base.BroadcastStyle(::Broadcast.ArrayStyle{MyArray1}, ::Broadcast.ArrayStyle{MyA
11361136
Base.BroadcastStyle(::Broadcast.ArrayStyle{MyArray2}, S::Broadcast.DefaultArrayStyle) = S
11371137

11381138
@testset "broadcast" begin
1139+
dotaddsub((a, b, c),) = a .+ b .- c
11391140
s = StructArray{ComplexF64}((rand(2,2), rand(2,2)))
11401141
@test isa(@inferred(s .+ s), StructArray)
11411142
@test (s .+ s).re == 2*s.re
@@ -1159,18 +1160,21 @@ Base.BroadcastStyle(::Broadcast.ArrayStyle{MyArray2}, S::Broadcast.DefaultArrayS
11591160
s2 = StructArray{ComplexF64}((MyArray2(rand(2)), MyArray2(rand(2))))
11601161
s3 = StructArray{ComplexF64}((MyArray3(rand(2)), MyArray3(rand(2))))
11611162
s4 = StructArray{ComplexF64}((rand(2), rand(2)))
1162-
1163-
function _test_similar(a, b, c)
1164-
try
1165-
d = StructArray{ComplexF64}((a.re .+ b.re .- c.re, a.im .+ b.im .- c.im))
1166-
@test typeof(a .+ b .- c) == typeof(d)
1167-
catch
1168-
@test_throws MethodError a .+ b .- c
1163+
test_set = Any[s1, s2, s3, s4]
1164+
for ia in 1:4, ib in 1:4, ic in 1:4
1165+
as = test_set[ia], test_set[ib], test_set[ic]
1166+
is = ia, ib, ic
1167+
ns = count(==(3), is), count(==(4), is)
1168+
if count(==(2), is) == 0 && !(ia<=ib<=ic)
1169+
# Skip some order independent test (MyArray1 > MyArray3 > Array)
1170+
continue
1171+
elseif ns in ((1,2), (2,1)) || (ic == 3 && ia + ib == 6)
1172+
@test_throws MethodError dotaddsub(as)
1173+
else
1174+
d = StructArray{ComplexF64}((dotaddsub(map(a->a.re, as)), dotaddsub(map(a->a.im, as))))
1175+
@test @inferred(dotaddsub(as))::typeof(d) == d
11691176
end
11701177
end
1171-
for s in (s1,s2,s3,s4), s′ in (s1,s2,s3,s4), s″ in (s1,s2,s3,s4)
1172-
_test_similar(s, s′, s″)
1173-
end
11741178

11751179
# test for dimensionality track
11761180
s = s1
@@ -1197,21 +1201,20 @@ Base.BroadcastStyle(::Broadcast.ArrayStyle{MyArray2}, S::Broadcast.DefaultArrayS
11971201
@test (x -> x.x.x.a).(StructArray(x=StructArray(x=StructArray(a=1:3)))) == [1, 2, 3]
11981202

11991203
@testset "ambiguity check" begin
1200-
function _test(a, b, c)
1201-
if a isa StructArray || b isa StructArray || c isa StructArray
1202-
d = @inferred a .+ b .- c
1203-
@test d == collect(a) .+ collect(b) .- collect(c)
1204-
@test d isa StructArray
1205-
end
1206-
end
12071204
testset = Any[StructArray([1;2+im]),
12081205
1:2,
12091206
(1,2),
12101207
StructArray(@SArray [1 1+2im]),
12111208
(@SArray [1 2])
12121209
]
1213-
for aa in testset, bb in testset, cc in testset
1214-
_test(aa, bb, cc)
1210+
# The 3 styles in testset has clear priorities:
1211+
# Style{Tuple} < StaticArrayStyle < DefaultArrayStyle
1212+
# Thus is OK to skip some test as the result is order independent
1213+
for ia in 1:5, ib in ia:5, ic in ib:5
1214+
as = a, b, c = testset[ia], testset[ib], testset[ic]
1215+
if a isa StructArray || b isa StructArray || c isa StructArray
1216+
@test @inferred(dotaddsub(as))::StructArray == dotaddsub(map(collect, as))
1217+
end
12151218
end
12161219
end
12171220

0 commit comments

Comments
 (0)