Skip to content

Commit

Permalink
Skip redundant test
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
N5N3 committed Nov 6, 2022
1 parent 10e6442 commit 129b904
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,7 @@ Base.BroadcastStyle(::Broadcast.ArrayStyle{MyArray1}, ::Broadcast.ArrayStyle{MyA
Base.BroadcastStyle(::Broadcast.ArrayStyle{MyArray2}, S::Broadcast.DefaultArrayStyle) = S

@testset "broadcast" begin
dotaddsub((a, b, c),) = a .+ b .- c
s = StructArray{ComplexF64}((rand(2,2), rand(2,2)))
@test isa(@inferred(s .+ s), StructArray)
@test (s .+ s).re == 2*s.re
Expand All @@ -1159,18 +1160,21 @@ Base.BroadcastStyle(::Broadcast.ArrayStyle{MyArray2}, S::Broadcast.DefaultArrayS
s2 = StructArray{ComplexF64}((MyArray2(rand(2)), MyArray2(rand(2))))
s3 = StructArray{ComplexF64}((MyArray3(rand(2)), MyArray3(rand(2))))
s4 = StructArray{ComplexF64}((rand(2), rand(2)))

function _test_similar(a, b, c)
try
d = StructArray{ComplexF64}((a.re .+ b.re .- c.re, a.im .+ b.im .- c.im))
@test typeof(a .+ b .- c) == typeof(d)
catch
@test_throws MethodError a .+ b .- c
test_set = Any[s1, s2, s3, s4]
for ia in 1:4, ib in 1:4, ic in 1:4
as = test_set[ia], test_set[ib], test_set[ic]
is = ia, ib, ic
ns = count(==(3), is), count(==(4), is)
if count(==(2), is) == 0 && !(ia<=ib<=ic)
# Skip some order independent test (MyArray1 > MyArray3 > Array)
continue
elseif ns in ((1,2), (2,1)) || (ic == 3 && ia + ib == 6)
@test_throws MethodError dotaddsub(as)
else
d = StructArray{ComplexF64}((dotaddsub(map(a->a.re, as)), dotaddsub(map(a->a.im, as))))
@test @inferred(dotaddsub(as))::typeof(d) == d
end
end
for s in (s1,s2,s3,s4), s′ in (s1,s2,s3,s4), s″ in (s1,s2,s3,s4)
_test_similar(s, s′, s″)
end

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

@testset "ambiguity check" begin
function _test(a, b, c)
if a isa StructArray || b isa StructArray || c isa StructArray
d = @inferred a .+ b .- c
@test d == collect(a) .+ collect(b) .- collect(c)
@test d isa StructArray
end
end
testset = Any[StructArray([1;2+im]),
1:2,
(1,2),
StructArray(@SArray [1 1+2im]),
(@SArray [1 2])
]
for aa in testset, bb in testset, cc in testset
_test(aa, bb, cc)
# The 3 styles in testset has clear priorities:
# Style{Tuple} < StaticArrayStyle < DefaultArrayStyle
# Thus is OK to skip some test as the result is order independent
for ia in 1:5, ib in ia:5, ic in ib:5
as = a, b, c = testset[ia], testset[ib], testset[ic]
if a isa StructArray || b isa StructArray || c isa StructArray
@test @inferred(dotaddsub(as))::StructArray == dotaddsub(map(collect, as))
end
end
end

Expand Down

0 comments on commit 129b904

Please sign in to comment.