Skip to content

Commit 002f56c

Browse files
authored
Test floating-point arrays using isapprox (#318)
1 parent f174c7b commit 002f56c

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

test/runtests.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -378,22 +378,22 @@ end
378378
# type, and produce numerically correct results.
379379
as_array(x::AbstractArray) = Array(x)
380380
as_array(x::UniformScaling) = x
381-
equal_or_undef(a::Number, b::Number) = (a == b) || isequal(a, b)
382-
equal_or_undef(a, b) = all(equal_or_undef.(a, b))
381+
isapprox_or_undef(a::Number, b::Number) = (a b) || isequal(a, b)
382+
isapprox_or_undef(a, b) = all(((x,y),) -> isapprox_or_undef(x,y), zip(a, b))
383383
function test_addition_subtraction_dot(As, Bs, Tout::Type)
384384
for A in As, B in Bs
385385
@testset "$(typeof(A)) and $(typeof(B))" begin
386386
@test @inferred(A + B) isa Tout{promote_type(eltype(A), eltype(B))}
387-
@test equal_or_undef(as_array(A + B), as_array(A) + as_array(B))
387+
@test isapprox_or_undef(as_array(A + B), as_array(A) + as_array(B))
388388

389389
@test @inferred(A - B) isa Tout{promote_type(eltype(A), eltype(B))}
390-
@test equal_or_undef(as_array(A - B), as_array(A) - as_array(B))
390+
@test isapprox_or_undef(as_array(A - B), as_array(A) - as_array(B))
391391

392392
@test @inferred(B + A) isa Tout{promote_type(eltype(B), eltype(A))}
393-
@test equal_or_undef(as_array(B + A), as_array(B) + as_array(A))
393+
@test isapprox_or_undef(as_array(B + A), as_array(B) + as_array(A))
394394

395395
@test @inferred(B - A) isa Tout{promote_type(eltype(B), eltype(A))}
396-
@test equal_or_undef(as_array(B - A), as_array(B) - as_array(A))
396+
@test isapprox_or_undef(as_array(B - A), as_array(B) - as_array(A))
397397

398398
# Julia 1.6 doesn't support dot(UniformScaling)
399399
if VERSION < v"1.6.0" || VERSION >= v"1.8.0"

0 commit comments

Comments
 (0)